creamy-window-79763
07/09/2025, 1:20 PMtall-airline-16756
07/09/2025, 1:20 PMtall-airline-16756
07/09/2025, 1:21 PMempty_timeout
and departure_timeout
settings for rooms:
• `empty_timeout`: seconds to keep a room open if no one joins
• `departure_timeout`: seconds to keep a room open after everyone leaves
These can be set when creating a room using the CreateRoomRequest
. However, these do not cover the exact scenario of automatically deleting a room if it has only one participant for more than X seconds.
To handle that scenario, you would need to manually monitor the participant count using the LiveKit API and delete the room when the condition is met.
Here is a Python example combining both parts:
from livekit import api
from livekit.protocol.room import CreateRoomRequest
import asyncio
# Initialize LiveKit API client
lkapi = api.LiveKitAPI(
"YOUR_LIVEKIT_URL",
"YOUR_API_KEY",
"YOUR_API_SECRET",
)
# Create room with timeouts
create_room_request = CreateRoomRequest(
name="my_room",
empty_timeout=30, # in seconds
departure_timeout=30, # in seconds
)
room = lkapi.room.create_room(create_room_request)
# Monitor room for single participant condition
async def monitor_room(lkapi, room_name, single_participant_timeout=30):
while True:
participants = await lkapi.room.list_participants(
api.ListParticipantsRequest(room=room_name)
)
if len(participants.participants) == 1:
await asyncio.sleep(single_participant_timeout)
participants = await lkapi.room.list_participants(
api.ListParticipantsRequest(room=room_name)
)
if len(participants.participants) == 1:
await lkapi.room.delete_room(
api.DeleteRoomRequest(room=room_name)
)
break
await asyncio.sleep(1)
# Run the monitoring task
asyncio.run(monitor_room(lkapi, "my_room"))
This example shows how to set timeouts on room creation and implement your own logic to automatically delete the room if it stays with only one participant for a specified timeout.
Let me know if you need details on any part of this setup.
Sources: livekit/livekit_room.pb.go