WebRTC sends audio and video between browsers and applications in real time. Two peers connect to each other directly whenever the network allows it, so the delay is small and the media does not pass through a server.
Background reading: WebRTC on Wikipedia, Getting started with WebRTC, WebRTC connectivity (MDN) and our blog post WebRTC in a native desktop Windows application.
The Video SDK has two WebRTC implementations:
-
WebRTC 1.0, described in this section: the
MWebRTCandMWebRTC_Pluginobjects with their default settings. - WebRTC 2.0 (MConnect), described in the WebRTC 2.0 section.
Each implementation has its own signaling server. WebRTC 2.0 components cannot use the WebRTC 1.0 server. The property webrtc20.enabled switches an MWebRTC object to the 2.0 implementation; it is false by default.
What takes part in a connection
- Peers: an application that uses the SDK, or a web page in a browser.
- Signaling server: introduces the peers to each other and passes their connection offers. You run your own WebRTC 1.0 signaling server, which also serves the web pages.
- STUN server: tells a peer its public network address.
- TURN server: relays the media when the peers cannot connect directly. You add it yourself.
Publish a stream
The address passed to Login has the form https://server[:port]/room/name: peers in the same room can see and call each other.
MPlatform: add the plugin to a source object (MFile, MLive, MPlaylist or MMixer).
var webRTC = new MWebRTC_PluginClass();
webRTC.PropsSet("mode", "sender");
m_objFile.PluginsAdd(webRTC, 0);
string myId;
webRTC.Login("https://signal.example.com:8889/room/Studio", "", out myId);
// ... when streaming is finished
webRTC.Logout();
m_objFile.PluginsRemove(webRTC);
Marshal.ReleaseComObject(webRTC);
MFormats: create an MWebRTC object and send frames to it from your processing loop.
var webRTC = new MWebRTCClass();
webRTC.PropsSet("mode", "sender");
string myId;
webRTC.Login("https://signal.example.com:8889/room/Studio", "", out myId);
var avProps = new M_AV_PROPS();
while (m_bWork)
{
MFFrame frame = null;
try
{
m_objLive.SourceFrameConvertedGet(ref avProps, -1, out frame, "");
webRTC.ReceiverFramePut(frame, -1, "");
}
finally
{
if (frame != null)
Marshal.ReleaseComObject(frame);
}
}
webRTC.Logout();
Marshal.ReleaseComObject(webRTC);
Receive a stream
A receiver logs in to the room and calls the publisher by its name. A web browser can watch the same stream at https://signal.example.com:8889/room/Studio.
MPlatform:
var webRTC = new MWebRTCClass();
webRTC.PropsSet("mode", "receiver");
string myId;
webRTC.Login("https://signal.example.com:8889/room", "Viewer1", out myId);
webRTC.ConnectToPeer("Studio");
int cookie = 0;
while (m_bWork)
{
MFrame frame = null;
try
{
webRTC.SourceFrameGetEx(ref cookie, -1, out frame, 0);
if (frame != null)
m_objPreview.ReceiverPutFrame("", frame);
}
finally
{
if (frame != null)
Marshal.ReleaseComObject(frame);
}
}
webRTC.Logout();
Marshal.ReleaseComObject(webRTC);
MFormats:
var webRTC = new MWebRTCClass();
webRTC.PropsSet("mode", "receiver");
string myId;
webRTC.Login("https://signal.example.com:8889/room", "Viewer1", out myId);
webRTC.ConnectToPeer("Studio");
var avProps = new M_AV_PROPS();
while (m_bWork)
{
MFFrame frame = null;
try
{
webRTC.SourceFrameConvertedGetByTime(ref avProps, -1, -1, out frame, "");
m_objPreview.ReceiverFramePut(frame, -1, "");
}
finally
{
if (frame != null)
Marshal.ReleaseComObject(frame);
}
}
webRTC.Logout();
Marshal.ReleaseComObject(webRTC);
Samples
The SDK installation contains complete WebRTC 1.0 samples in the Samples WebRTC folder, in the folder of each programming language. The WebRTC 2.0 subfolders belong to the other implementation.
| Language | MFormats SDK | MPlatform SDK |
|---|---|---|
| C#, VB.NET | Sample Streamer, Sample Receiver, Sample Duplex | Streamer Sample, Receiver Sample, Duplex Sample |
| Delphi | Sample Streamer, Sample Receiver, Sample Remote Control | Streamer Sample, Receiver Sample, Remote Control Sample |
Next steps
- Environment: signaling, STUN and TURN servers
- Signaling server deployment and usage
- TURN server deployment and usage
- WebRTC properties
- WebRTC event list
- How to communicate with the signaling server
- Sharing custom information between Publisher and Receiver
- WebRTC GPU encoding
- Transmitting timecode to a web page frame accurately
- SFU: one stream for many receivers
- WebRTC Q&A
Still have questions?
Tell us what didn’t work or what you’d like clarified.