proud-lawyer-39815
10/21/2025, 12:36 AMtall-airline-16756
10/21/2025, 12:36 AMproud-lawyer-39815
10/21/2025, 12:36 AMtall-airline-16756
10/21/2025, 12:37 AMrtc.DisconnectReason in the Python SDK, you can use the Name() method provided by protobuf. Here’s a little example to guide you:
from livekit import rtc
# If you have a DisconnectReason value
reason = rtc.DisconnectReason.CLIENT_INITIATED
reason_string = rtc.DisconnectReason.Name(reason)
# This should return "CLIENT_INITIATED"
If you find that the Name() method isn’t available, no worries! You can simply try converting it directly to a string like this:
reason_string = str(reason)
Please feel free to reach out if you have any more questions or need a hand with this—I’m here to help!proud-lawyer-39815
10/21/2025, 12:39 AMrtc.DisconnectReason that is sent from the room. When I convert to string, I stil get a number.tall-airline-16756
10/21/2025, 12:41 AMName() method isn’t available in your situation. No worries! You can still map the integer values of rtc.DisconnectReason to their string names manually. Here’s a little function that can help you do just that:
from livekit.rtc import DisconnectReason
def disconnect_reason_to_string(reason_value):
reason_map = {
DisconnectReason.UNKNOWN_REASON: "UNKNOWN_REASON",
DisconnectReason.CLIENT_INITIATED: "CLIENT_INITIATED",
DisconnectReason.DUPLICATE_IDENTITY: "DUPLICATE_IDENTITY",
DisconnectReason.SERVER_SHUTDOWN: "SERVER_SHUTDOWN",
DisconnectReason.PARTICIPANT_REMOVED: "PARTICIPANT_REMOVED",
DisconnectReason.ROOM_DELETED: "ROOM_DELETED",
DisconnectReason.STATE_MISMATCH: "STATE_MISMATCH",
DisconnectReason.JOIN_FAILURE: "JOIN_FAILURE",
DisconnectReason.MIGRATION: "MIGRATION",
DisconnectReason.SIGNAL_CLOSE: "SIGNAL_CLOSE",
DisconnectReason.ROOM_CLOSED: "ROOM_CLOSED",
DisconnectReason.USER_UNAVAILABLE: "USER_UNAVAILABLE",
DisconnectReason.USER_REJECTED: "USER_REJECTED",
DisconnectReason.SIP_TRUNK_FAILURE: "SIP_TRUNK_FAILURE",
DisconnectReason.CONNECTION_TIMEOUT: "CONNECTION_TIMEOUT",
DisconnectReason.MEDIA_FAILURE: "MEDIA_FAILURE"
}
return reason_map.get(reason_value, "UNKNOWN_REASON")
# Example usage
reason = rtc.DisconnectReason.CLIENT_INITIATED
print(disconnect_reason_to_string(reason)) # Output: "CLIENT_INITIATED"
This way, you’ll be able to cover all the disconnect reasons smoothly. If anything’s unclear or you want me to walk you through it, just let me know—I’m here to help!
Sources: livekit-protocol/livekit/protocol/models.pyi | livekit-protocol/src/livekit.rs | agent-console/lib/event-types.ts | packages/livekit-rtc/src/proto/participant_pb.tsproud-lawyer-39815
10/21/2025, 12:43 AMtall-airline-16756
10/21/2025, 12:45 AM