hi, when SIP user cuts the call when will livekit ...
# ask-ai
g
hi, when SIP user cuts the call when will livekit get to know participant disconnected?, is it instant or takes some seconds of time
✅ 1
t
Thanks for reaching out, vishnu. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — good question. Regarding SIP callers: LiveKit does not detect the disconnect truly instantly. When a SIP user hangs up, LiveKit waits for the peer connection/keep-alive signals to stop (ICE/STUN) and then marks the participant disconnected — this typically takes on the order of ~15 seconds. After that timeout LiveKit emits the participant-left/webhook events and the disconnect reason is usually reported as a connection timeout/STATE_MISMATCH. Would you like suggestions for reducing that delay (e.g., signaling changes or detecting SIP hangup earlier in your SIP gateway)? Sources: Understanding the STATE_MISMATCH Disconnect Reason, with interactive elements
g
yes, i want to calculate the actual call duration, so when user cuts the call i want to know as soon as possible
t
Thanks — I’m responding about detecting SIP hangups as quickly as possible so you can calculate accurate call duration. Short answer: • LiveKit detects an unclean SIP disconnect based on WebRTC keep-alives and typically takes ~15–20 seconds to mark the participant disconnected and emit
participant_left
. That delay is normal to avoid false disconnects from transient network blips. Options to get the hangup time earlier (pick one or more that fit your setup): • Have your SIP gateway send an explicit event to your backend when the SIP user hangs up, and record that timestamp as the call end. Use LiveKit webhooks (`participant_joined`/`participant_left`) as a fallback to verify or reconcile later. • If your SIP gateway can call LiveKit APIs, call
RemoveParticipant
or tell the LiveKit room to
leave()
the participant immediately when SIP BYE is received — LiveKit will then emit
participant_left
immediately with a clean disconnect reason. • Add an application-level heartbeat between your SIP gateway and your backend to detect disconnects faster than the SFU timeout; when the heartbeat stops, mark the call ended. • Continue to consume
participant_left
webhooks to cover unclean cases and map disconnect reasons (
CLIENT_INITIATED
vs `CONNECTION_TIMEOUT`/`STATE_MISMATCH`) when reconciling durations. Which option would you prefer or can you implement in your SIP gateway: (A) send a direct hangup event to your backend, or (B) call LiveKit to remove the participant on SIP BYE? Tell me which and I’ll give exact implementation steps. , with interactive elements