Compare commits

...
Author SHA1 Message Date
Quan HL 771aa9d06e INVITE from gw should have register_from_domain if it's available 2023-12-13 17:06:15 +07:00
Hoan Luu Huu eb0de5b0ee Feat support Outbound DTMF (#115)
* feat/support inband dtmf

* wip

* wip

* wip

* wip

* wip

* wip

* wip
2023-12-11 10:40:24 -05:00
Anton Voylenko d684fbb59b Set display name (#117)
* JAMBONES_MYSQL_PORT env added

* set display name from header

* remove double quotes
2023-12-10 09:07:21 -05:00
2 changed files with 43 additions and 7 deletions
+35 -3
View File
@@ -11,7 +11,7 @@ const makeInviteInProgressKey = (callid) => `sbc-out-iip${callid}`;
* this is to make sure the outgoing From has the number in the incoming From
* and not the incoming PAI
*/
const createBLegFromHeader = (req, teams) => {
const createBLegFromHeader = (req, teams, register_from_domain = null) => {
const from = req.getParsedHeader('From');
const uri = parseUri(from.uri);
let user = uri.user || 'anonymous';
@@ -22,6 +22,11 @@ const createBLegFromHeader = (req, teams) => {
else if (req.has('X-Preferred-From-User') || req.has('X-Preferred-From-Host')) {
user = req.get('X-Preferred-From-User') || user;
host = req.get('X-Preferred-From-Host') || host;
} else if (register_from_domain) {
host = register_from_domain;
}
if (from.name) {
return `${from.name} <sip:${user}@${host}>`;
}
return `sip:${user}@${host}`;
};
@@ -292,7 +297,8 @@ class CallSession extends Emitter {
name: vc.name,
diversion: vc.diversion,
hostport,
protocol: o.protocol
protocol: o.protocol,
register_from_domain: vc.register_from_domain
};
if (vc.register_username && vc.register_password) {
obj.auth = {
@@ -407,6 +413,12 @@ class CallSession extends Emitter {
'Diversion': div
};
}
if (gw.register_from_domain) {
hdrs = {
...hdrs,
'From': createBLegFromHeader(this.req, teams, gw.register_from_domain)
};
}
}
else this.logger.info(`sending INVITE to ${uri} via proxy ${proxy})`);
try {
@@ -447,7 +459,7 @@ class CallSession extends Emitter {
...this.rtpEngineOpts.uas.mediaOpts,
'from-tag': this.rtpEngineOpts.uas.tag,
'to-tag': this.rtpEngineOpts.uac.tag,
flags: ['single codec'],
flags: ['single codec', 'inject DTMF'],
sdp
};
const response = await this.answer(opts);
@@ -865,6 +877,26 @@ Duration=${payload.duration} `
)).every((r) => r);
}
res.send(succeeded ? 200 : 503);
} else if (reason.includes('Dtmf')) {
const arr = /Signal=\s*([0-9#*])/.exec(req.body);
if (!arr) {
this.logger.info({body: req.body}, '_onInfo: invalid INFO Dtmf');
throw new Error(`_onInfo: no dtmf in body for ${contentType}`);
}
const code = arr[1];
const arr2 = /Duration=\s*(\d+)/.exec(req.body);
const duration = arr2 ? arr2[1] : 250;
const dtmfOpts = {
...this.rtpEngineOpts.common,
'from-tag': this.rtpEngineOpts.uas.tag,
code,
duration
};
const response = await this.playDTMF(dtmfOpts);
if ('ok' !== response.result) {
this.logger.info({response}, `rtpengine play Dtmf failed with ${JSON.stringify(response)}`);
throw new Error('rtpengine failed: answer');
}
}
}
else if (dlg.type === 'uac' && ['application/dtmf-relay', 'application/dtmf'].includes(contentType)) {
+8 -4
View File
@@ -21,10 +21,14 @@ function makeRtpEngineOpts(req, srcIsUsingSrtp, dstIsUsingSrtp, padCrypto, teams
const dstOpts = dstIsUsingSrtp ? srtpOpts : rtpCopy;
const srcOpts = srcIsUsingSrtp ? srtpOpts : rtpCopy;
/* webrtc clients (e.g. sipjs) send DMTF via SIP INFO */
if ((srcIsUsingSrtp || dstIsUsingSrtp) && !teams) {
dstOpts.flags.push('inject DTMF');
srcOpts.flags.push('inject DTMF');
/** Allow feature server to send DTMF to the call excepts call from/to teams */
if (!teams) {
if (!dstOpts.flags.includes('inject DTMF')) {
dstOpts.flags.push('inject DTMF');
}
if (!srcOpts.flags.includes('inject DTMF')) {
srcOpts.flags.push('inject DTMF');
}
}
const common = {
'call-id': req.get('Call-ID'),