Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support device call to app #120

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ const {
lookupAccountBySid,
lookupAccountCapacitiesBySid,
queryCallLimits,
lookupClientByAccountAndUsername
lookupClientByAccountAndUsername,
lookupAppBySid
} = require('@jambonz/db-helpers')({
host: process.env.JAMBONES_MYSQL_HOST,
port: process.env.JAMBONES_MYSQL_PORT || 3306,
Expand Down Expand Up @@ -130,7 +131,8 @@ srf.locals = {...srf.locals,
lookupAccountBySipRealm,
lookupAccountCapacitiesBySid,
queryCallLimits,
lookupClientByAccountAndUsername
lookupClientByAccountAndUsername,
lookupAppBySid
},
realtimeDbHelpers: {
createSet,
Expand Down
14 changes: 12 additions & 2 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module.exports = function(srf, logger) {
lookupAccountBySipRealm,
lookupAccountBySid,
lookupAccountCapacitiesBySid,
queryCallLimits
queryCallLimits,
lookupAppBySid
} = srf.locals.dbHelpers;
const {stats, writeCdrs} = srf.locals;

Expand Down Expand Up @@ -196,11 +197,20 @@ module.exports = function(srf, logger) {
res.send(404);
return req.srf.endSession(req);
}
let deviceAppSid = null;
if (req.has('X-Application-Sid')) {
// Call from registered device to test application.
const appSid = req.get('X-Application-Sid');
const app = await lookupAppBySid(appSid);
if (app && app.account_sid === account.account_sid) {
deviceAppSid = app.application_sid;
}
}
req.locals = {
service_provider_sid: account.service_provider_sid,
account_sid: account.account_sid,
account,
application_sid: account.device_calling_application_sid,
application_sid: deviceAppSid || account.device_calling_application_sid,
webhook_secret: account.webhook_secret,
realm: uri.host,
...(account.registration_hook && {
Expand Down