millions-honey-27871
07/09/2025, 2:18 AMtall-airline-16756
07/09/2025, 2:18 AMtall-airline-16756
07/09/2025, 2:19 AMsession.aclose()
, the LiveKit client should emit a Disconnected
event on the room.on
listener. This event indicates the participant has been disconnected and is the recommended event to listen for to handle cleanup.
If you’re not seeing this event, some points to verify are:
• Ensure you are correctly subscribing to the Disconnected
event on the room object before calling aclose()
.
• Confirm the asynchronous aclose()
call completes as expected.
The Disconnected
event is the standard trigger to perform your cleanup logic, such as releasing tracks or UI updates.
Example usage:
room.on(RoomEvent.Disconnected, (reason) => {
// cleanup logic here
console.log('Disconnected from the room:', reason);
});
await session.aclose();
This approach allows your user to say "bye", call aclose()
on the session, and then reliably handle the disconnection with your subscribed event handler.
Sources: Connecting to LiveKit | LiveKit Docs | src/room/events.ts | livekit-android-sdk/src/main/java/io/livekit/android/events/RoomEvent.ktmillions-honey-27871
07/09/2025, 2:20 AMtall-airline-16756
07/09/2025, 2:20 AMsession.aclose()
. It might seem like this would automatically disconnect your clients, but it actually doesn't work quite that way.
When you call aclose()
, it closes the server-side session, but your JavaScript clients won't automatically get a Disconnected
event. I know, a bit tricky, right?
No worries, though! To make sure your clients are properly notified, you'll want to use the server API to delete the room or shutdown the session. Something like api_client.room.delete_room()
will do the trick and make sure all your connected clients get that Disconnected
event.
Here's a friendly example of how you might do this in Python:
await api_client.room.delete_room(api.DeleteRoomRequest(
room=ctx.job.room.name,
))
# Then optionally delete the room context
ctx.delete_room()
Bottom line: To wrap things up nicely and keep your clients in the loop, use the server API to delete the room instead of just calling aclose()
. Hope this helps!
Sources: livekit-agents/livekit/agents/worker.py | Job lifecycle | LiveKit Docs | Inside a session | LiveKit Docs | Inside a session | LiveKit Docs | basics/exit_message.pymillions-honey-27871
07/09/2025, 2:27 AMdeclare enum DisconnectReason {
/**
* @generated from enum value: UNKNOWN_REASON = 0;
*/
UNKNOWN_REASON = 0,
/**
* the client initiated the disconnect
*
* @generated from enum value: CLIENT_INITIATED = 1;
*/
CLIENT_INITIATED = 1,
/**
* another participant with the same identity has joined the room
*
* @generated from enum value: DUPLICATE_IDENTITY = 2;
*/
DUPLICATE_IDENTITY = 2,
/**
* the server instance is shutting down
*
* @generated from enum value: SERVER_SHUTDOWN = 3;
*/
SERVER_SHUTDOWN = 3,
/**
* RoomService.RemoveParticipant was called
*
* @generated from enum value: PARTICIPANT_REMOVED = 4;
*/
PARTICIPANT_REMOVED = 4,
/**
* RoomService.DeleteRoom was called
*
* @generated from enum value: ROOM_DELETED = 5;
*/
ROOM_DELETED = 5,
/**
* the client is attempting to resume a session, but server is not aware of it
*
* @generated from enum value: STATE_MISMATCH = 6;
*/
STATE_MISMATCH = 6,
/**
* client was unable to connect fully
*
* @generated from enum value: JOIN_FAILURE = 7;
*/
JOIN_FAILURE = 7,
/**
* Cloud-only, the server requested Participant to migrate the connection elsewhere
*
* @generated from enum value: MIGRATION = 8;
*/
MIGRATION = 8,
/**
* the signal websocket was closed unexpectedly
*
* @generated from enum value: SIGNAL_CLOSE = 9;
*/
SIGNAL_CLOSE = 9,
/**
* the room was closed, due to all Standard and Ingress participants having left
*
* @generated from enum value: ROOM_CLOSED = 10;
*/
ROOM_CLOSED = 10,
/**
* SIP callee did not respond in time
*
* @generated from enum value: USER_UNAVAILABLE = 11;
*/
USER_UNAVAILABLE = 11,
/**
* SIP callee rejected the call (busy)
*
* @generated from enum value: USER_REJECTED = 12;
*/
USER_REJECTED = 12,
/**
* SIP protocol failure or unexpected response
*
* @generated from enum value: SIP_TRUNK_FAILURE = 13;
*/
SIP_TRUNK_FAILURE = 13,
/**
* server timed out a participant session
*
* @generated from enum value: CONNECTION_TIMEOUT = 14;
*/
CONNECTION_TIMEOUT = 14,
/**
* media stream failure or media timeout
*
* @generated from enum value: MEDIA_FAILURE = 15;
*/
MEDIA_FAILURE = 15,
}
If I delete the room will the egress still work? There has to be a more graceful way to handletall-airline-16756
07/09/2025, 2:28 AMstopEgress
API. This gives you the power to stop recordings or streaming explicitly while keeping the room active for your participants.
Best practices? Here's what I recommend:
• Use deleteRoom
when you want to cleanly shut everything down.
• Or use stopEgress
if you want to keep the room going and have more precise control.
This approach lets you manage your recordings and rooms super flexibly, giving you the exact user experience you're looking for. Cool, right?
Sources: packages/livekit-server-sdk/src/EgressClient.ts | pkg/service/redisstore_test.go | Inside a session | LiveKit Docs