able-jackal-84140
10/03/2025, 6:39 AMtall-airline-16756
10/03/2025, 6:39 AMtall-airline-16756
10/03/2025, 6:40 AMable-jackal-84140
10/03/2025, 6:40 AMtall-airline-16756
10/03/2025, 6:41 AMlist_rooms() method to get all active rooms. Here's a simple example to guide you:
from livekit import api
import asyncio
async def list_all_rooms():
lkapi = api.LiveKitAPI()
# List all rooms
room_list = await lkapi.room.list_rooms(api.ListRoomsRequest())
for room in room_list.rooms:
print(f"Room: {room.name}, Participants: {len(room.participants) if room.participants else 0}")
await lkapi.aclose()
# Run the function
asyncio.run(list_all_rooms())
2. Terminating Rooms:
When you want to terminate a specific room, the delete_room() method is your friend. Here's how you can do it:
from livekit import api
import asyncio
async def delete_room(room_name: str):
lkapi = api.LiveKitAPI()
# Delete a specific room by name
await lkapi.room.delete_room(api.DeleteRoomRequest(room=room_name))
print(f"Room '{room_name}' has been deleted.")
await lkapi.aclose()
# Example usage
asyncio.run(delete_room("my-room"))
Just a quick reminder: make sure your environment variables (LIVEKIT_API_KEY, LIVEKIT_API_SECRET, and LIVEKIT_URL) are correctly set up, or you can pass them directly when creating your LiveKitAPI instance.
If you have any questions or need a hand with anything else, feel free to ask—I'm here to help!
Sources: examples/agent_dispatch.py | Job lifecycle | LiveKit Docs | Connecting to LiveKit | LiveKit Docs