does egress recieves disconnect reason from liveki...
# ask-ai
c
does egress recieves disconnect reason from livekit server?
t
Thanks for reaching out, shahi. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely! Egress participants can indeed receive disconnect reasons from the LiveKit server. The LiveKit protocol thoughtfully includes a
disconnect_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 Docs
c
in livekit-server-sdk-go recieves disconnect reason ?
t
I'm happy to let you know that the LiveKit server SDK for Go does indeed receive disconnect reasons. It offers a
DisconnectionReason
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.go
c
what is about engine.go ? what disconnec reason its getting
t
In the
engine.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 Docs
c
how to pass on this disconnect reason to sdk.go callback
t
I'm glad you're looking into how to pass disconnect reasons from
engine.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:
Copy code
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.go
c
not understand .can you please elaborate and share the code changes
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!