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, "port": 3010,
"secret": "cymru" "secret": "cymru"
}, },
"freeswitch: [ "freeswitch: {
{ "address": "127.0.0.1",
"address": "127.0.0.1", "port": 8021,
"port": 8021, "secret": "ClueCon"
"secret": "ClueCon" },
}
],
"logging": { "logging": {
"level": "info" "level": "info"
}, },

View File

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

View File

@@ -18,7 +18,8 @@ class CallInfo {
this.originatingSipIP = req.get('X-Forwarded-For'); this.originatingSipIP = req.get('X-Forwarded-For');
this.originatingSipTrunkName = req.get('X-Originating-Carrier'); 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; const {req, parentCallInfo} = opts;
this.callSid = uuidv4(); this.callSid = uuidv4();
this.parentCallSid = parentCallInfo.callSid; this.parentCallSid = parentCallInfo.callSid;

View File

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

View File

@@ -130,12 +130,6 @@ class TaskDial extends Task {
callingNumber: this.callerId || req.callingNumber 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 ms = await cs.getMS();
const timerRing = setTimeout(() => { const timerRing = setTimeout(() => {
this.logger.info(`Dial:_attemptCall: ring no answer timer ${this.timeout}s exceeded`); this.logger.info(`Dial:_attemptCall: ring no answer timer ${this.timeout}s exceeded`);
@@ -154,7 +148,7 @@ class TaskDial extends Task {
sbcAddress, sbcAddress,
target: t, target: t,
opts, opts,
callInfo callInfo: cs.callInfo
}); });
this.dials.set(sd.callSid, sd); this.dials.set(sd.callSid, sd);

View File

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

View File

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