is there a lifecycle hook for when a user exits th...
# ask-ai
f
is there a lifecycle hook for when a user exits the room?
t
Thanks for reaching out, Eden. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
LiveKit does not have a specific lifecycle hook for when a user exits a room. However, you can achieve similar functionality by listening to the
participant_disconnected
event on the room object. Here is an example of how you can use this event:
Copy code
def _on_participant_disconnected(_: rtc.Participant, fut=room_empty_future):
    if len(ctx.room.remote_participants) == 0 and not fut.done():
        fut.set_result(None)

ctx.room.on("participant_disconnected", _on_participant_disconnected)
This event is triggered when a participant disconnects from the room, which can happen for various reasons such as calling
Room.disconnect()
, server-initiated actions like room deletion, or participant removal. Let me know if you need further clarification or assistance with implementing this! Sources: Pipeline nodes and hooks | LiveKit Docs | examples/voice_agents/realtime_joke_teller.py | Connecting to LiveKit | LiveKit Docs