Is it possible to monitor a room using the LiveKit...
# ask-ai
h
Is it possible to monitor a room using the LiveKit Server SDK of Node.js? I would like to check for room error, room close events and such.
t
Thanks for reaching out, tri.nguyen. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're looking into monitoring a room using the LiveKit Server SDK for Node.js! Here are a couple of friendly approaches that can help you keep a close eye on things: • Client-Side Monitoring: You can use the
Room
class to listen for important events like
Disconnected
. For instance, detecting when a room closes is possible by checking for
DisconnectReason.ROOM_CLOSED
or
DisconnectReason.ROOM_DELETED
. This way, you’ll be able to understand why a disconnection happened and spot room closures or errors easily. • Server-Side Monitoring: Another great option is setting up webhooks to catch events like
room_finished
when a room closes. Webhooks are super reliable and will notify you about room lifecycle events, even if no clients are connected at that moment. Here's a simple example to help you monitor disconnection reasons:
Copy code
room.on(RoomEvent.Disconnected, (reason) => {
  if (reason === DisconnectReason.ROOM_CLOSED) {
    console.log('Room was closed');
  } else {
    console.log('Disconnected for another reason:', reason);
  }
});
By combining these client-side event listeners with server-side webhooks, you’ll have a well-rounded way to monitor room errors and closures. If you have any questions or need further help, feel free to ask—I’m here to support you! Sources: Connecting to LiveKit | LiveKit docs | agent-console/app/room/page.tsx | Server-Side SDKs & Authentication | livekit/livekit_composite | DeepWiki | Events and error handling | LiveKit docs
h
Is it OK to use the LiveKit JS Client SDK on the server?
t
I'm glad you reached out! The LiveKit JS Client SDK is mainly designed to be used on the client side within browsers. If you're working on server-side applications, LiveKit has a special Node.js Realtime SDK (found in the
livekit-rtc
package) just for that. This SDK lets your server-side apps connect to rooms as participants, publish and subscribe to audio, video, and data, and interact with the room in a flexible way. For server-side scenarios like bots, recording agents, or AI integrations, using the Node.js Realtime SDK is definitely the best path. The standard
livekit-client
SDK isn’t really meant to be used directly on the server. If you have any questions about getting started or need help along the way, feel free to ask—we’re here to support you! Sources: README.md
h
Is it possible to monitor the room with
@livekit/rtc-node
?
t
Absolutely, you can monitor a room using
@livekit/rtc-node
. This SDK is designed to help you connect to a room and keep an eye on participant and track states, while also letting you listen to real-time events like these: • `TrackSubscribed`: When you subscribe to a remote track • `ParticipantConnected`: When a new participant joins • `ParticipantDisconnected`: When a participant leaves • `TrackPublished`: When a participant publishes a new track • `Disconnected`: When the connection to the room is lost Here’s a simple example to get you started with monitoring events:
Copy code
room
  .on(RoomEvent.TrackSubscribed, (track, publication, participant) => {
    console.log(`${participant.identity} published ${track.kind}:`, track.name);
  })
  .on(RoomEvent.ParticipantConnected, (participant) => {
    console.log(`Participant ${participant.identity} joined`);
  })
  .on(RoomEvent.Disconnected, () => {
    console.log('Disconnected from room');
  });
Just a quick heads-up:
@livekit/rtc-node
is currently in Developer Preview, so it’s best to avoid using it in production for now. If you have a specific scenario in mind or need help with an example, feel free to ask—I’m here to help! Sources: packages/livekit-rtc/CHANGELOG.md