From 17b53438e21816b2818990a69dfb74f6806738f3 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Fri, 1 Apr 2022 06:51:44 -0400 Subject: [PATCH] track account level calls if env JAMBONES_TRACK_ACCOUNT_CALLS is set --- lib/call-session.js | 4 ++-- lib/middleware.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/call-session.js b/lib/call-session.js index 68ac151..bf1e05c 100644 --- a/lib/call-session.js +++ b/lib/call-session.js @@ -256,9 +256,9 @@ class CallSession extends Emitter { await other.destroy(); } catch (err) {} this.unsubscribeDTMF(this.logger, this.req.get('Call-ID'), this.rtpEngineOpts.uas.tag); - if (process.env.JAMBONES_HOSTING) { + if (process.env.JAMBONES_HOSTING || process.env.JAMBONES_TRACK_ACCOUNT_CALLS) { this.decrKey(this.callCountKey) - .then((count) => this.logger.debug({key: this.callCountKey}, + .then((count) => this.logger.info({key: this.callCountKey}, `after hangup there are ${count} active calls for this account`)) .catch((err) => this.logger.error({err}, 'Error decrementing call count')); } diff --git a/lib/middleware.js b/lib/middleware.js index c3bb458..f139217 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -220,7 +220,7 @@ module.exports = function(srf, logger) { }; const checkLimits = async(req, res, next) => { - if (!process.env.JAMBONES_HOSTING) return next(); // skip + if (!process.env.JAMBONES_HOSTING && !process.env.JAMBONES_TRACK_ACCOUNT_CALLS) return next(); // skip const {incrKey, decrKey} = req.srf.locals.realtimeDbHelpers; const {logger, account_sid} = req.locals; @@ -244,6 +244,7 @@ module.exports = function(srf, logger) { try { /* increment the call count */ const calls = await incrKey(key); + if (!process.env.JAMBONES_HOSTING) return next(); /* compare to account's limit, though avoid db hit when call count is low */ const minLimit = process.env.MIN_CALL_LIMIT ?