detect wss transport

This commit is contained in:
Dave Horton
2024-09-25 15:24:34 -04:00
parent b9d789c1bf
commit cef0be86c9
2 changed files with 16 additions and 5 deletions

View File

@@ -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

View File

@@ -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
};