diff --git a/lib/call-session.js b/lib/call-session.js index 366b8b3..9cf6f00 100644 --- a/lib/call-session.js +++ b/lib/call-session.js @@ -904,6 +904,7 @@ Duration=${payload.duration} ` this.uac = uac; uac.other = this.uas; this.uas.other = uac; + uac.on('info', this._onInfo.bind(this, uac)); uac.on('modify', this._onReinvite.bind(this, uac)); uac.on('refer', this._onFeatureServerTransfer.bind(this, uac)); uac.on('destroy', () => { @@ -913,19 +914,22 @@ Duration=${payload.duration} ` uac.other.destroy(); this.srf.endSession(this.req); }); - // now we can destroy the old dialog - dlg.destroy().catch(() => {}); - // modify rtpengine to stream to new feature server - const opts = Object.assign({sdp: uac.remote.sdp, 'to-tag': res.getParsedHeader('To').params.tag}, - this.rtpEngineOpts.answer); + const opts = { + ...this.rtpEngineOpts.common, + 'from-tag': this.rtpEngineOpts.uas.tag, + 'to-tag': this.rtpEngineOpts.uac.tag, + sdp: uac.remote.sdp, + flags: ['port latching'] + }; const response = await this.answer(opts); if ('ok' !== response.result) { - res.send(488); - throw new Error(`_onFeatureServerTransfer: rtpengine failed: ${JSON.stringify(response)}`); + throw new Error(`_onFeatureServerTransfer: rtpengine answer failed: ${JSON.stringify(response)}`); } + dlg.destroy().catch(() => {}); this.logger.info('successfully moved call to new feature server'); } catch (err) { + res.send(488); this.logger.error(err, 'Error handling refer from feature server'); } }