C# Samples
C# MFormats Duplex WebRTC20.zip
C# MPlatform Duplex WebRTC20.zip
WebRTC 2.0 Architecture
The main logic for establishing connections is based on channels:
- IMCChannelSGN – used to control and communicate with the signaling server. It allows enumeration of current active channels and access to channel metadata.
- IMCChannel – represents the actual media communication channel, which we previously referred to as a room in WebRTC 1.0.
MConnectClass - used for creating the IMChannel and IMCChannelSGN, connecting to existing channels.
Overview of WebRTCHelper
The WebRTCHelper
class used in the samples encapsulates the logic required to manage bi-directional video communication using the Medialooks MConnectClass (IMConnect), IMCChannel, and IMCChannelSGN.
Samples channel establishment logic
To create an IMCChannelSGN
instance, call Enum_Create
on the MConnectClass. You can then enumerate existing channels. If the required channel doesn't exist, create one using Channel_Create()
. If it does, use Channel_Connect()
to join it.
As an example of the logic for connecting to a signaling server and joining or creating a channel, you can refer to the samples in WebRTCHelper.Connect method.
public void Connect(string URL)
{
server.Enum_Create(URL + "_enum", "username=test_user password=12345", " ", null, out server_manager);
channel_url = URL;
var members = GetRoomMembers();
if (members.Count <= 0)
{
current_channel = CreateChannel(channel_url);
current_channel.OnEventSafe += new IMEventsEvent_OnEventSafeEventHandler(Current_channel_OnEventSafe);
mode = PeerMode.server;
}
else
{
current_channel = ConnectToChannel(channel_url);
mode = PeerMode.client;
}
}
This logic determines the role (server/client) dynamically based on whether the channel already exists.
Sample Authentication and Security
The OnEventSafe
event handler is triggered when a remote_offer
is received. You can use it for different kinds of cases; in our samples, we are using it with a class toProtectionForm
validate incoming peer credentials. If authorization fails, the peer is rejected using IMAttributes.AttributesStringSet
to set. succeded=false
.
Sample Channel Status Monitoring
GetChannelInfoDetails()
retrieves runtime metrics using ChannelInfoGet
:
- eDataState: data stream state
- eChannelMode: mode of the channel (enum reference)
- eSGNState: signaling server state (enum reference)
Sample Sending and Receiving Media
-
SendToChannel(MFFrame)
– sends a video frame to the channel usingChannelSend
. -
ReceiverFrameChannel()
– receives frames usingChannelReceive
. Ifmix_on_server
is true, it collects and composites frames from all peers.
Sample Server-Side Frame Mixing
The mixFrames()
method arranges up to 4 frames into a 2x2 grid on a 1920×1080 canvas using:
-
MFFactoryClass.MFFrameCreateFromMem
– to allocate the background frame. -
IMFFrame.MFConvert
– to resize incoming frames. -
MFOverlay
– to place each frame on the canvas.
Sample Peer Enumeration and Metadata
GetRoomMembers()
uses VTSG_EnumGetCount
and VTSG_EnumGetByIndex
to get metadata of connected peers through the IMCChannelSGN
interface.
Connected Peers List
GetConnectedPeers()
retrieves the IDs of peers currently connected using indexed property access (connected[i]::remote::id
) from the channel.
Documentation References
- MConnectClass
- IMConnect
- MCChannelClass
- IMCChannel
- IMCChannelSGN
- eVTSG_State
- eChannelMode
- eMC_ChannelState
This helper class provides a full abstraction for WebRTC 2.0 peer setup and media transmission in duplex or one-way mode using the Medialooks SDK, supporting secure connections and multi-peer mixing.