@@ -878,35 +878,45 @@ Duration=${payload.duration} `
878
878
...( req . has ( 'X-Retain-Call-Sid' ) && { 'X-Retain-Call-Sid' : req . get ( 'X-Retain-Call-Sid' ) } ) ,
879
879
...( req . has ( 'X-Account-Sid' ) && { 'X-Account-Sid' : req . get ( 'X-Account-Sid' ) } )
880
880
} ;
881
- const dlg = await this . srf . createUAC ( referTo . uri , { localSdp : dlg . local . sdp , headers} ) ;
882
- this . uas = dlg ;
883
- this . uas . other = this . uac ;
884
- this . uac . other = this . uas ;
885
- this . uas . on ( 'modify' , this . _onReinvite . bind ( this , this . uas ) ) ;
886
- this . uas . on ( 'refer' , this . _onFeatureServerTransfer . bind ( this , this . uas ) ) ;
887
- this . uas . on ( 'destroy' , ( ) => {
881
+
882
+ const uac = await this . srf . createUAC ( referTo . uri , { localSdp : dlg . local . sdp , headers} ) ;
883
+ this . uas = uac ;
884
+ uac . other = this . uac ;
885
+ this . uac . other = uac ;
886
+ uac . on ( 'modify' , this . _onReinvite . bind ( this , uac ) ) ;
887
+ uac . on ( 'refer' , this . _onFeatureServerTransfer . bind ( this , uac ) ) ;
888
+ uac . on ( 'destroy' , ( ) => {
888
889
this . logger . info ( 'call ended with normal termination' ) ;
889
890
this . rtpEngineResource . destroy ( ) ;
890
891
this . activeCallIds . delete ( this . req . get ( 'Call-ID' ) ) ;
891
892
if ( this . activeCallIds . size === 0 ) this . idleEmitter . emit ( 'idle' ) ;
892
- this . uas . other . destroy ( ) ;
893
+ uac . other . destroy ( ) ;
893
894
this . srf . endSession ( this . req ) ;
894
895
} ) ;
895
896
896
- // modify rtpengine to stream to new feature server
897
- let response = await this . offer ( Object . assign ( this . rtpEngineOpts . offer , { sdp : this . uas . remote . sdp } ) ) ;
897
+ let opts = {
898
+ ...this . rtpEngineOpts . common ,
899
+ 'from-tag' : this . rtpEngineOpts . uas . tag ,
900
+ sdp : uac . remote . sdp
901
+ } ;
902
+ let response = await this . offer ( opts ) ;
898
903
if ( 'ok' !== response . result ) {
899
- throw new Error ( `_onReinvite : rtpengine failed: offer: ${ JSON . stringify ( response ) } ` ) ;
904
+ throw new Error ( `_onFeatureServerTransfer : rtpengine offer failed : ${ JSON . stringify ( response ) } ` ) ;
900
905
}
901
- const sdp = await this . uas . other . modify ( response . sdp ) ;
902
- const opts = Object . assign ( { sdp, 'to-tag' : res . getParsedHeader ( 'To' ) . params . tag } ,
903
- this . rtpEngineOpts . answer ) ;
906
+ opts = {
907
+ ...this . rtpEngineOpts . common ,
908
+ 'from-tag' : this . rtpEngineOpts . uas . tag ,
909
+ 'to-tag' : this . rtpEngineOpts . uac . tag ,
910
+ sdp : await uac . other . modify ( response . sdp )
911
+ } ;
904
912
response = await this . answer ( opts ) ;
905
913
if ( 'ok' !== response . result ) {
906
- throw new Error ( `_onReinvite : rtpengine failed: ${ JSON . stringify ( response ) } ` ) ;
914
+ throw new Error ( `_onFeatureServerTransfer : rtpengine answer failed: ${ JSON . stringify ( response ) } ` ) ;
907
915
}
916
+ dlg . destroy ( ) . catch ( ( ) => { } ) ;
908
917
this . logger . info ( 'successfully moved call to new feature server' ) ;
909
918
} catch ( err ) {
919
+ res . send ( 488 ) ;
910
920
this . logger . error ( err , 'Error handling refer from feature server' ) ;
911
921
}
912
922
}
0 commit comments