track account level calls if env JAMBONES_TRACK_ACCOUNT_CALLS is set

This commit is contained in:
Dave Horton
2022-04-01 06:51:44 -04:00
parent f1e2f192b7
commit 17b53438e2
2 changed files with 4 additions and 3 deletions
+2 -2
View File
@@ -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'));
}
+2 -1
View File
@@ -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 ?