This commit is contained in:
Dave Horton
2020-01-29 16:46:38 -05:00
parent 8487bb0571
commit 44a1b45357
7 changed files with 20 additions and 24 deletions

View File

@@ -3,13 +3,11 @@
"port": 3010,
"secret": "cymru"
},
"freeswitch: [
{
"freeswitch: {
"address": "127.0.0.1",
"port": 8021,
"secret": "ClueCon"
}
],
},
"logging": {
"level": "info"
},

View File

@@ -83,12 +83,12 @@ module.exports = function(srf, logger) {
baseUrl: `${u.protocol}://${u.resource}${myPort}`,
auth
};
logger.debug({originalRequest: app.originalRequest}, 'invokeWebCallback');
const obj = req.locals.callInfo;
logger.debug({url: call_hook.url, method}, 'invokeWebCallback');
const obj = Object.assign({}, req.locals.callInfo);
// if the call hook is a POST add the entire SIP message to the payload
if (method === 'POST') Object.assign(obj, {sip: req.msg});
app.tasks = await retrieveApp(logger, app.call_hook, method, auth, obj);
if (method === 'POST') obj.sip = req.msg;
app.tasks = await retrieveApp(logger, call_hook.url, method, auth, obj);
next();
} catch (err) {
logger.error(err, 'Error retrieving or parsing application');

View File

@@ -18,7 +18,8 @@ class CallInfo {
this.originatingSipIP = req.get('X-Forwarded-For');
this.originatingSipTrunkName = req.get('X-Originating-Carrier');
}
else if (opts.parentCallInfo instanceof CallInfo) {
else if (opts.parentCallInfo) {
console.log(`is opts.parentCallInfo a CallInfo ${opts.parentCallInfo instanceof CallInfo}`);
const {req, parentCallInfo} = opts;
this.callSid = uuidv4();
this.parentCallSid = parentCallInfo.callSid;

View File

@@ -198,7 +198,7 @@ class CallSession extends Emitter {
}
_notifyCallStatusChange({callStatus, sipStatus}) {
this.logger.debug(`CallSession:_notifyCallStatusChange: ${callStatus} ${sipStatus}`);
this.callInfo.updateStatus(callStatus, sipStatus);
this.callInfo.updateCallStatus(callStatus, sipStatus);
try {
this.notifyHook(this.application.call_status_hook);
} catch (err) {

View File

@@ -130,12 +130,6 @@ class TaskDial extends Task {
callingNumber: this.callerId || req.callingNumber
};
// construct bare-bones callInfo for the new outbound call attempt
const callInfo = Object.assign({}, cs.callInfo);
callInfo.parentCallSid = cs.callSid;
callInfo.direction = CallDirection.Outbound;
['callSid', 'callID', 'from', 'to', 'callerId', 'sipStatus', 'callStatus'].forEach((k) => delete callInfo[k]);
const ms = await cs.getMS();
const timerRing = setTimeout(() => {
this.logger.info(`Dial:_attemptCall: ring no answer timer ${this.timeout}s exceeded`);
@@ -154,7 +148,7 @@ class TaskDial extends Task {
sbcAddress,
target: t,
opts,
callInfo
callInfo: cs.callInfo
});
this.dials.set(sd.callSid, sd);

View File

@@ -3,13 +3,15 @@ require('request-debug')(request);
const retrieveApp = require('./retrieve-app');
function hooks(logger, callInfo) {
function actionHook(hook, obj, expectResponse = true) {
logger.debug({callInfo}, 'creating action hook');
function actionHook(hook, obj = {}, expectResponse = true) {
const method = hook.method.toUpperCase();
const auth = (hook.username && hook.password) ?
{username: hook.username, password: hook.password} :
null;
const data = Object.assign({}, obj, callInfo);
logger.debug({data}, `actionhook sending to ${hook.url}`);
if ('GET' === method) {
// remove customer data - only for POSTs since it might be quite complex
delete data.customerData;
@@ -20,8 +22,8 @@ function hooks(logger, callInfo) {
json: 'POST' === method || expectResponse
};
if (auth) obj.auth = auth;
if ('POST' === method) obj.body = data;
else obj.qs = data;
if ('POST' === method) opts.body = data;
else opts.qs = data;
return new Promise((resolve, reject) => {
request(opts, (err, response, body) => {

View File

@@ -95,6 +95,7 @@ class SingleDialer extends Emitter {
* (a) create a logger for this call
* (b) augment this.callInfo with additional call info
*/
this.logger.debug(`call sent, creating CallInfo parentCallInfo is CallInfo? ${this.parentCallInfo instanceof CallInfo}`);
this.callInfo = new CallInfo({
direction: CallDirection.Outbound,
parentCallInfo: this.parentCallInfo,
@@ -221,7 +222,7 @@ class SingleDialer extends Emitter {
_notifyCallStatusChange({callStatus, sipStatus}) {
this.logger.debug(`SingleDialer:_notifyCallStatusChange: ${callStatus} ${sipStatus}`);
this.callInfo.updateStatus(callStatus, sipStatus);
this.callInfo.updateCallStatus(callStatus, sipStatus);
try {
this.notifyHook(this.application.call_status_hook);
} catch (err) {