how can I print the disconnect reason on participa...
# ask-ai
w
how can I print the disconnect reason on participant disconnect without parsing the protobuf int
t
Thanks for reaching out, Drew. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to print the disconnect reason for a participant without digging into the protobuf integer, you can simply use the
disconnect_reason
property on the
Participant
object. The
DisconnectReason
enum gives you a friendly, human-readable name for each reason. Here’s a quick example for you:
Copy code
from livekit import DisconnectReason

# Assuming 'participant' is your Participant object
reason = participant.disconnect_reason
if reason:
    print(f"Disconnected with reason: {reason.name}")
Just a few things to keep in mind: • The
disconnect_reason
property will be
None
if the participant is still connected. • The
name
property turns the enum value into a readable string like "CLIENT_INITIATED" or "SERVER_SHUTDOWN". • The
DisconnectReason
enum covers all the possible disconnect reasons, including
CLIENT_INITIATED
,
SERVER_SHUTDOWN
, and more. If you have any more questions or need a hand with anything else, just let me know—I’m here to help! Sources: livekit-rtc/livekit/rtc/participant.py
p
How can I convert all numbers to the actual reason string?
t
I'd love to help you with this! Could you please share which SDK or programming language you're using? For instance, are you working with Python, Go, Rust, or maybe another SDK? Knowing this will allow me to give you the best guidance on how to convert all numbers to their corresponding reason strings. Sources: livekit-protocol/src/livekit.rs | livekit-agents/livekit/agents/voice/room_io/room_io.py | pkg/rtc/types/interfaces.go | livekit-android-sdk/src/main/java/io/livekit/android/events/RoomEvent.kt