From f54513f166874242a1e33617c0e1d7a82056d34f Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Mon, 6 Apr 2020 11:30:46 -0400 Subject: [PATCH] bugfix #14 - incorrect from when PAI differs from From header --- lib/http-routes/api/create-call.js | 2 +- lib/session/call-info.js | 15 +++++++++++---- lib/tasks/dial.js | 12 ------------ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/http-routes/api/create-call.js b/lib/http-routes/api/create-call.js index e0afcd41..140c8269 100644 --- a/lib/http-routes/api/create-call.js +++ b/lib/http-routes/api/create-call.js @@ -81,7 +81,7 @@ router.post('/', async(req, res) => { res.status(500).send('Call Failure'); ep.destroy(); } - /* ok our outbound NVITE is in flight */ + /* ok our outbound INVITE is in flight */ const tasks = [restDial]; const callInfo = new CallInfo({ diff --git a/lib/session/call-info.js b/lib/session/call-info.js index 713bbe4d..b9cacd35 100644 --- a/lib/session/call-info.js +++ b/lib/session/call-info.js @@ -1,4 +1,5 @@ const {CallDirection, CallStatus} = require('../utils/constants'); +const parseUri = require('drachtio-srf').parseUri; const uuidv4 = require('uuid/v4'); /** @@ -7,16 +8,22 @@ const uuidv4 = require('uuid/v4'); */ class CallInfo { constructor(opts) { + let from ; this.direction = opts.direction; + if (opts.req) { + const u = opts.req.getParsedHeader('from'); + const uri = parseUri(u.uri); + from = uri.user; + this.callerName = u.name || ''; + } if (this.direction === CallDirection.Inbound) { // inbound call const {app, req} = opts; this.callSid = req.locals.callSid, this.accountSid = app.account_sid, this.applicationSid = app.application_sid; - this.from = req.callingNumber; + this.from = from || req.callingNumber; this.to = req.calledNumber; - this.callerName = this.from.name || req.callingNumber; this.callId = req.get('Call-ID'); this.sipStatus = 100; this.callStatus = CallStatus.Trying; @@ -30,7 +37,7 @@ class CallInfo { this.parentCallSid = parentCallInfo.callSid; this.accountSid = parentCallInfo.accountSid; this.applicationSid = parentCallInfo.applicationSid; - this.from = req.callingNumber; + this.from = from || req.callingNumber; this.to = to; this.callerId = this.from.name || req.callingNumber; this.callId = req.get('Call-ID'); @@ -46,7 +53,7 @@ class CallInfo { this.callStatus = CallStatus.Trying, this.callId = req.get('Call-ID'); this.sipStatus = 100; - this.from = req.callingNumber; + this.from = from || req.callingNumber; this.to = to; if (tag) this._customerData = tag; } diff --git a/lib/tasks/dial.js b/lib/tasks/dial.js index 93b2595a..b05c7c73 100644 --- a/lib/tasks/dial.js +++ b/lib/tasks/dial.js @@ -242,18 +242,6 @@ class TaskDial extends Task { const {getSBC} = srf.locals; const sbcAddress = getSBC(); - /* - if (CallDirection.Inbound === cs.direction) { - const contact = req.getParsedHeader('Contact'); - const uri = parseUri(contact[0].uri); - this.logger.debug({contact}, 'outdialing with contact'); - sbcAddress = `${uri.host}:${uri.port || 5060}`; - //sbcAddress = `${req.source_address}:${req.source_port}`; - } - else { - sbcAddress = getSBC(); - } - */ if (!sbcAddress) throw new Error('no SBC found for outbound call'); const opts = { headers: req && req.has('X-CID') ? Object.assign(this.headers, {'X-CID': req.get('X-CID')}) : this.headers,