How can I know if the participant is left OR disco...
# ask-ai
a
How can I know if the participant is left OR disconnected from the room?? I want to call shutdown immediately when this is detected.. tell me about it
t
Thanks for reaching out, Hiren. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To detect when a participant has left or disconnected from a room in LiveKit, you can use the following methods depending on the platform you are using: • Swift SDK: Implement the
RoomDelegate
protocol and use the
room(_:participantDidDisconnect:)
method. For example:
Copy code
func room(_ room: Room, participantDidDisconnect participant: RemoteParticipant) {
    // Handle participant disconnection
}
Flutter SDK: Listen for the
ParticipantDisconnectedEvent
emitted by the
Room
class when a
RemoteParticipant
leaves the room. • Android SDK: Listen for the
ParticipantDisconnected
event which is triggered when a
RemoteParticipant
leaves after the local participant has joined. Each of these methods provides access to the RemoteParticipant object that has disconnected, allowing you to identify which participant left the room. Let me know if you need further assistance! Sources: room(_:participantDidDisconnect:) | Documentation | ParticipantDisconnectedEvent class - livekit_client library - Dart API | RoomEvent
a
give me an example for the python
t
In Python, you can detect participant disconnection in LiveKit by checking the disconnect_reason property of a Participant object. This property provides the reason for disconnection, such as: •
CLIENT_INITIATED
- The client initiated the disconnect. •
DUPLICATE_IDENTITY
- Another participant with the same identity joined the room. •
SERVER_SHUTDOWN
- The server instance is shutting down. •
PARTICIPANT_REMOVED
-
RoomService.RemoveParticipant
was called. •
ROOM_DELETED
-
RoomService.DeleteRoom
was called. •
STATE_MISMATCH
- Client attempting to resume a session the server isn’t aware of. •
JOIN_FAILURE
- Client was unable to connect fully. Here’s an example of how you might use this in your code:
Copy code
# Example to check disconnection reason
if participant.disconnect_reason:
    print(f"Participant {participant.identity} disconnected due to: {participant.disconnect_reason}")
Let me know if you need further clarification or additional examples! Sources: livekit.rtc.participant API documentation
a
I want the event.. where participant lefts the conversation in between
t
I'm sorry, but I don't have the information you need at the moment. If you would like a member of the LiveKit team to respond, please ask your question in one of the other channels.