diff --git a/lib/call-session.js b/lib/call-session.js index 4fffa30..9de8283 100644 --- a/lib/call-session.js +++ b/lib/call-session.js @@ -780,6 +780,27 @@ 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.uac.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'); + } + res.send(200); } } else if (dlg.type === 'uas' && ['application/dtmf-relay', 'application/dtmf'].includes(contentType)) { diff --git a/lib/utils.js b/lib/utils.js index 0a4bcd1..17886eb 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -22,8 +22,8 @@ function makeRtpEngineOpts(req, srcIsUsingSrtp, dstIsUsingSrtp, teams = false) { const dstOpts = dstIsUsingSrtp ? srtpOpts : rtpCopy; const srcOpts = srcIsUsingSrtp ? srtpOpts : rtpCopy; - /* webrtc clients (e.g. sipjs) send DMTF via SIP INFO */ - if ((srcIsUsingSrtp || dstIsUsingSrtp) && !teams) { + /* Allow Feature server to inject DTMF to both leg except call from Teams*/ + if (!teams) { dstOpts.flags.push('inject DTMF'); srcOpts.flags.push('inject DTMF'); }