<@U084APK40NS> using livekit-server-sdk how to che...
# ask-ai
r
@millions-hair-24956 using livekit-server-sdk how to check if room is active and has tracks
g
To check if a room is active and has tracks using the LiveKit server SDK, you can use the
listRooms
and
listParticipants
methods from the
RoomServiceClient
class. Here's a brief overview: 1. List Active Rooms: Use the
listRooms
method to get a list of active rooms. This method returns a list of rooms that are currently active. 2. Check Participants and Tracks: For each room, use the
listParticipants
method to get the list of participants. You can then check if any participant has published tracks. Here's a code snippet to illustrate this:
Copy code
const { RoomServiceClient } = require('livekit-server-sdk');

const client = new RoomServiceClient('https://your.livekit.server', 'apiKey', 'secret');

async function checkRoomStatus() {
  const rooms = await client.listRooms();
  for (const room of rooms) {
    const participants = await client.listParticipants(room.name);
    const hasTracks = participants.some(participant => participant.tracks.length > 0);
    console.log(`Room: ${room.name}, Active: ${participants.length > 0}, Has Tracks: ${hasTracks}`);
  }
}

checkRoomStatus();
Would you like more details on any specific part of this process? Sources: - RoomServiceClient 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.