From b9d789c1bf4c45a992f702c7dfa530b0d1343359 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Thu, 19 Sep 2024 10:36:05 -0400 Subject: [PATCH 1/4] fix for #163 --- lib/call-session.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/call-session.js b/lib/call-session.js index aa745d8..ef74945 100644 --- a/lib/call-session.js +++ b/lib/call-session.js @@ -68,6 +68,8 @@ class CallSession extends Emitter { this.service_provider_sid = req.locals.service_provider_sid; this.srsClients = []; this.recordingNoAnswerTimeout = (process.env.JAMBONES_RECORDING_NO_ANSWER_TIMEOUT || 2) * 1000; + + this.isUsingPrivateNetwork = isPrivateVoipNetwork(this.req.source_address); } get isFromMSTeams() { @@ -187,7 +189,7 @@ class CallSession extends Emitter { ...this.rtpEngineOpts.common, ...this.rtpEngineOpts.uac.mediaOpts, 'from-tag': this.rtpEngineOpts.uas.tag, - direction: [isPrivateVoipNetwork(this.req.source_address) ? 'private' : 'public', 'private'], + direction: [this.isUsingPrivateNetwork ? 'private' : 'public', 'private'], sdp }; const startAt = process.hrtime(); @@ -224,7 +226,7 @@ class CallSession extends Emitter { // set Contact header based on scenario, and transport protocol let responseHeaders = {}; - if (isPrivateVoipNetwork(this.req.source_address)) { + if (this.isUsingPrivateNetwork) { this.contactHeader = `<${scheme}:${this.privateSipAddress};transport=${this.req.protocol}>`; responseHeaders = { ...responseHeaders, @@ -998,11 +1000,15 @@ Duration=${payload.duration} ` ...customHeaders } = req.headers; + if (this.isUsingPrivateNetwork && this.privateSipAddress) { + u.host = this.privateSipAddress; + } const response = await this.uas.request({ method: 'REFER', headers: { 'Refer-To': `<${stringifyUri(uri)}>`, 'Referred-By': `<${stringifyUri(u)}>`, + ...(this.contactHeader && {'Contact': this.contactHeader}), ...customHeaders } }); From cef0be86c9943e8b89c3f5636d59544ff77f30d0 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Wed, 25 Sep 2024 15:24:34 -0400 Subject: [PATCH 2/4] detect wss transport --- lib/call-session.js | 13 +++++++++---- lib/utils.js | 8 +++++++- 2 files changed, 16 insertions(+), 5 deletions(-) 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 }; From 66c5d120fa15ad6f24ebd2a635ef959a1fd66825 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Wed, 25 Sep 2024 15:26:55 -0400 Subject: [PATCH 3/4] wip --- lib/call-session.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/call-session.js b/lib/call-session.js index 34e75d0..eaa89ae 100644 --- a/lib/call-session.js +++ b/lib/call-session.js @@ -9,7 +9,6 @@ const { parseConnectionIp, isPrivateVoipNetwork, isWSS, - //localSipPort } = require('./utils'); const {forwardInDialogRequests} = require('drachtio-fn-b2b-sugar'); @@ -74,7 +73,6 @@ class CallSession extends Emitter { this.isUsingPrivateNetwork = isPrivateVoipNetwork(this.req.source_address); this.protocol = isWSS(req) ? 'wss' : req.protocol; - //this.localSipPort = localSipPort(req); } get isFromMSTeams() { From ae8a90653862deab6bdefde0dbd77d3e074a33e9 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Thu, 3 Oct 2024 10:35:59 -0400 Subject: [PATCH 4/4] on REFER from fs, remove incoming Contact header before sending onward --- lib/call-session.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/call-session.js b/lib/call-session.js index eaa89ae..247a267 100644 --- a/lib/call-session.js +++ b/lib/call-session.js @@ -999,7 +999,7 @@ Duration=${payload.duration} ` // eslint-disable-next-line no-unused-vars 'content-length':contentlength, 'refer-to':_referto, 'referred-by':_referredby, // eslint-disable-next-line no-unused-vars - 'X-Refer-To-Leave-Untouched': _leave, + 'X-Refer-To-Leave-Untouched': _leave, 'contact':_contact, ...customHeaders } = req.headers;