Skip to content

Commit

Permalink
sip scheme in contact header of re-invite 200 OK should be same as in…
Browse files Browse the repository at this point in the history
…itial 200 OK (#150)
  • Loading branch information
davehorton authored Jul 10, 2024
1 parent e999b4e commit 4153a14
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions lib/call-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ class CallSession extends Emitter {
const obj = parseUri(this.req.uri);
let proxy, host, uri;

const scheme = obj.scheme;

// replace host part of uri if its an ipv4 address, leave it otherwise
if (/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(obj.host)) {
debug(`replacing host: was ${obj.host} is ${featureServer}`);
Expand All @@ -176,8 +178,8 @@ class CallSession extends Emitter {
host = obj.host;
proxy = `sip:${featureServer}`;
}
if (obj.user) uri = `${obj.scheme}:${obj.user}@${host}`;
else uri = `${obj.scheme}:${host}`;
if (obj.user) uri = `${scheme}:${obj.user}@${host}`;
else uri = `${scheme}:${host}`;
this.logger.info(`uri will be: ${uri}, proxy ${proxy}`);

try {
Expand Down Expand Up @@ -223,25 +225,28 @@ 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}`;
responseHeaders = {
...responseHeaders,
'Contact':`<${obj.scheme}:${this.privateSipAddress}>;transport=${this.req.protocol}`
'Contact': this.contactHeader
};
} 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
this.contactHeader = `sip:${this.req.locals.msTeamsTenantFqdn}`;
responseHeaders = {
...responseHeaders,
Allow: 'INVITE, ACK, OPTIONS, CANCEL, BYE, NOTIFY, UPDATE, PRACK',
Contact: `sip:${this.req.locals.msTeamsTenantFqdn}`
Contact: this.contactHeader
};
}
else {
const hostport = this.srf.locals.sbcPublicIpAddress[this.req.protocol];
this.contactHeader = `<${scheme}:${hostport}>;transport=${this.req.protocol}`;
responseHeaders = {
...responseHeaders,
'Contact':`<${obj.scheme}:${hostport}>;transport=${this.req.protocol}`
'Contact': this.contactHeader
};
}
if (this.req.locals.application_sid) {
Expand Down Expand Up @@ -653,7 +658,12 @@ Duration=${payload.duration} `
}
else {
this.logger.info('got a reINVITE with no SDP; just respond with our current offer');
res.send(200, {body: dlg.local.sdp});
res.send(200, {
headers: {
'Contact': this.contactHeader
},
body: dlg.local.sdp
});
}
return;
}
Expand Down Expand Up @@ -706,7 +716,12 @@ Duration=${payload.duration} `
res.send(488);
throw new Error(`_onReinvite: rtpengine failed: ${JSON.stringify(response)}`);
}
res.send(200, {body: response.sdp});
res.send(200, {
headers: {
'Contact': this.contactHeader
},
body: response.sdp
});
} catch (err) {
res.send(err.status || 500);
this.logger.error(err, 'Error handling reinvite');
Expand Down

0 comments on commit 4153a14

Please sign in to comment.