Reconnection & Call Recovery
Network interruptions happen — Wi-Fi drops, VPNs reconnect, laptops sleep. The Telnyx WebRTC JS SDK automatically handles reconnection so your users experience minimal disruption.How Reconnection Works
When the WebSocket connection tortc.telnyx.com drops:
- SDK detects the disconnect via WebSocket
closeorerrorevent, or via active-call signaling health checks when the socket is half-dead - SDK attempts reconnection after a randomized 2-6 second delay
- On successful reconnect, the SDK re-authenticates and re-attaches to existing calls
- If reconnection fails after
maxReconnectAttemptsattempts (default: 10), theRECONNECTION_EXHAUSTEDerror is emitted
When Calls Survive Reconnection
Calls can survive a brief WebSocket disconnect if:
Configuration:
keepConnectionAliveOnSocketClose is enabled:
- The PeerConnection (WebRTC media) stays alive even when the WebSocket (signaling) drops
- Audio continues flowing during the reconnection attempt
- On reconnect, the SDK re-attaches the existing call to the new WebSocket
- The call ID may change — use
recoveredCallIdto correlate
recoveredCallId
After a successful reconnection, the call may have a new ID. The previous ID is available as recoveredCallId:
When Calls Don’t Survive
When a call doesn’t survive reconnection, the SDK emits a
hangup state for that call.
Handling Reconnection in Your UI
Show reconnection status
Handle recovered calls
Handle signaling and media recovery warnings
During an active call, the SDK monitors WebSocket signaling liveness and media flow. If the browser reports the WebSocket as open but signaling stops flowing, the SDK emitstelnyx.warning and force-closes the socket to trigger reconnect + call reattach. If signaling is healthy but media is unhealthy, the SDK emits a media recovery warning and attempts ICE restart instead.
telnyx.ready, a recovered callUpdate, or a final hangup before cleaning up the call.
Inbound Calls After Reconnection
After a WebSocket reconnect, the browser may need to re-acquire microphone permissions to receive inbound calls. This is a browser security requirement, not an SDK limitation.mediaPermissionsRecovery
Handle microphone permission failures for inbound calls with a recoverable error pattern. When enabled and getUserMedia fails while answering, the SDK emits a recoverable telnyx.error event with resume() and reject() callbacks so your app can prompt the user to fix permissions before the call fails:
- An inbound call arrives and the user tries to answer
getUserMedia()fails (permission denied, device busy, etc.)- Instead of immediately failing the call, SDK emits a recoverable error with
resume()andreject()callbacks - Your app shows a UI prompting the user to grant permissions
- If the user fixes permissions and you call
resume(), the SDK retriesgetUserMedia() - If the user declines or
timeoutexpires, the call is terminated
mediaPermissionsRecovery only works for inbound calls. Recovery is attempted only when the initial getUserMedia call fails while answering.Page Lifecycle and Call Report Flush
When the browser page is unloaded (close, reload, navigation), the SDK’s behavior depends on thehangupOnBeforeUnload option:
When
hangupOnBeforeUnload: false, active calls never hang up on unload, so a normal telnyx.stats.report (end-of-call report) would never fire for a call the user reloads or closes on. To prevent data loss, the SDK flushes an intermediate call report using navigator.sendBeacon / keepalive on visibilitychange → hidden — the last event reliably observable on both desktop and mobile before the page tears down.
The
visibilitychange → hidden flush is available since SDK v2.27.4. It mirrors the call report collector’s POST/retry/keepalive shape, ensuring the report reaches the stats endpoint even during page teardown.Explicit Disconnect
When a user intentionally disconnects (e.g., signs out), you want to prevent automatic reconnection:clearReconnectToken() removes the session token that the SDK uses for automatic reconnection. After calling it, the SDK will not attempt to reconnect.
Common Issues
Rapid reconnection loops
Symptom: WebSocket connects and immediately disconnects, repeating rapidly. Cause: Usually an authentication issue — the JWT has expired or the credential has been revoked. Fix:- Check that the JWT is still valid
- Verify the credential still exists in the Telnyx Portal
- Check for
telnyx.errorevents withAUTH_FAILEDcode
RECONNECTION_EXHAUSTED
Symptom: SDK stops trying to reconnect after multiple failures.
Cause: Automatic reconnect reached maxReconnectAttempts (default: 10). The SDK uses a randomized 2-6 second delay between attempts; set maxReconnectAttempts: 0 only if your app should retry indefinitely.
Fix:
- Check network connectivity
- Verify
rtc.telnyx.comis reachable - Offer a manual “Reconnect” button in the UI:
Calls die after network change (Wi-Fi → Cellular)
Symptom: Call drops when switching networks, even withkeepConnectionAliveOnSocketClose.
Cause: The PeerConnection’s ICE candidates are tied to the old network. The new network has different candidates that weren’t part of the original negotiation.
Fix: This is a WebRTC limitation. The SDK attempts ICE restart, but it may not always succeed. The user will need to place a new call.
Configuration Summary
See Also
- TelnyxRTC Class — Client configuration and methods
- IClientOptions — Full configuration reference
- Error Handling — Error codes including reconnection errors
- Best Practices — Production reconnection guidance