sendDtmf method
Implementation
sendDtmf(int handleId, Callbacks callbacks) {
Plugin pluginHandle = this.pluginHandles[handleId.toString()];
if (pluginHandle == null) {
Janus.warn("Invalid handle");
callbacks.error("Invalid handle");
return;
}
if (pluginHandle.dtmfSender == null) {
// Create the DTMF sender the proper way, if possible
if (pluginHandle.pc != null) {
MediaStreamTrack audioSender;
List<MediaStream> senders = pluginHandle.pc.getLocalStreams();
senders.forEach((sender) {
audioSender = sender
.getAudioTracks()
.firstWhere((track) => track.kind == 'audio');
});
if (audioSender != null) {
Janus.warn("Invalid DTMF configuration (no audio track)");
callbacks.error("Invalid DTMF configuration (no audio track)");
return;
}
pluginHandle.dtmfSender = pluginHandle.pc.createDtmfSender(audioSender);
if (pluginHandle.dtmfSender != null) {
Janus.log("Created DTMF Sender");
// Not implemented in flutter_webrtc
// pluginHandle.dtmfSender.ontonechange = (tone) =>
// Janus.debug("Sent DTMF tone: " + tone['tone'].toString());
}
}
if (pluginHandle.dtmfSender == null) {
Janus.warn("Invalid DTMF configuration");
callbacks.error("Invalid DTMF configuration");
return;
}
}
var dtmf = callbacks.dtmf;
if (dtmf == null) {
Janus.warn("Invalid DTMF parameters");
callbacks.error("Invalid DTMF parameters");
return;
}
String tones = dtmf['tones'];
if (tones == null) {
Janus.warn("Invalid DTMF string");
callbacks.error("Invalid DTMF string");
return;
}
int duration = (dtmf['duration'] is int)
? dtmf['duration']
: 500; // We choose 500ms as the default duration for a tone
int gap = (dtmf['gap'] is int)
? dtmf['gap']
: 50; // We choose 50ms as the default gap between tones
Janus.debug("Sending DTMF string " +
tones +
" (duration " +
duration.toString() +
"ms, gap " +
gap.toString() +
"ms)");
// FIX ME the upstream flutter_webrtc call name is not in compliance with WebRTC
// pluginHandle.dtmfSender.insertDTMF(tones, duration, gap);
pluginHandle.dtmfSender
.sendDtmf(tones, duration: duration, interToneGap: gap);
callbacks.success();
}