Skip to content

Commit

Permalink
detect wss transport
Browse files Browse the repository at this point in the history
  • Loading branch information
davehorton committed Sep 25, 2024
1 parent b9d789c commit cef0be8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 9 additions & 4 deletions lib/call-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const {
nudgeCallCounts,
roundTripTime,
parseConnectionIp,
isPrivateVoipNetwork
isPrivateVoipNetwork,
isWSS,
//localSipPort
} = require('./utils');

const {forwardInDialogRequests} = require('drachtio-fn-b2b-sugar');
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -262,6 +267,7 @@ module.exports = {
parseConnectionIp,
isMSTeamsCIDR,
isPrivateVoipNetwork,
parseHostPorts
parseHostPorts,
localSipPort
};

0 comments on commit cef0be8

Please sign in to comment.