i'm not able to see a livekit call ended when a pa...
# ask-ai
a
i'm not able to see a livekit call ended when a participant hangs up. We are not getting this event. Is there something I need to enact on the SIP connector side (currently using twilio directly) to inform livekit of a disconnect?
t
Thanks for reaching out, Adam. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm here to help you make sure LiveKit detects when a participant disconnects during a call using the SIP connector with Twilio. Let's walk through these steps together: • First, listen for the
participantDisconnected
event in your application code. This event fires whenever a participant, including those using SIP, leaves the room. You can use this snippet:
room.on('participantDisconnected', participant => { /* handle disconnect */ });
• Keep an eye on the
sip.callStatus
attribute to track real-time call state changes. When the call ends, you’ll see it update to
hangup
. • Make sure your Twilio SIP trunk is set up correctly with the right origination URL and credentials—this helps avoid any signaling hiccups. • Also, double-check that your application is actively subscribed to the room events and that nothing’s blocking event delivery, like network interruptions. If you find that disconnect events still aren’t coming through, a helpful tip is to cross-reference Twilio’s call logs using the
sip.twilio.callSid
attribute. This way, you can confirm exactly when and why the call ended. Sources: quickstart/src/joinroom.js | Making outbound calls | LiveKit Docs | packages/livekit-rtc/src/proto/participant_pb.ts | Tests/PlayMode/RoomTests.cs | SIP participant | LiveKit Docs
a
I'm using python and room.on('participant_disconnected') is never fired on a caller hangup
t
I'm here to help you with the
participant_disconnected
event in the Python SDK, which should fire when a caller hangs up. Let’s walk through some steps together to see why it might not be firing: • First, please double-check that you’re using the exact event name:
participant_disconnected
(with underscores), not
participantDisconnected
(camelCase). • Make sure your event handler is set up correctly. Here’s a simple example you can compare with:
Copy code
@room.on("participant_disconnected")
def on_participant_disconnected(participant):
    print(f"Participant disconnected: {participant.identity}")
• If you’re working with SIP participants, sometimes disconnection is indicated through
participant_attributes_changed
. Keep an eye on the
sip.callStatus
attribute for the value
hangup
. • Turning on debug logging can be really helpful to spot any errors or missed events. You can do this with:
Copy code
import logging
logging.basicConfig(level=logging.DEBUG)
• Also, it’s a good idea to confirm your SDK is updated to the latest version, as older versions might have some event propagation issues. If you’re still running into trouble, please feel free to share any related logs or details about how the disconnection is happening (like SIP hangup or server-side termination). I’m here to support you through this! Sources: stream_audio.py | terminal-client/client.py | Connecting to LiveKit | LiveKit Docs | telephony/sip_lifecycle.py | livekit-rtc/livekit/rtc/_proto/room_pb2.pyi
r
Same issue it never disconnects on hangup its relying on the 15 sec silence timeout
t
It looks like the disconnection is currently based on a 15-second silence timeout instead of detecting the hangup directly. To help you improve this, here are a few suggestions you might find useful: • Keep an eye on the
sip.callStatus
attribute for SIP participants. When it switches to
hangup
, you can immediately handle the disconnection. • Consider using a silence detection system to monitor user activity, so you can disconnect participants after a set period of inactivity. For example, tracking the last time someone spoke and disconnecting them if the silence goes beyond your threshold. • Make sure your SIP trunk is correctly configured to send signaling updates to LiveKit, since any misconfiguration might delay or block disconnection events. If you'd like, I’m here to help you implement these steps or troubleshoot the issue further. Just let me know! Sources: packages/livekit-server-sdk/src/SipClient.ts | How to detect and handle silence during calls | SIP & Telephony Applications | livekit/livekit_composite | DeepWiki | livekit-api/livekit/api/sip_service.py | pkg/sip/participant.go