mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
Feat/support device call (#495)
* support dequeue from registered user * support dequeue from registered user * wip * wip * wip * wip * fix review comments
This commit is contained in:
@@ -29,8 +29,9 @@ module.exports = function(srf, logger) {
|
|||||||
} = srf.locals;
|
} = srf.locals;
|
||||||
const {lookupAccountDetails} = dbUtils(logger, srf);
|
const {lookupAccountDetails} = dbUtils(logger, srf);
|
||||||
|
|
||||||
function initLocals(req, res, next) {
|
async function initLocals(req, res, next) {
|
||||||
const callId = req.get('Call-ID');
|
const callId = req.get('Call-ID');
|
||||||
|
const uri = parseUri(req.uri);
|
||||||
logger.info({
|
logger.info({
|
||||||
callId,
|
callId,
|
||||||
callingNumber: req.callingNumber,
|
callingNumber: req.callingNumber,
|
||||||
@@ -43,12 +44,39 @@ module.exports = function(srf, logger) {
|
|||||||
const callSid = req.has('X-Retain-Call-Sid') ? req.get('X-Retain-Call-Sid') : uuidv4();
|
const callSid = req.has('X-Retain-Call-Sid') ? req.get('X-Retain-Call-Sid') : uuidv4();
|
||||||
const account_sid = req.get('X-Account-Sid');
|
const account_sid = req.get('X-Account-Sid');
|
||||||
req.locals = {callSid, account_sid, callId};
|
req.locals = {callSid, account_sid, callId};
|
||||||
if (req.has('X-Application-Sid')) {
|
|
||||||
|
if (req.has('X-Authenticated-User')) req.locals.originatingUser = req.get('X-Authenticated-User');
|
||||||
|
|
||||||
|
// check for call to application
|
||||||
|
if (uri.user.startsWith('app-') && req.locals.originatingUser) {
|
||||||
|
const application_sid = uri.user.match(/app-(.*)/)[1];
|
||||||
|
logger.debug(`got application from Request URI header: ${application_sid}`);
|
||||||
|
req.locals.application_sid = application_sid;
|
||||||
|
} else if (req.has('X-Application-Sid')) {
|
||||||
const application_sid = req.get('X-Application-Sid');
|
const application_sid = req.get('X-Application-Sid');
|
||||||
logger.debug(`got application from X-Application-Sid header: ${application_sid}`);
|
logger.debug(`got application from X-Application-Sid header: ${application_sid}`);
|
||||||
req.locals.application_sid = application_sid;
|
req.locals.application_sid = application_sid;
|
||||||
}
|
}
|
||||||
if (req.has('X-Authenticated-User')) req.locals.originatingUser = req.get('X-Authenticated-User');
|
// check for call to queue
|
||||||
|
if (uri.user.startsWith('queue-') && req.locals.originatingUser) {
|
||||||
|
const queue_name = uri.user.match(/queue-(.*)/)[1];
|
||||||
|
logger.debug(`got Queue from Request URI header: ${queue_name}`);
|
||||||
|
req.locals.queue_name = queue_name;
|
||||||
|
}
|
||||||
|
// check for call to registered user
|
||||||
|
if (req.locals.originatingUser) {
|
||||||
|
const arr = /^(.*)@(.*)/.exec(req.locals.originatingUser);
|
||||||
|
if (arr) {
|
||||||
|
const sipRealm = arr[2];
|
||||||
|
const called_user = `${req.calledNumber}@${sipRealm}`;
|
||||||
|
const reg = await registrar.query(called_user);
|
||||||
|
if (reg) {
|
||||||
|
logger.debug(`got called Number is a registered user: ${called_user}`);
|
||||||
|
req.locals.called_user = called_user;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (req.has('X-MS-Teams-Tenant-FQDN')) req.locals.msTeamsTenant = req.get('X-MS-Teams-Tenant-FQDN');
|
if (req.has('X-MS-Teams-Tenant-FQDN')) req.locals.msTeamsTenant = req.get('X-MS-Teams-Tenant-FQDN');
|
||||||
if (req.has('X-Cisco-Recording-Participant')) {
|
if (req.has('X-Cisco-Recording-Participant')) {
|
||||||
const ciscoParticipants = req.get('X-Cisco-Recording-Participant');
|
const ciscoParticipants = req.get('X-Cisco-Recording-Participant');
|
||||||
@@ -185,42 +213,56 @@ module.exports = function(srf, logger) {
|
|||||||
const {span} = rootSpan.startChildSpan('lookupApplication');
|
const {span} = rootSpan.startChildSpan('lookupApplication');
|
||||||
try {
|
try {
|
||||||
let app;
|
let app;
|
||||||
if (req.locals.application_sid) app = await lookupAppBySid(req.locals.application_sid);
|
if (req.locals.queue_name) {
|
||||||
else if (req.locals.originatingUser) {
|
logger.debug(`calling to queue ${req.locals.queue_name}, generating queue app`);
|
||||||
|
app = {
|
||||||
|
// Dummy hook to follow later feature server logic.
|
||||||
|
call_hook: {
|
||||||
|
url: 'https://jambonz.org',
|
||||||
|
method: 'GET'
|
||||||
|
},
|
||||||
|
account_sid,
|
||||||
|
app_json: JSON.stringify(
|
||||||
|
[{
|
||||||
|
verb: 'dequeue',
|
||||||
|
name: req.locals.queue_name,
|
||||||
|
timeout: 5
|
||||||
|
}]
|
||||||
|
)
|
||||||
|
};
|
||||||
|
} else if (req.locals.called_user) {
|
||||||
|
logger.debug(`calling to registered user ${req.locals.called_user}, generating dial app`);
|
||||||
|
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: req.locals.callingNumber,
|
||||||
|
answerOnBridge: true,
|
||||||
|
target: [
|
||||||
|
{
|
||||||
|
type: 'user',
|
||||||
|
name: req.locals.called_user
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}]
|
||||||
|
)
|
||||||
|
};
|
||||||
|
} else if (req.locals.application_sid) {
|
||||||
|
app = await lookupAppBySid(req.locals.application_sid);
|
||||||
|
} else if (req.locals.originatingUser) {
|
||||||
const arr = /^(.*)@(.*)/.exec(req.locals.originatingUser);
|
const arr = /^(.*)@(.*)/.exec(req.locals.originatingUser);
|
||||||
if (arr) {
|
if (arr) {
|
||||||
const sipRealm = arr[2];
|
const sipRealm = arr[2];
|
||||||
const calledAor = `${req.calledNumber}@${sipRealm}`;
|
logger.debug(`looking for device calling app for realm ${sipRealm}`);
|
||||||
const reg = await registrar.query(calledAor);
|
app = await lookupAppByRealm(sipRealm);
|
||||||
if (reg) {
|
if (app) {
|
||||||
logger.debug(`called client ${calledAor} is registered, forwarding call to called client.`);
|
logger.debug({app}, `retrieved device calling app for realm ${sipRealm}`);
|
||||||
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 {
|
|
||||||
logger.debug(`looking for device calling app for realm ${sipRealm}`);
|
|
||||||
app = await lookupAppByRealm(sipRealm);
|
|
||||||
if (app) {
|
|
||||||
logger.debug({app}, `retrieved device calling app for realm ${sipRealm}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user