blue-fish-45249
05/15/2025, 8:14 PMlivekit_api = get_livekit_api()
request = ListParticipantsRequest(room=ctx.room.name)
async with livekit_api:
total_participants = await livekit_api.room.list_participants(request)
participants = total_participants.participants
<http://logger.info|logger.info>("Total participants in room: %s", len(participants))
Occasionally, a participant disconnects before the call officially starts, which results in the room being automatically deleted by LiveKit. When that happens, calling list_participants
raises a TwirpError('not_found', 'requested room does not exist')
.
Is there a way to check if the room exists before calling list_participants
, or a recommended pattern to handle this scenario more gracefully?tall-airline-16756
05/15/2025, 8:14 PMtall-airline-16756
05/15/2025, 8:15 PMconst rooms = await roomServiceClient.listRooms([roomName]);
if (rooms.length > 0) {
// Room exists, now you can list participants
const participants = await roomServiceClient.listParticipants(roomName);
}
The listRooms method accepts an optional array of room names to filter the results and returns an array of Room objects. If the array is empty, it means the room doesn’t exist or is not active. This approach can help you handle the situation more gracefully. Sources: RoomServiceClient | LiveKit JS Server SDK - v2.9.7tall-airline-16756
05/15/2025, 8:16 PMfrom livekit import ListRoomsRequest
# Create a request to filter by room name
request = ListRoomsRequest(names=[room_name])
# Call the list_rooms method
response = await livekit_api.room.list_rooms(request)
# Check if the room exists
if response.rooms:
# Room exists, now you can list participants
participants_response = await livekit_api.room.list_participants(room_name)
This approach ensures that you only call list_participants for rooms that are active. Sources: livekit.api.room_service API documentation