fix(voice-call): auto-end call when media stream disconnects

When a Twilio media stream disconnects (e.g., caller hangs up or
network drops), the call object was left in an active state indefinitely.
This caused "stuck calls" that consumed resources and blocked new calls.

Now calls are automatically ended when their media stream closes,
matching the expected lifecycle behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
JayMishra-github
2026-02-16 10:13:29 -08:00
committed by Peter Steinberger
parent a5c94b8e7b
commit 3eec5e54b1

View File

@@ -181,6 +181,13 @@ export class VoiceCallWebhookServer {
},
onDisconnect: (callId) => {
console.log(`[voice-call] Media stream disconnected: ${callId}`);
// Auto-end call when media stream disconnects to prevent stuck calls.
// Without this, calls can remain active indefinitely after the stream closes.
const disconnectedCall = this.manager.getCallByProviderCallId(callId);
if (disconnectedCall) {
console.log(`[voice-call] Auto-ending call ${disconnectedCall.callId} on stream disconnect`);
void this.manager.endCall(disconnectedCall.callId).catch(() => {});
}
if (this.provider.name === "twilio") {
(this.provider as TwilioProvider).unregisterCallStream(callId);
}