How does a client know that a session is closed? D...
# ask-ai
k
How does a client know that a session is closed? Do I get a event?
t
Thanks for reaching out, Jex. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Clients are notified when a session is closed through specific events, depending on the context: Agent Sessions: • A
CloseEvent
is emitted when an agent session is closed. This can happen for reasons such as the user ending the conversation, calling
session.aclose()
, room deletion, or an unrecoverable error. The event includes an
error
property with details if an error caused the closure. Example of handling the close event in an agent session:
Copy code
@session.on("close")
def on_close(ev: CloseEvent):
    print(f"Agent Session closed, reason: {ev.reason}")
Regular Client Sessions: • Participants receive a
Disconnected
event when disconnected from a room. This can occur due to server actions like room deletion, participant removal, or other reasons such as
DUPLICATE_IDENTITY
or
ROOM_DELETED
. SDK-Level Implementation: • Rust SDK: Uses a
Close
event in the
SessionEvent
enum, including details like source, reason, and retry information. • Android SDK: Implements an
onClose
callback method with the reason and code for the closure. • JavaScript SDK: Handles close events through the
SignalClient
with appropriate callback mechanisms. The specific event names and handling mechanisms vary between SDKs, but all provide ways for clients to be notified when sessions are closed. Sources: Events and error handling | LiveKit Docs | livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py | Connecting to LiveKit | LiveKit Docs | livekit/src/rtc_engine/rtc_session.rs | livekit-android-test/src/test/java/io/livekit/android/room/SignalClientTest...