worried-rocket-36543
09/04/2025, 11:54 AMtall-airline-16756
09/04/2025, 11:54 AMtall-airline-16756
09/04/2025, 11:55 AM@livekit/rtc-node SDK makes it easy for your Node.js app to connect to a LiveKit server, publish audio/video tracks, and subscribe to media from other participants.
Here’s a quick rundown to get you started:
• Connecting to a Room: Use the Room class to join a room. Here’s a simple example:
import { Room } from '@livekit/rtc-node';
const room = new Room();
await room.connect(url, token, { autoSubscribe: true, dynacast: true });
• Sending Audio: Create an AudioSource and LocalAudioTrack, then publish it to the room. Like this:
const source = new AudioSource(sampleRate, channels);
const track = LocalAudioTrack.createAudioTrack('audio', source);
await room.localParticipant.publishTrack(track, options);
await source.captureFrame(new AudioFrame(buffer, sampleRate, channels, sampleCount));
• Receiving Audio: You can subscribe to and handle incoming audio tracks easily. For example:
room.on(RoomEvent.TrackSubscribed, (track) => {
if (track.kind === TrackKind.KIND_AUDIO) {
const stream = new AudioStream(track);
for await (const frame of stream) {
// Process audio frame
}
}
});
• Video Support: The SDK also supports video! You can manage video tracks similarly to audio, using the RemoteVideoTrack class to work with video from other participants.
Just a heads up: the Node.js realtime SDK is currently in Developer Preview, so it’s best to avoid using it in production environments for now.
Sources: examples/rpc/index.ts | Connecting to LiveKit | LiveKit Docs