Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for #163 #168

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions lib/call-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const {
nudgeCallCounts,
roundTripTime,
parseConnectionIp,
isPrivateVoipNetwork
isPrivateVoipNetwork,
isWSS,
} = require('./utils');

const {forwardInDialogRequests} = require('drachtio-fn-b2b-sugar');
Expand Down Expand Up @@ -68,6 +69,10 @@ 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);

this.protocol = isWSS(req) ? 'wss' : req.protocol;
}

get isFromMSTeams() {
Expand Down Expand Up @@ -187,7 +192,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();
Expand Down Expand Up @@ -224,8 +229,8 @@ class CallSession extends Emitter {

// set Contact header based on scenario, and transport protocol
let responseHeaders = {};
if (isPrivateVoipNetwork(this.req.source_address)) {
this.contactHeader = `<${scheme}:${this.privateSipAddress};transport=${this.req.protocol}>`;
if (this.isUsingPrivateNetwork) {
this.contactHeader = `<${scheme}:${this.privateSipAddress};transport=${this.protocol}>`;
responseHeaders = {
...responseHeaders,
'Contact': this.contactHeader
Expand All @@ -242,8 +247,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 Expand Up @@ -994,15 +999,19 @@ 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;

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