Skip to content

Commit a12b114

Browse files
author
Matt Preskett
committed
Update _onFeatureServerTransfer to fix REFER case
1 parent d50272d commit a12b114

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

lib/call-session.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -878,35 +878,45 @@ Duration=${payload.duration} `
878878
...(req.has('X-Retain-Call-Sid') && {'X-Retain-Call-Sid': req.get('X-Retain-Call-Sid')}),
879879
...(req.has('X-Account-Sid') && {'X-Account-Sid': req.get('X-Account-Sid')})
880880
};
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', () => {
888889
this.logger.info('call ended with normal termination');
889890
this.rtpEngineResource.destroy();
890891
this.activeCallIds.delete(this.req.get('Call-ID'));
891892
if (this.activeCallIds.size === 0) this.idleEmitter.emit('idle');
892-
this.uas.other.destroy();
893+
uac.other.destroy();
893894
this.srf.endSession(this.req);
894895
});
895896

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);
898903
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)}`);
900905
}
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+
};
904912
response = await this.answer(opts);
905913
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)}`);
907915
}
916+
dlg.destroy().catch(() => {});
908917
this.logger.info('successfully moved call to new feature server');
909918
} catch (err) {
919+
res.send(488);
910920
this.logger.error(err, 'Error handling refer from feature server');
911921
}
912922
}

0 commit comments

Comments
 (0)