From b1ceadcf02b387ec08ceaef1656cd50e7cb51bf3 Mon Sep 17 00:00:00 2001 From: Arvind Rk Date: Wed, 24 Sep 2025 13:21:29 -0700 Subject: [PATCH] updates --- vapi.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/vapi.ts b/vapi.ts index 3809101fd..3eff1e514 100644 --- a/vapi.ts +++ b/vapi.ts @@ -216,11 +216,13 @@ export default class Vapi extends VapiEventEmitter { this.dailyCallObject = createSafeDailyFactoryOptions(dailyCallObject); } - private cleanup() { + private async cleanup() { this.started = false; this.hasEmittedCallEndedStatus = false; - this.call?.destroy(); - this.call = null; + if (this.call) { + await this.call.destroy(); + this.call = null; + } this.speakingTimeout = null; } @@ -325,7 +327,7 @@ export default class Vapi extends VapiEventEmitter { timestamp: new Date().toISOString(), metadata: { action: 'cleanup-existing' } }); - this.cleanup(); + await this.cleanup(); } const isVideoRecordingEnabled = @@ -395,7 +397,7 @@ export default class Vapi extends VapiEventEmitter { if (isVideoRecordingEnabled) { this.call?.stopRecording(); } - this.cleanup(); + this.cleanup().catch(console.error); }); this.call.on('error', (error: any) => { @@ -743,7 +745,7 @@ export default class Vapi extends VapiEventEmitter { } }); - this.cleanup(); + await this.cleanup(); return null; } } @@ -800,10 +802,13 @@ export default class Vapi extends VapiEventEmitter { }, 1000); } - stop(): void { + async stop(): Promise { this.started = false; - this.call?.destroy(); - this.call = null; + if (this.call) { + await this.call.destroy(); + this.call = null; + } + this.speakingTimeout = null; } send(message: VapiClientToServerMessage): void {