early-afternoon-97327
05/08/2025, 8:18 AMtall-airline-16756
05/08/2025, 8:19 AMtall-airline-16756
05/08/2025, 8:19 AMctx.shutdown(reason="Session ended")
method. This will trigger the shutdown hooks.
• Using shutdown hooks: Implement post-processing or cleanup tasks by adding shutdown hooks with ctx.add_shutdown_callback(my_shutdown_hook)
. These hooks are called when the session ends.
• Ending the session for everyone: Use the server API to delete the room. For example: `from livekit import api
async def entrypoint(ctx: JobContext):
api_client = api.LiveKitAPI(
os.getenv("LIVEKIT_URL"),
os.getenv("LIVEKIT_API_KEY"),
os.getenv("LIVEKIT_API_SECRET"),
)
await api_client.room.delete_room(api.DeleteRoomRequest(
room=ctx.job.room.name,
))`This will send a "Disconnected" room event and remove the room from the server.
Let me know if you need further assistance!
Sources: Inside a session | LiveKit Docsearly-afternoon-97327
05/08/2025, 8:20 AMtall-airline-16756
05/08/2025, 8:21 AMroom(_:participantDidDisconnect:)
method, which is triggered when a RemoteParticipant
leaves the room: func room(_ room: Room, participantDidDisconnect participant: RemoteParticipant) {
// Handle participant disconnection
}
• Using event listeners in Python: Register an event handler for the "participant_disconnected"
event: `def on_participant_disconnected(participant):
# Handle participant disconnection
room.on("participant_disconnected", on_participant_disconnected)`This event is triggered when a participant leaves the room, passing the RemoteParticipant
as an argument.
Let me know if you need further clarification or assistance!
Sources: room(_:participantDidDisconnect:) | Documentation | livekit.rtc API documentation