Skip to content

Commit 70c5216

Browse files
authored
updates (#141)
1 parent 157c5c2 commit 70c5216

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

vapi.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,13 @@ export default class Vapi extends VapiEventEmitter {
216216
this.dailyCallObject = createSafeDailyFactoryOptions(dailyCallObject);
217217
}
218218

219-
private cleanup() {
219+
private async cleanup() {
220220
this.started = false;
221221
this.hasEmittedCallEndedStatus = false;
222-
this.call?.destroy();
223-
this.call = null;
222+
if (this.call) {
223+
await this.call.destroy();
224+
this.call = null;
225+
}
224226
this.speakingTimeout = null;
225227
}
226228

@@ -325,7 +327,7 @@ export default class Vapi extends VapiEventEmitter {
325327
timestamp: new Date().toISOString(),
326328
metadata: { action: 'cleanup-existing' }
327329
});
328-
this.cleanup();
330+
await this.cleanup();
329331
}
330332

331333
const isVideoRecordingEnabled =
@@ -395,7 +397,7 @@ export default class Vapi extends VapiEventEmitter {
395397
if (isVideoRecordingEnabled) {
396398
this.call?.stopRecording();
397399
}
398-
this.cleanup();
400+
this.cleanup().catch(console.error);
399401
});
400402

401403
this.call.on('error', (error: any) => {
@@ -743,7 +745,7 @@ export default class Vapi extends VapiEventEmitter {
743745
}
744746
});
745747

746-
this.cleanup();
748+
await this.cleanup();
747749
return null;
748750
}
749751
}
@@ -800,10 +802,13 @@ export default class Vapi extends VapiEventEmitter {
800802
}, 1000);
801803
}
802804

803-
stop(): void {
805+
async stop(): Promise<void> {
804806
this.started = false;
805-
this.call?.destroy();
806-
this.call = null;
807+
if (this.call) {
808+
await this.call.destroy();
809+
this.call = null;
810+
}
811+
this.speakingTimeout = null;
807812
}
808813

809814
send(message: VapiClientToServerMessage): void {

0 commit comments

Comments
 (0)