DTMF Signalling
LiveSwitch supports dual-tone multi-frequency signaling (DTMF) for peer connections. Per Mozilla:
The primary purpose for WebRTC's DTMF support is to allow WebRTC-based communication clients to be connected to a public-switched telephone network (PSTN) or other legacy telephone service, including extant voice over IP (VoIP) services. For that reason, DTMF can't be used between two WebRTC-based devices, because there is no mechanism provided by WebRTC for receiving DTMF codes.
Note
About the code examples on this page:
- For .NET MAUI and Unity, use the C# code.
- For macOS, use the iOS code.
Send DTMF Tones
Sending a DTMF tone is simple.
Note
SFU upstreams are send only by definition, so they can send DTMF tones, but not receive them.
audioStream.InsertDtmfTones(FM.LiveSwitch.Dtmf.Tone.FromToneString("..."));
Note
A DTMF tone string is made of up characters from the set "123456789*0#ABCD,". The special character "," indicates a pause.
You can also hook into an event that is raised when the sending tone changes.
audioStream.OnSendDtmfToneChange += (tone) =>
{
Log.Info("Sender's DTMF tone is changing: " + tone.ToString());
};
The empty string "" indicates that the tone has stopped. For browsers, that's all there is to it.
Additional DTMF Tone Features for Native Platforms
We've taken it a few steps further on all other platforms (native desktop/mobile), where additional sending and receiving events are available.
When the receiving tone changes, an event is raised:
audioStream.OnReceiveDtmfToneChange += (tone) =>
{
Log.Info("Receiver's DTMF tone is changing: " + tone.ToString());
};
The empty string "" indicates that the tone has stopped.
If you want to go lower-level, it's possible to handle the actual packet-level send/receive events which are tied to the clock-rate of the selected audio stream codec (Opus, PCMU, PCMA, etc.).
Note
SFU upstreams are send only by definition, so they can send DTMF tones, but not receive them. Similarly, SFU downstreams are receive only by definition. so they can receive DTMF tones but cannot send them.