Skip to content
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
6 changes: 6 additions & 0 deletions lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ module.exports = {
UPDATE : 'UPDATE',
SUBSCRIBE : 'SUBSCRIBE',

// DTMF transport methods.
DTMF_TRANSPORT : {
INFO : 'INFO',
RFC2833 : 'RFC2833'
},

/* SIP Response Reasons
* DOC: https://www.iana.org/assignments/sip-parameters
* Copied from https://github.com/versatica/OverSIP/blob/master/lib/oversip/sip/constants.rb#L7
Expand Down
60 changes: 54 additions & 6 deletions lib/RTCSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ module.exports = class RTCSession extends EventEmitter
let position = 0;
let duration = options.duration || null;
let interToneGap = options.interToneGap || null;
const transportType = options.transportType || JsSIP_C.DTMF_TRANSPORT.INFO;
Comment thread
acharlop marked this conversation as resolved.
Resolved

if (tones === undefined)
{
Expand Down Expand Up @@ -1046,13 +1047,40 @@ module.exports = class RTCSession extends EventEmitter
}
else
{
const dtmf = new RTCSession_DTMF(this);
if (
transportType !== JsSIP_C.DTMF_TRANSPORT.INFO ||
transportType !== JsSIP_C.DTMF_TRANSPORT.RFC2833
)
{
throw new TypeError(`invalid transportType: ${transportType}`);
}

// Send DTMF according to transport config.
switch (transportType)
{
case JsSIP_C.DTMF_TRANSPORT.RFC2833: {
// Send DTMF in current audio RTP stream.
const sender = this._getDTMFRTPSender();

if (sender)
{
sender.insertDTMF(tone, duration, interToneGap);
}

options.eventHandlers = {
onFailed : () => { this._tones = null; }
};
dtmf.send(tone, options);
timeout = duration + interToneGap;
break;
}

case JsSIP_C.DTMF_TRANSPORT.INFO: {
// Send DTMF via SIP INFO messages.
const dtmf = new RTCSession_DTMF(this);

options.eventHandlers = {
Comment thread
acharlop marked this conversation as resolved.
Resolved
onFailed : () => { this._tones = null; }
};
dtmf.send(tone, options);
timeout = duration + interToneGap;
}
}
}

// Set timeout for the next tone.
Expand Down Expand Up @@ -2632,6 +2660,26 @@ module.exports = class RTCSession extends EventEmitter
});
}

/**
* Get DTMF RTCRtpSender.
*/
_getDTMFRTPSender()
{
const sender = this._connection.getSenders().find((rtpSender) =>
{
return rtpSender.track && rtpSender.track.kind === 'audio';
});

if (!(sender && sender.dtmf))
{
debugerror('sendDTMF() | no local audio track to send DTMF with');

return;
}

return sender.dtmf;
}

/**
* Reception of Response for Initial INVITE
*/
Expand Down