the participant left with closing the tab or inter...
# ask-ai
s
the participant left with closing the tab or internet issue, after how long i get Participant left (CONNECTION_TIMEOUT)? and in which cases i receive this webhook request?
t
Thanks for reaching out, Mostafa. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’ll explain when the
Participant left (CONNECTION_TIMEOUT)
webhook is sent and why. • Timing: LiveKit sends the
participant_left
webhook with reason
CONNECTION_TIMEOUT
after the server stops receiving ICE/STUN keep‑alive packets from the client's WebRTC peer connection for about 20 seconds. • Typical cases that trigger it: ◦ Participant closes their browser tab or window abruptly. ◦ Participant loses internet connectivity (network drop). ◦ The media path is otherwise interrupted so ICE/STUN keep‑alives stop arriving. This reason specifically means the media connection timed out (the media path is dead), not that there was a signaling/state mismatch. If you want, I can help you handle this webhook in your app (reconnection UI, grace window, or logging) — which option would you like? Sources: Understanding the STATE_MISMATCH Disconnect Reason
s
when the room get closed ?
t
You're asking when a room gets closed — here are the ways a LiveKit room closes and the timing to expect. • Automatic closure: When the last participant leaves, LiveKit starts a departure grace period (default ~20 seconds). If no new participants join during that period, the room is closed and a
room_finished
webhook is emitted. • Manual/API closure: Calling the
deleteRoom
API immediately closes the room and disconnects all participants. • Agent/server-triggered closure: Rooms can be programmatically deleted by agent workflows or server-side logic (e.g., using the API client), which also closes the room immediately. If you want, tell me which scenario you care about (automatic vs API vs agent workflows) and I’ll provide exact API calls or sample webhook handling. Sources: Avoiding Room ID Reuse When Re-Creating Rooms With the Same Name | server-sdk-js | livekit/livekit_composite | DeepWiki | Job lifecycle | LiveKit docs | Agents telephony integration | LiveKit docs
s
what is the gracefull way to end the room ?
t
Good question — here’s a concise, recommended flow to end a LiveKit room gracefully, plus options depending on your needs. Recommended graceful flow 1. Notify participants: Send an in-app message (or UI prompt) telling participants the session will end soon so clients can stop publishing and save state. 2. Ask clients to cleanly disconnect: Have clients call the SDK disconnect/leave method so they can stop tracks and close peer connections. 3. Wait briefly for acknowledgements (optional): Give a short grace window (a few seconds) for clients to finish uploads or save data. 4. Close the room via API: Call the
deleteRoom
API to terminate the room and disconnect any remaining participants. This ensures immediate and clean server-side cleanup. 5. Handle webhooks and post-close tasks: Listen for
room_finished
and
participant_left
webhooks to trigger recordings, archives, analytics, or other cleanup. When to use alternatives • If you want automatic closure after everyone leaves: rely on the default behavior (room closes after the departure timeout, ~20s, if no one rejoins). • If you must forcibly stop a room now (e.g., abuse): call
deleteRoom
immediately without waiting for client disconnects. Need code samples or SDK-specific calls? Tell me which language/SDK you use (JavaScript, TypeScript, Python, or server SDK), and I’ll give the exact API/SDK calls and a short example.
s
when i get room ended event ? and is that event exist or not?
t
You're asking whether a "room ended" event exists and when you receive it — yes. • Event name:
room_finished
(a webhook event). • When it's sent: after the room is shut down — typically when the last participant has left and the departure grace period (~20 seconds) expires, or when the room is explicitly closed via the
deleteRoom
API or programmatic deletion. • What it indicates: the room has been fully terminated (useful for stopping recordings, cleanup, billing, etc.). If you want, I can show a short webhook handler example or confirm how to enable webhooks for your server — which would you prefer? Sources: Server-side | livekit/livekit_composite | DeepWiki
s
deleteRoom is it will effect the egress? because i see the egress still active for something to complete the composing and recording of the stream
t
Good question — here’s a clear answer about how
deleteRoom
affects egress. • Effect on participants/room: Calling
deleteRoom
immediately disconnects all participants and marks the room closed. • Effect on egress (recording/composing): Egress processes are not terminated instantly. Active egress (composite recording, MP4 finalization, uploads, RTMP sessions finishing segments, etc.) will continue briefly after the room is deleted so they can finalize output (preventing corrupted files). • Best practices: ◦ If you need deterministic timing, explicitly stop egress first (call the egress stop API) and wait for confirmation, then call
deleteRoom
. ◦ If you prefer server-side finalization, you can call
deleteRoom
and allow LiveKit to finish composing/finishing egress; expect a short delay until egress fully stops. Would you like the exact API calls/snippets for stopping egress before deleting the room (Node, Python, or JS)? Sources: server-sdk-js | livekit/livekit_composite | DeepWiki | Job lifecycle | LiveKit docs