From 26169517dc529768fcc8e105873e35f2d875b8a3 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Tue, 1 Nov 2022 15:40:37 -0400 Subject: [PATCH] fix for dtmf handler when running multiple instances on same EC2 --- lib/call-session.js | 27 ++++++++++++++++++++------- package-lock.json | 14 +++++++------- package.json | 2 +- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/lib/call-session.js b/lib/call-session.js index 137ce75..1c86159 100644 --- a/lib/call-session.js +++ b/lib/call-session.js @@ -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(); diff --git a/package-lock.json b/package-lock.json index 9f9fc36..f524cb1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index feafc19..e7d8203 100644 --- a/package.json +++ b/package.json @@ -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",