Skip to content

Commit 7f2bce9

Browse files
two56Matt Preskett
andauthored
Fix: Feature server REFER (#90)
* Update _onFeatureServerTransfer to fix REFER case * Avoid remote re-invite by using port latching * Add INFO listener and pretend we're a uas --------- Co-authored-by: Matt Preskett <[email protected]>
1 parent 41eaa42 commit 7f2bce9

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

lib/call-session.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -907,35 +907,38 @@ Duration=${payload.duration} `
907907
...(req.has('X-Retain-Call-Sid') && {'X-Retain-Call-Sid': req.get('X-Retain-Call-Sid')}),
908908
...(req.has('X-Account-Sid') && {'X-Account-Sid': req.get('X-Account-Sid')})
909909
};
910-
const dlg = await this.srf.createUAC(referTo.uri, {localSdp: dlg.local.sdp, headers});
911-
this.uas = dlg;
912-
this.uas.other = this.uac;
913-
this.uac.other = this.uas;
914-
this.uas.on('modify', this._onReinvite.bind(this, this.uas));
915-
this.uas.on('refer', this._onFeatureServerTransfer.bind(this, this.uas));
916-
this.uas.on('destroy', () => {
910+
911+
const uac = await this.srf.createUAC(referTo.uri, {localSdp: dlg.local.sdp, headers});
912+
this.uas = uac;
913+
uac.type = 'uas';
914+
uac.other = this.uac;
915+
this.uac.other = uac;
916+
uac.on('info', this._onInfo.bind(this, uac));
917+
uac.on('modify', this._onReinvite.bind(this, uac));
918+
uac.on('refer', this._onFeatureServerTransfer.bind(this, uac));
919+
uac.on('destroy', () => {
917920
this.logger.info('call ended with normal termination');
918921
this.rtpEngineResource.destroy();
919922
this.activeCallIds.delete(this.req.get('Call-ID'));
920923
if (this.activeCallIds.size === 0) this.idleEmitter.emit('idle');
921-
this.uas.other.destroy();
924+
uac.other.destroy();
922925
this.srf.endSession(this.req);
923926
});
924927

925-
// modify rtpengine to stream to new feature server
926-
let response = await this.offer(Object.assign(this.rtpEngineOpts.offer, {sdp: this.uas.remote.sdp}));
927-
if ('ok' !== response.result) {
928-
throw new Error(`_onReinvite: rtpengine failed: offer: ${JSON.stringify(response)}`);
929-
}
930-
const sdp = await this.uas.other.modify(response.sdp);
931-
const opts = Object.assign({sdp, 'to-tag': res.getParsedHeader('To').params.tag},
932-
this.rtpEngineOpts.answer);
933-
response = await this.answer(opts);
928+
const opts = {
929+
...this.rtpEngineOpts.common,
930+
'from-tag': this.rtpEngineOpts.uas.tag,
931+
sdp: uac.remote.sdp,
932+
flags: ['port latching']
933+
};
934+
const response = await this.offer(opts);
934935
if ('ok' !== response.result) {
935-
throw new Error(`_onReinvite: rtpengine failed: ${JSON.stringify(response)}`);
936+
throw new Error(`_onFeatureServerTransfer: rtpengine offer failed: ${JSON.stringify(response)}`);
936937
}
938+
dlg.destroy().catch(() => {});
937939
this.logger.info('successfully moved call to new feature server');
938940
} catch (err) {
941+
res.send(488);
939942
this.logger.error(err, 'Error handling refer from feature server');
940943
}
941944
}

0 commit comments

Comments
 (0)