fix for dtmf handler when running multiple instances on same EC2

This commit is contained in:
Dave Horton
2022-11-01 15:40:37 -04:00
parent c78ec892b9
commit 26169517dc
3 changed files with 28 additions and 15 deletions
+20 -7
View File
@@ -84,6 +84,20 @@ class CallSession extends Emitter {
return this.req.has('X-Five9-StreamingPairId');
}
subscribeForDTMF(dlg) {
if (!this._subscribedForDTMF) {
this._subscribedForDTMF = true;
this.subscribeDTMF(this.logger, this.req.get('Call-ID'), this.rtpEngineOpts.uas.tag,
this._onDTMF.bind(this, dlg));
}
}
unsubscribeForDTMF() {
if (this._subscribedForDTMF) {
this._subscribedForDTMF = false;
this.unsubscribeDTMF(this.logger, this.req.get('Call-ID'), this.rtpEngineOpts.uas.tag);
}
}
async connect() {
const {sdp} = this.req.locals;
this.logger.info('inbound call accepted for routing');
@@ -290,8 +304,7 @@ class CallSession extends Emitter {
_setDlgHandlers(dlg) {
const {callId} = dlg.sip;
this.activeCallIds.set(callId, this);
this.subscribeDTMF(this.logger, callId, this.rtpEngineOpts.uas.tag,
this._onDTMF.bind(this));
this.subscribeForDTMF(dlg);
dlg.on('destroy', () => {
debug('call ended with normal termination');
this.logger.info('call ended with normal termination');
@@ -339,7 +352,8 @@ class CallSession extends Emitter {
try {
await other.destroy();
} catch (err) {}
this.unsubscribeDTMF(this.logger, this.req.get('Call-ID'), this.rtpEngineOpts.uas.tag);
this.unsubscribeForDTMF();
const trackingOn = process.env.JAMBONES_TRACK_ACCOUNT_CALLS ||
process.env.JAMBONES_TRACK_SP_CALLS ||
@@ -395,8 +409,7 @@ class CallSession extends Emitter {
});
});
this.subscribeDTMF(this.logger, this.req.get('Call-ID'), this.rtpEngineOpts.uas.tag,
this._onDTMF.bind(this, uac));
this.subscribeForDTMF(uac);
uas.on('modify', this._onReinvite.bind(this, uas));
uac.on('modify', this._onReinvite.bind(this, uac));
@@ -490,7 +503,7 @@ Duration=${payload.duration} `
});
}
this.unsubscribeDTMF(this.logger, this.req.get('Call-ID'), this.rtpEngineOpts.uas.tag);
this.unsubscribeForDTMF();
const uas = await this.srf.createUAS(req, res, {
localSdp: response.sdp,
@@ -883,7 +896,7 @@ Duration=${payload.duration} `
// successfully connected
this.logger.info('successfully connected new call leg for REFER');
this.unsubscribeDTMF(this.logger, this.req.get('Call-ID'), this.rtpEngineOpts.uas.tag);
this.unsubscribeForDTMF();
this.referInvite = null;
sendNotify(this.uas, '200 OK');
this.uas.destroy();
+7 -7
View File
@@ -13,7 +13,7 @@
"@jambonz/http-authenticator": "^0.2.2",
"@jambonz/http-health-check": "^0.0.1",
"@jambonz/realtimedb-helpers": "^0.4.35",
"@jambonz/rtpengine-utils": "^0.3.10",
"@jambonz/rtpengine-utils": "^0.3.11",
"@jambonz/siprec-client-utils": "^0.1.4",
"@jambonz/stats-collector": "^0.1.6",
"@jambonz/time-series": "^0.2.5",
@@ -634,9 +634,9 @@
}
},
"node_modules/@jambonz/rtpengine-utils": {
"version": "0.3.10",
"resolved": "https://registry.npmjs.org/@jambonz/rtpengine-utils/-/rtpengine-utils-0.3.10.tgz",
"integrity": "sha512-nwnHaS4vKkj5YB9HyB06ZyHu5knhSzAOeg4qMG4GS0joRAx7DVmnuPhRaQJmcVAgZm9VuDfxSFQrGIot/oVBBQ==",
"version": "0.3.11",
"resolved": "https://registry.npmjs.org/@jambonz/rtpengine-utils/-/rtpengine-utils-0.3.11.tgz",
"integrity": "sha512-+WDZrAje2ww7zBY2+DYgPdiDg+Uh9qC4B/+EfQ/ghjseausaUWhUCDuJOdFQtHXA1qtEiMxTD1argeC5DtJBYQ==",
"dependencies": {
"debug": "^4.3.1",
"rtpengine-client": "^0.3.9",
@@ -6259,9 +6259,9 @@
}
},
"@jambonz/rtpengine-utils": {
"version": "0.3.10",
"resolved": "https://registry.npmjs.org/@jambonz/rtpengine-utils/-/rtpengine-utils-0.3.10.tgz",
"integrity": "sha512-nwnHaS4vKkj5YB9HyB06ZyHu5knhSzAOeg4qMG4GS0joRAx7DVmnuPhRaQJmcVAgZm9VuDfxSFQrGIot/oVBBQ==",
"version": "0.3.11",
"resolved": "https://registry.npmjs.org/@jambonz/rtpengine-utils/-/rtpengine-utils-0.3.11.tgz",
"integrity": "sha512-+WDZrAje2ww7zBY2+DYgPdiDg+Uh9qC4B/+EfQ/ghjseausaUWhUCDuJOdFQtHXA1qtEiMxTD1argeC5DtJBYQ==",
"requires": {
"debug": "^4.3.1",
"rtpengine-client": "^0.3.9",
+1 -1
View File
@@ -29,7 +29,7 @@
"@jambonz/realtimedb-helpers": "^0.4.35",
"@jambonz/http-authenticator": "^0.2.2",
"@jambonz/http-health-check": "^0.0.1",
"@jambonz/rtpengine-utils": "^0.3.10",
"@jambonz/rtpengine-utils": "^0.3.11",
"@jambonz/siprec-client-utils": "^0.1.4",
"@jambonz/stats-collector": "^0.1.6",
"@jambonz/time-series": "^0.2.5",