@@ -216,11 +216,13 @@ export default class Vapi extends VapiEventEmitter {
216
216
this . dailyCallObject = createSafeDailyFactoryOptions ( dailyCallObject ) ;
217
217
}
218
218
219
- private cleanup ( ) {
219
+ private async cleanup ( ) {
220
220
this . started = false ;
221
221
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
+ }
224
226
this . speakingTimeout = null ;
225
227
}
226
228
@@ -325,7 +327,7 @@ export default class Vapi extends VapiEventEmitter {
325
327
timestamp : new Date ( ) . toISOString ( ) ,
326
328
metadata : { action : 'cleanup-existing' }
327
329
} ) ;
328
- this . cleanup ( ) ;
330
+ await this . cleanup ( ) ;
329
331
}
330
332
331
333
const isVideoRecordingEnabled =
@@ -395,7 +397,7 @@ export default class Vapi extends VapiEventEmitter {
395
397
if ( isVideoRecordingEnabled ) {
396
398
this . call ?. stopRecording ( ) ;
397
399
}
398
- this . cleanup ( ) ;
400
+ this . cleanup ( ) . catch ( console . error ) ;
399
401
} ) ;
400
402
401
403
this . call . on ( 'error' , ( error : any ) => {
@@ -743,7 +745,7 @@ export default class Vapi extends VapiEventEmitter {
743
745
}
744
746
} ) ;
745
747
746
- this . cleanup ( ) ;
748
+ await this . cleanup ( ) ;
747
749
return null ;
748
750
}
749
751
}
@@ -800,10 +802,13 @@ export default class Vapi extends VapiEventEmitter {
800
802
} , 1000 ) ;
801
803
}
802
804
803
- stop ( ) : void {
805
+ async stop ( ) : Promise < void > {
804
806
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 ;
807
812
}
808
813
809
814
send ( message : VapiClientToServerMessage ) : void {
0 commit comments