miniature-nail-35141
02/25/2025, 5:21 AMgray-monkey-83525
02/25/2025, 5:21 AMminiature-nail-35141
02/25/2025, 5:39 AMgray-monkey-83525
02/25/2025, 5:39 AMlist_participants
method from the RoomService
class. This method returns a list of participants in the specified room, and you can simply count the number of participants in the list.
Here's a basic example:
from livekit.api.room_service import RoomService
import aiohttp
async def get_number_of_participants(room_name):
async with aiohttp.ClientSession() as session:
room_service = RoomService(session, 'your_livekit_url', 'api_key', 'api_secret')
response = await room_service.list_participants({'room': room_name})
number_of_participants = len(response.participants)
return number_of_participants
# Example usage
room_name = 'example_room'
number_of_participants = await get_number_of_participants(room_name)
print(f"Number of participants in {room_name}: {number_of_participants}")
This code snippet initializes a RoomService
client, lists the participants in the specified room, and counts them.
Would you like more details on this process?
Sources:
- RoomService API documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.miniature-nail-35141
02/25/2025, 5:41 AMgray-monkey-83525
02/25/2025, 5:41 AMJobContext
in LiveKit, you can access the room
property of the JobContext
and then use the remote_participants
attribute to count the participants. Here's a concise example:
async def entrypoint(ctx: JobContext):
await ctx.connect()
number_of_participants = len(ctx.room.remote_participants)
print(f"Number of participants in the room: {number_of_participants}")
In this example, ctx.room.remote_participants
provides a dictionary of participants, and len()
is used to count them. This code should be placed within the entrypoint function of your agent.
Would you like more detailed information on using JobContext
?
Sources:
- JobContext documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.miniature-nail-35141
02/25/2025, 5:49 AMgray-monkey-83525
02/25/2025, 5:49 AMJobContext
in LiveKit. Here's a basic approach to gather this information:
async def entrypoint(ctx: JobContext):
await ctx.connect()
# Number of remote participants
num_remote_participants = len(ctx.room.remote_participants)
# Number of agents (assuming agents are a specific type of participant)
num_agents = sum(1 for p in ctx.room.remote_participants.values() if p.kind == 'AGENT')
# Tracks subscribed by each participant
tracks_subscribed = {p.identity: len(p.tracks) for p in ctx.room.remote_participants.values()}
print(f"Number of remote participants: {num_remote_participants}")
print(f"Number of agents: {num_agents}")
print(f"Tracks subscribed: {tracks_subscribed}")
# Example usage
# This function would be called within the context of a LiveKit agent's entrypoint
This code snippet connects to the room, counts the remote participants, filters for agents, and lists the tracks subscribed by each participant.
Would you like more detailed instructions or information on any specific part of this process?
Sources:
- https://docs.livekit.io/server/room-management/#GetParticipant
- https://docs.livekit.io/client-sdk-js/classes/Room.html 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.