cold-belgium-91163
09/25/2025, 10:49 AMtall-airline-16756
09/25/2025, 10:49 AMtall-airline-16756
09/25/2025, 10:50 AMdisconnect_reason field within the ParticipantInfo message, which helps communicate why a disconnection happened. This feature is supported across various SDKs like Python, Node.js, and Rust, making it quite versatile.
To give you a clearer picture, in the Python SDK, the disconnect_reason property of a Participant object will return one of the predefined DisconnectReason values, or None if there isn’t a specific reason. Also, when the server initiates a disconnection—say, if a room is deleted or a participant is removed—you’ll find the reason included in the Disconnected event payload.
Here are some common disconnect reasons you might encounter:
• CLIENT_INITIATED: The client chose to disconnect
• DUPLICATE_IDENTITY: Another participant joined with the same identity
• SERVER_SHUTDOWN: The server is shutting down
• PARTICIPANT_REMOVED: A participant was removed through the API
• ROOM_DELETED: The room was deleted via the API
• ROOM_CLOSED: The room closed automatically because there were no active participants
• CONNECTION_TIMEOUT: The server timed out the participant’s session
• MEDIA_FAILURE: There was a media stream failure or timeout
If you’d like, I’m more than happy to provide further details or examples to help you out. Just let me know!
Sources: livekit-rtc/livekit/rtc/participant.py | packages/livekit-rtc/src/proto/room_pb.ts | livekit-ffi/src/livekit.proto.rs | livekit/livekit_models.pb.go | Connecting to LiveKit | LiveKit Docscold-belgium-91163
09/25/2025, 10:54 AMtall-airline-16756
09/25/2025, 10:55 AMDisconnectionReason type along with a callback function OnDisconnectedWithReason inside the RoomCallback struct. This setup helps your application gracefully handle disconnection events by providing specific reasons.
The GetDisconnectionReason function is really handy—it translates protocol-level livekit.DisconnectReason values into clear, descriptive strings, like these:
• CLIENT_INITIATED: Leave requested by the user
• ROOM_CLOSED: The room was closed
• DUPLICATE_IDENTITY: Another participant with the same identity joined
• JOIN_FAILURE: Connection to the room failed
If you'd like, I’m here to help with more details or even some example code on how to use this in your Go application. Just let me know!
Sources: engine.go | protobufs/livekit_rtc.proto | pkg/rtc/types/interfaces.gocold-belgium-91163
09/25/2025, 11:06 AMtall-airline-16756
09/25/2025, 11:07 AMengine.go file of the LiveKit server SDK for Go, disconnection reasons are thoughtfully handled by mapping the protocol-level livekit.DisconnectReason enum to more user-friendly string types using the GetDisconnectionReason function. These reasons are then passed along to the OnDisconnected callback whenever a disconnection happens.
Here are some of the common disconnection reasons you might see:
• LeaveRequested: When the client initiates the disconnect
• UserUnavailable: When the SIP callee doesn’t respond
• RejectedByUser: When the SIP callee rejects the call
• Failed: When the connection fails due to issues like JOIN_FAILURE or STATE_MISMATCH
• RoomClosed: When the room closes after all participants have left
• ParticipantRemoved: When the participant is removed by the server
• DuplicateIdentity: When another participant with the same identity joins
• OtherReason: For any disconnection reasons that aren’t explicitly mapped
If you want to dig a little deeper, you can also check the original livekit.DisconnectReason values directly. The protocol includes some additional reasons like SERVER_SHUTDOWN, ROOM_DELETED, and MEDIA_FAILURE that might not be explicitly mapped in the Go SDK but are definitely good to be aware of.
Feel free to reach out if you’d like any more details or examples—I’m here to help!
Sources: room.go | livekit/livekit_models.pb.go | Connecting to LiveKit | LiveKit Docscold-belgium-91163
09/25/2025, 11:15 AMtall-airline-16756
09/25/2025, 11:16 AMengine.go to the SDK callback in the LiveKit server SDK for Go. Let me walk you through the flow step-by-step to make it clearer:
1. Receive Disconnect Signal: The RTCEngine in engine.go handles the disconnect event and extracts the livekit.DisconnectReason from the protocol layer.
2. Map to SDK Reason: Then, the GetDisconnectionReason function translates this protocol-level reason into a more user-friendly DisconnectionReason string type.
3. Trigger Engine Handler: Next, the OnDisconnected method of the engine handler is called, passing along the mapped reason.
4. Invoke Room Callback: The Room struct, which implements the engine handler interface, calls its OnDisconnected method. This, in turn, triggers your user-defined OnDisconnectedWithReason callback with the mapped reason.
5. Application Receives Reason: Finally, as the application developer, you set up a RoomCallback and provide an OnDisconnectedWithReason function to gracefully handle the disconnection reason.
Here's a simple example to define the callback:
cb := lksdk.NewRoomCallback()
cb.OnDisconnectedWithReason = func(reason lksdk.DisconnectionReason) {
fmt.Printf("Disconnected from room: %s\n", reason)
}
This way, your application gets meaningful disconnect reasons, helping you respond appropriately. If you'd like, I’m here to help with any further questions or examples you might need!
Sources: examples/openai_realtime_voice/main.gocold-belgium-91163
09/25/2025, 11:19 AMtall-airline-16756
09/25/2025, 11:19 AM