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