Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions vapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -743,7 +745,7 @@ export default class Vapi extends VapiEventEmitter {
}
});

this.cleanup();
await this.cleanup();
return null;
}
}
Expand Down Expand Up @@ -800,10 +802,13 @@ export default class Vapi extends VapiEventEmitter {
}, 1000);
}

stop(): void {
async stop(): Promise<void> {
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 {
Expand Down