mirror of
https://github.com/jambonz/sbc-inbound.git
synced 2026-10-04 02:04:22 +00:00
SIP INFO DTMF handling: if media has been released, just relay SIP INFO to FS otherwise transcode to RFC 2833
This commit is contained in:
+36
-18
@@ -50,6 +50,7 @@ class CallSession extends Emitter {
|
||||
|
||||
this.decrKey = req.srf.locals.realtimeDbHelpers.decrKey;
|
||||
this.callCountKey = makeCallCountKey(req.locals.account_sid);
|
||||
this._mediaReleased = false;
|
||||
}
|
||||
|
||||
get isFromMSTeams() {
|
||||
@@ -60,6 +61,10 @@ class CallSession extends Emitter {
|
||||
return this.srf.locals.privateSipAddress;
|
||||
}
|
||||
|
||||
get isMediaReleased() {
|
||||
return this._mediaReleased;
|
||||
}
|
||||
|
||||
async connect() {
|
||||
const {sdp} = this.req.locals;
|
||||
this.logger.info('inbound call accepted for routing');
|
||||
@@ -488,6 +493,7 @@ Duration=${payload.duration} `
|
||||
this.logger.info({response}, `got a reinvite from FS to ${reason}`);
|
||||
sdp = dlg.other.remote.sdp;
|
||||
answerMedia.flags = ['asymmetric', 'port latching'];
|
||||
this._mediaReleased = 'release-media' === reason;
|
||||
}
|
||||
else {
|
||||
sdp = await dlg.other.modify(response.sdp);
|
||||
@@ -620,26 +626,38 @@ Duration=${payload.duration} `
|
||||
}
|
||||
}
|
||||
else if (dlg.type === 'uas' && ['application/dtmf-relay', 'application/dtmf'].includes(contentType)) {
|
||||
/* convert SIP INFO dtmf to RFC 2833 */
|
||||
const arr = /Signal=\s([1-9#*])/.exec(req.body);
|
||||
if (!arr) throw new Error(`_onInfo: no dtmf in body for ${contentType}`);
|
||||
const digit = arr[1];
|
||||
const arr2 = /Duration=\s(\d+)/.exec(req.body);
|
||||
const arr = /Signal=\s*([1-9#*])/.exec(req.body);
|
||||
if (!arr) {
|
||||
this.logger.info({body: req.body}, '_onInfo: invalid INFO dtmf request');
|
||||
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;
|
||||
this.logger.info({body: req.body}, 'got SIP INFO DTMF from caller');
|
||||
const opts = {
|
||||
...this.rtpEngineOpts.common,
|
||||
'from-tag': this.rtpEngineOpts.uas.tag,
|
||||
digit,
|
||||
duration
|
||||
};
|
||||
const response = await this.playDTMF(opts);
|
||||
this.logger.debug({opts, response}, 'response from rtpengine to playDTMF');
|
||||
if ('ok' !== response.result) {
|
||||
this.logger.error({response}, `rtpengine playDTMF failed with ${JSON.stringify(response)}`);
|
||||
throw new Error('rtpengine failed: answer');
|
||||
|
||||
if (this.isMediaReleased) {
|
||||
/* just relay on to the feature server */
|
||||
this.logger.info({code, duration}, 'got SIP INFO DTMF from caller, relaying to feature server');
|
||||
this._onDTMF(dlg.other, {event: code, duration})
|
||||
.catch((err) => this.logger.info({err}, 'Error relaying DTMF to feature server'));
|
||||
res.send(200);
|
||||
}
|
||||
else {
|
||||
/* else convert SIP INFO to RFC 2833 telephony events */
|
||||
this.logger.info({code, duration}, 'got SIP INFO DTMF from caller, converting to RFC 2833');
|
||||
const opts = {
|
||||
...this.rtpEngineOpts.common,
|
||||
'from-tag': this.rtpEngineOpts.uas.tag,
|
||||
code,
|
||||
duration
|
||||
};
|
||||
const response = await this.playDTMF(opts);
|
||||
if ('ok' !== response.result) {
|
||||
this.logger.info({response}, `rtpengine playDTMF failed with ${JSON.stringify(response)}`);
|
||||
throw new Error('rtpengine failed: answer');
|
||||
}
|
||||
res.send(200);
|
||||
}
|
||||
res.send(200);
|
||||
}
|
||||
else {
|
||||
const immutableHdrs = ['via', 'from', 'to', 'call-id', 'cseq', 'max-forwards', 'content-length'];
|
||||
|
||||
Reference in New Issue
Block a user