diff --git a/lib/call-session.js b/lib/call-session.js index ef74945..34e75d0 100644 --- a/lib/call-session.js +++ b/lib/call-session.js @@ -7,7 +7,9 @@ const { nudgeCallCounts, roundTripTime, parseConnectionIp, - isPrivateVoipNetwork + isPrivateVoipNetwork, + isWSS, + //localSipPort } = require('./utils'); const {forwardInDialogRequests} = require('drachtio-fn-b2b-sugar'); @@ -70,6 +72,9 @@ class CallSession extends Emitter { this.recordingNoAnswerTimeout = (process.env.JAMBONES_RECORDING_NO_ANSWER_TIMEOUT || 2) * 1000; this.isUsingPrivateNetwork = isPrivateVoipNetwork(this.req.source_address); + + this.protocol = isWSS(req) ? 'wss' : req.protocol; + //this.localSipPort = localSipPort(req); } get isFromMSTeams() { @@ -227,7 +232,7 @@ class CallSession extends Emitter { // set Contact header based on scenario, and transport protocol let responseHeaders = {}; if (this.isUsingPrivateNetwork) { - this.contactHeader = `<${scheme}:${this.privateSipAddress};transport=${this.req.protocol}>`; + this.contactHeader = `<${scheme}:${this.privateSipAddress};transport=${this.protocol}>`; responseHeaders = { ...responseHeaders, 'Contact': this.contactHeader @@ -244,8 +249,8 @@ class CallSession extends Emitter { }; } else { - const hostport = this.srf.locals.sbcPublicIpAddress[this.req.protocol]; - this.contactHeader = `<${scheme}:${hostport};transport=${this.req.protocol}>`; + const hostport = this.srf.locals.sbcPublicIpAddress[this.protocol]; + this.contactHeader = `<${scheme}:${hostport};transport=${this.protocol}>`; responseHeaders = { ...responseHeaders, 'Contact': this.contactHeader diff --git a/lib/utils.js b/lib/utils.js index 42e8978..280654b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -9,6 +9,11 @@ const isWSS = (req) => { return req.getParsedHeader('Via')[0].protocol.toLowerCase().startsWith('ws'); }; +const localSipPort = (req) => { + const arr = /:(\d+)$/.exec(req.receivedOn); + return arr ? arr[1] : '5060'; +}; + const getAppserver = (srf) => { const len = srf.locals.featureServers.length; return srf.locals.featureServers[idx++ % len]; @@ -262,6 +267,7 @@ module.exports = { parseConnectionIp, isMSTeamsCIDR, isPrivateVoipNetwork, - parseHostPorts + parseHostPorts, + localSipPort };