This commit is contained in:
Quan HL
2023-10-24 12:56:07 +07:00
parent 8cd91c19c9
commit 563ea405e9
5 changed files with 36 additions and 1 deletions

3
app.js
View File

@@ -67,6 +67,7 @@ const {LifeCycleEvents} = require('./lib/constants');
const setNameRtp = `${(process.env.JAMBONES_CLUSTER_ID || 'default')}:active-rtp`; const setNameRtp = `${(process.env.JAMBONES_CLUSTER_ID || 'default')}:active-rtp`;
const rtpServers = []; const rtpServers = [];
const setName = `${(process.env.JAMBONES_CLUSTER_ID || 'default')}:active-sip`; const setName = `${(process.env.JAMBONES_CLUSTER_ID || 'default')}:active-sip`;
const Registrar = require('@jambonz/mw-registrar');
const { const {
pool, pool,
@@ -101,6 +102,7 @@ const {
host: process.env.JAMBONES_REDIS_HOST, host: process.env.JAMBONES_REDIS_HOST,
port: process.env.JAMBONES_REDIS_PORT || 6379 port: process.env.JAMBONES_REDIS_PORT || 6379
}, logger); }, logger);
const registrar = new Registrar(logger, redisClient);
const ngProtocol = process.env.JAMBONES_NG_PROTOCOL || 'udp'; const ngProtocol = process.env.JAMBONES_NG_PROTOCOL || 'udp';
const ngPort = process.env.RTPENGINE_PORT || ('udp' === ngProtocol ? 22222 : 8080); const ngPort = process.env.RTPENGINE_PORT || ('udp' === ngProtocol ? 22222 : 8080);
@@ -121,6 +123,7 @@ srf.locals = {...srf.locals,
activeCallIds: new Map(), activeCallIds: new Map(),
getRtpEngine, getRtpEngine,
dbHelpers: { dbHelpers: {
registrar,
pool, pool,
ping, ping,
lookupAuthHook, lookupAuthHook,

View File

@@ -227,6 +227,9 @@ class CallSession extends Emitter {
if (this.req.locals.queue_name) { if (this.req.locals.queue_name) {
Object.assign(headers, {'X-Queue-Name': this.req.locals.queue_name}); Object.assign(headers, {'X-Queue-Name': this.req.locals.queue_name});
} }
if (this.req.locals.called_user) {
Object.assign(headers, {'X-Called-User': this.req.locals.called_user});
}
if (this.req.authorization) { if (this.req.authorization) {
if (this.req.authorization.grant && this.req.authorization.grant.application_sid) { if (this.req.authorization.grant && this.req.authorization.grant.application_sid) {
Object.assign(headers, {'X-Application-Sid': this.req.authorization.grant.application_sid}); Object.assign(headers, {'X-Application-Sid': this.req.authorization.grant.application_sid});

View File

@@ -29,7 +29,8 @@ module.exports = function(srf, logger) {
lookupAccountBySid, lookupAccountBySid,
lookupAccountCapacitiesBySid, lookupAccountCapacitiesBySid,
queryCallLimits, queryCallLimits,
lookupAppBySid lookupAppBySid,
registrar
} = srf.locals.dbHelpers; } = srf.locals.dbHelpers;
const {stats, writeCdrs} = srf.locals; const {stats, writeCdrs} = srf.locals;
@@ -198,6 +199,7 @@ module.exports = function(srf, logger) {
return req.srf.endSession(req); return req.srf.endSession(req);
} }
let deviceAppSid = null; let deviceAppSid = null;
let called_user = null;
const queue_name = uri.user.startsWith('queue-') ? uri.user.match(/queue-(.*)/)[1] : null; const queue_name = uri.user.startsWith('queue-') ? uri.user.match(/queue-(.*)/)[1] : null;
if (uri.user.startsWith('app-')) { if (uri.user.startsWith('app-')) {
// Call from registered device to test application. // Call from registered device to test application.
@@ -206,6 +208,14 @@ module.exports = function(srf, logger) {
if (app && app.account_sid === account.account_sid) { if (app && app.account_sid === account.account_sid) {
deviceAppSid = app.application_sid; deviceAppSid = app.application_sid;
} }
} else if (!queue_name) {
// check if call to registered user
const {realm} = this.req.authorization.challengeResponse;
const calledAor = `${req.calledNumber}@${realm}`;
const reg = await registrar.query(calledAor);
if (reg) {
called_user = calledAor;
}
} }
req.locals = { req.locals = {
service_provider_sid: account.service_provider_sid, service_provider_sid: account.service_provider_sid,
@@ -213,6 +223,7 @@ module.exports = function(srf, logger) {
account, account,
application_sid: deviceAppSid || account.device_calling_application_sid, application_sid: deviceAppSid || account.device_calling_application_sid,
...(queue_name && ({queue_name})), ...(queue_name && ({queue_name})),
...(called_user && ({called_user})),
webhook_secret: account.webhook_secret, webhook_secret: account.webhook_secret,
realm: uri.host, realm: uri.host,
...(account.registration_hook && { ...(account.registration_hook && {

17
package-lock.json generated
View File

@@ -14,6 +14,7 @@
"@jambonz/db-helpers": "^0.9.1", "@jambonz/db-helpers": "^0.9.1",
"@jambonz/digest-utils": "^0.0.3", "@jambonz/digest-utils": "^0.0.3",
"@jambonz/http-health-check": "^0.0.1", "@jambonz/http-health-check": "^0.0.1",
"@jambonz/mw-registrar": "^0.2.4",
"@jambonz/realtimedb-helpers": "^0.8.6", "@jambonz/realtimedb-helpers": "^0.8.6",
"@jambonz/rtpengine-utils": "^0.4.3", "@jambonz/rtpengine-utils": "^0.4.3",
"@jambonz/siprec-client-utils": "^0.2.6", "@jambonz/siprec-client-utils": "^0.2.6",
@@ -1696,6 +1697,14 @@
"node": ">=14.x" "node": ">=14.x"
} }
}, },
"node_modules/@jambonz/mw-registrar": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/@jambonz/mw-registrar/-/mw-registrar-0.2.5.tgz",
"integrity": "sha512-+aBI2xpR6Ir140Hi7/ED+z5Hl7NgCalyVzTLNlgUVzTvsMLtyZZh6n9IQipKnuKvhh4nPM4aJ+JuFhi1UH9zEA==",
"dependencies": {
"debug": "^4.3.4"
}
},
"node_modules/@jambonz/realtimedb-helpers": { "node_modules/@jambonz/realtimedb-helpers": {
"version": "0.8.6", "version": "0.8.6",
"resolved": "https://registry.npmjs.org/@jambonz/realtimedb-helpers/-/realtimedb-helpers-0.8.6.tgz", "resolved": "https://registry.npmjs.org/@jambonz/realtimedb-helpers/-/realtimedb-helpers-0.8.6.tgz",
@@ -7664,6 +7673,14 @@
"express": "^4.17.2" "express": "^4.17.2"
} }
}, },
"@jambonz/mw-registrar": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/@jambonz/mw-registrar/-/mw-registrar-0.2.5.tgz",
"integrity": "sha512-+aBI2xpR6Ir140Hi7/ED+z5Hl7NgCalyVzTLNlgUVzTvsMLtyZZh6n9IQipKnuKvhh4nPM4aJ+JuFhi1UH9zEA==",
"requires": {
"debug": "^4.3.4"
}
},
"@jambonz/realtimedb-helpers": { "@jambonz/realtimedb-helpers": {
"version": "0.8.6", "version": "0.8.6",
"resolved": "https://registry.npmjs.org/@jambonz/realtimedb-helpers/-/realtimedb-helpers-0.8.6.tgz", "resolved": "https://registry.npmjs.org/@jambonz/realtimedb-helpers/-/realtimedb-helpers-0.8.6.tgz",

View File

@@ -33,6 +33,7 @@
"@jambonz/stats-collector": "^0.1.9", "@jambonz/stats-collector": "^0.1.9",
"@jambonz/time-series": "^0.2.5", "@jambonz/time-series": "^0.2.5",
"@jambonz/digest-utils": "^0.0.3", "@jambonz/digest-utils": "^0.0.3",
"@jambonz/mw-registrar": "^0.2.4",
"@aws-sdk/client-sns": "^3.360.0", "@aws-sdk/client-sns": "^3.360.0",
"@aws-sdk/client-auto-scaling": "^3.360.0", "@aws-sdk/client-auto-scaling": "^3.360.0",
"bent": "^7.3.12", "bent": "^7.3.12",