Feat/devices call other (#491)

* calls between clients on same domain

* wip

* wip

* wip

* wip
This commit is contained in:
Hoan Luu Huu
2023-10-20 18:45:13 +07:00
committed by GitHub
parent 7992bc6ca0
commit 24fccbdae5
4 changed files with 55 additions and 4 deletions

View File

@@ -20,7 +20,8 @@ module.exports = function(srf, logger) {
lookupAppByRegex, lookupAppByRegex,
lookupAppBySid, lookupAppBySid,
lookupAppByRealm, lookupAppByRealm,
lookupAppByTeamsTenant lookupAppByTeamsTenant,
registrar
} = srf.locals.dbHelpers; } = srf.locals.dbHelpers;
const { const {
writeAlerts, writeAlerts,
@@ -191,8 +192,37 @@ module.exports = function(srf, logger) {
const sipRealm = arr[2]; const sipRealm = arr[2];
logger.debug(`looking for device calling app for realm ${sipRealm}`); logger.debug(`looking for device calling app for realm ${sipRealm}`);
app = await lookupAppByRealm(sipRealm); app = await lookupAppByRealm(sipRealm);
if (app) logger.debug({app}, `retrieved device calling app for realm ${sipRealm}`); if (app) {
logger.debug({app}, `retrieved device calling app for realm ${sipRealm}`);
} else {
const calledAor = `${req.calledNumber}@${sipRealm}`;
const reg = await registrar.query(calledAor);
if (reg) {
logger.debug(`There is no device app found, called client is registered,
forwarding call to called client.`);
app = {
// Dummy hook to follow later feature server logic.
call_hook: {
url: 'https://jambonz.org',
method: 'GET'
},
account_sid,
app_json: JSON.stringify(
[{
verb: 'dial',
callerId: arr[1],
answerOnBridge: true,
target: [
{
type: 'user',
name: calledAor
}
]
}]
)
};
}
}
} }
} }
else if (req.locals.msTeamsTenant) { else if (req.locals.msTeamsTenant) {
@@ -257,7 +287,7 @@ module.exports = function(srf, logger) {
app2.requestor = new HttpRequestor(logger, account_sid, app.call_hook, accountInfo.account.webhook_secret); app2.requestor = new HttpRequestor(logger, account_sid, app.call_hook, accountInfo.account.webhook_secret);
if (app.call_status_hook) app2.notifier = new HttpRequestor(logger, account_sid, app.call_status_hook, if (app.call_status_hook) app2.notifier = new HttpRequestor(logger, account_sid, app.call_status_hook,
accountInfo.account.webhook_secret); accountInfo.account.webhook_secret);
else app2.notifier = {request: () => {}}; else app2.notifier = {request: () => {}, close: () => {}};
} }
req.locals.application = app2; req.locals.application = app2;

View File

@@ -17,6 +17,7 @@ const {
PORT, PORT,
NODE_ENV, NODE_ENV,
} = require('../config'); } = require('../config');
const Registrar = require('@jambonz/mw-registrar');
const assert = require('assert'); const assert = require('assert');
function initMS(logger, wrapper, ms) { function initMS(logger, wrapper, ms) {
@@ -177,6 +178,7 @@ function installSrfLocals(srf, logger) {
host: JAMBONES_REDIS_HOST, host: JAMBONES_REDIS_HOST,
port: JAMBONES_REDIS_PORT || 6379 port: JAMBONES_REDIS_PORT || 6379
}, logger, tracer); }, logger, tracer);
const registrar = new Registrar(logger, client);
const { const {
synthAudio, synthAudio,
getNuanceAccessToken, getNuanceAccessToken,
@@ -204,6 +206,7 @@ function installSrfLocals(srf, logger) {
srf.locals = {...srf.locals, srf.locals = {...srf.locals,
dbHelpers: { dbHelpers: {
client, client,
registrar,
pool, pool,
lookupAppByPhoneNumber, lookupAppByPhoneNumber,
lookupAppByRegex, lookupAppByRegex,

17
package-lock.json generated
View File

@@ -13,6 +13,7 @@
"@aws-sdk/client-sns": "^3.360.0", "@aws-sdk/client-sns": "^3.360.0",
"@jambonz/db-helpers": "^0.9.1", "@jambonz/db-helpers": "^0.9.1",
"@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/speech-utils": "^0.0.22", "@jambonz/speech-utils": "^0.0.22",
"@jambonz/stats-collector": "^0.1.9", "@jambonz/stats-collector": "^0.1.9",
@@ -3126,6 +3127,14 @@
"node": ">=14.x" "node": ">=14.x"
} }
}, },
"node_modules/@jambonz/mw-registrar": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/@jambonz/mw-registrar/-/mw-registrar-0.2.4.tgz",
"integrity": "sha512-GHRlvHsDvwfQfqOUKh4Emt+CvoiODQ+Tny5zg8ZT5q5yz77qy3XIfOF072xO9gDSPrXjn0rH13W3iIKtNzcOIA==",
"dependencies": {
"debug": "^4.3.1"
}
},
"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",
@@ -13212,6 +13221,14 @@
"express": "^4.17.2" "express": "^4.17.2"
} }
}, },
"@jambonz/mw-registrar": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/@jambonz/mw-registrar/-/mw-registrar-0.2.4.tgz",
"integrity": "sha512-GHRlvHsDvwfQfqOUKh4Emt+CvoiODQ+Tny5zg8ZT5q5yz77qy3XIfOF072xO9gDSPrXjn0rH13W3iIKtNzcOIA==",
"requires": {
"debug": "^4.3.1"
}
},
"@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

@@ -29,6 +29,7 @@
"@aws-sdk/client-sns": "^3.360.0", "@aws-sdk/client-sns": "^3.360.0",
"@jambonz/db-helpers": "^0.9.1", "@jambonz/db-helpers": "^0.9.1",
"@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/speech-utils": "^0.0.22", "@jambonz/speech-utils": "^0.0.22",
"@jambonz/stats-collector": "^0.1.9", "@jambonz/stats-collector": "^0.1.9",