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

Contact in 200 should set sip(s) appropriately and have port and prot… #148

Merged
merged 4 commits into from
Jul 3, 2024
Merged
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
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run jslint
#npm run jslint
38 changes: 38 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ if (process.env.DRACHTIO_HOST && !process.env.K8S) {
srf.locals.addToRedis();
}
}
srf.locals.sbcPublicIpAddress = parseHostPorts(hostports);
});
}
else {
Expand All @@ -206,6 +207,7 @@ else {
}
}
}
srf.locals.sbcPublicIpAddress = parseHostPorts(hp.split(','));
});
}
if (process.env.NODE_ENV === 'test') {
Expand Down Expand Up @@ -362,4 +364,40 @@ function handle(removeFromSet, setName, signal) {
}
}

const parseHostPorts = (hostports) => {
let obj = {};
for (const hp of hostports) {
const arr = /^(.*)\/(.*):(\d+)$/.exec(hp);
if (arr) {
const ipv4 = arr[2];
const port = arr[3];
switch (arr[1]) {
case 'udp':
obj = {
...obj,
udp: `${ipv4}:${port}`
};
break;
case 'tls':
obj = {
...obj,
tls: `${ipv4}:${port}`
};
break;
case 'wss':
obj = {
...obj,
wss: `${ipv4}:${port}`
};
break;
}
}
if (!obj.tls) {
obj.tls = `${srf.locals.sipAddress}:5061`;
}
}
logger.info({obj}, 'sip endpoints');
return obj;
};

module.exports = {srf, logger};
26 changes: 19 additions & 7 deletions lib/call-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,24 +213,36 @@ class CallSession extends Emitter {
createSiprecBody(headers, response.sdp, this.xml.type, this.xml.content) :
response.sdp;

const responseHeaders = {};
if (isPrivateVoipNetwork(this.req.source_address)) {
Object.assign(responseHeaders, {'Contact':`<sip:${this.privateSipAddress}>`});
}
if (this.req.locals.carrier) {
Object.assign(headers, {
'X-Originating-Carrier': this.req.locals.carrier,
'X-Voip-Carrier-Sid': this.req.locals.voip_carrier_sid
});
}
if (this.req.locals.msTeamsTenantFqdn) {

// set Contact header based on scenario, and transport protocol
let responseHeaders = {};
if (isPrivateVoipNetwork(this.req.source_address)) {
responseHeaders = {
...responseHeaders,
'Contact':`<${obj.scheme}:${this.privateSipAddress}>;transport=${this.req.protocol}`
};
} else if (this.req.locals.msTeamsTenantFqdn) {
Object.assign(headers, {'X-MS-Teams-Tenant-FQDN': this.req.locals.msTeamsTenantFqdn});

// for Microsoft Teams the Contact header must include the tenant FQDN
Object.assign(responseHeaders, {
responseHeaders = {
...responseHeaders,
Allow: 'INVITE, ACK, OPTIONS, CANCEL, BYE, NOTIFY, UPDATE, PRACK',
Contact: `sip:${this.req.locals.msTeamsTenantFqdn}`
});
};
}
else {
const hostport = this.srf.locals.sbcPublicIpAddress[this.req.protocol];
responseHeaders = {
...responseHeaders,
'Contact':`<${obj.scheme}:${hostport}>;transport=${this.req.protocol}`
};
}
if (this.req.locals.application_sid) {
Object.assign(headers, {'X-Application-Sid': this.req.locals.application_sid});
Expand Down
Loading