Table of Contents

Simple WebRTC Server

The SimpleWebRtcServer sample demonstrates how to use WebRtcStandaloneSignalingServer — a stand-alone WebRTC signaling server for room-based peer-to-peer communication. Unlike the WebRTC integration in the Multi-Protocol Server where the server acts as a media endpoint, this signaling server facilitates direct media exchange between connected peers without processing the media itself.

Overview

The SimpleWebRtcServer class performs the following:

  1. Configures ICE server settings (STUN or TURN)
  2. Optionally creates and starts a TurnServer for NAT traversal
  3. Creates and starts a WebRtcStandaloneSignalingServer with an authorization handler

How It Works

The signaling server manages rooms where two or more peers can connect. When peers join the same room, the server relays signaling messages (SDP offers/answers and ICE candidates) between them. The actual media data flows directly between peers via WebRTC — the server only handles the signaling exchange.

ICE Configuration

WebRTC requires ICE (Interactive Connectivity Establishment) servers to discover network paths between peers. The sample supports two configurations:

STUN Only (No TURN Server)

var parameters = new VAST.WebRTC.WebRtcServerParameters
{
    IceServers = "stun:stun.l.google.com:19302",
};

STUN works when peers can establish a direct connection. It will fail if both peers are behind symmetric NATs.

With TURN Server

string publicIPv4 = "YOUR_PUBLIC_IPV4_ADDRESS";

var parameters = new VAST.WebRTC.WebRtcServerParameters
{
    IceServers = $"turn:user:password@{publicIPv4}:3478",
};

TURN relays media through the server when direct connections are not possible. This requires the server's public IP address to be configured.

TURN Server

When a public IP address is provided, the sample creates a TurnServer:

var credentials = new Dictionary<string, string>();
credentials.Add("user", "password");

var turnPars = new VAST.ICE.TurnServerParameters
{
    UserCredentials = credentials,
    PublicIPv4Address = IPAddress.Parse(publicIPv4),
};

this.turnServer = new VAST.ICE.TurnServer(turnPars);
this.turnServer.Start();

TURN Server Parameters

Parameter Description
UserCredentials Username-password pairs for TURN authentication
PublicIPv4Address Server's public IPv4 address
PublicIPv6Address Server's public IPv6 address (optional)
UdpServerIPv6EndPoint IPv6 UDP endpoint (set to null to disable)
TcpServerIPv6EndPoint IPv6 TCP endpoint (set to null to disable)

If the server does not have an IPv6 address, disable the IPv6 endpoints:

turnPars.UdpServerIPv6EndPoint = null;
turnPars.TcpServerIPv6EndPoint = null;

For secure TURN (TURNS over TLS):

turnPars.TlsServerIPv4EndPoint = new IPEndPoint(IPAddress.Any, 5349);
turnPars.TlsServerIPv6EndPoint = new IPEndPoint(IPAddress.IPv6Any, 5349);
turnPars.CertificateThumbprint = "YOUR_CERTIFICATE_THUMBPRINT";

Creating the Signaling Server

this.server = new VAST.WebRTC.WebRtcStandaloneSignalingServer(8888, 0, "/rtc", parameters);
this.server.Authorize += Server_Authorize;
this.server.Start();

Constructor Parameters

Parameter Value Description
httpPort 8888 HTTP port for the signaling endpoint
httpsPort 0 HTTPS port (0 = disabled)
path "/rtc" HTTP handler path for signaling
parameters WebRTC server parameters with ICE configuration

The signaling server can also be created with an existing HttpServer instance instead of specifying ports directly — useful when sharing the HTTP server with other services.

Authorization

private void Server_Authorize(object sender,
    VAST.WebRTC.WebRtcStandaloneSignalingServer.AuthorizeEventArgs e)
{
    e.Accept = true;
}

The Authorize event fires for each incoming connection. The handler receives:

Property Type Description
Accept bool Set to true to allow the connection
EndPoint EndPoint Client's network endpoint
InboundUri string The request URI
RoomId string The room the client is joining

The sample accepts all connections. In production, implement authentication logic based on the request URI, room ID, or external token validation.

Access URL

Peers connect to the signaling server via:

ws://server:8888/rtc

The supplied rtc_ws_two_way.html page provides a simple UI for joining rooms and establishing peer connections. In production, use the signaling WebSocket endpoint from your own client application.

See Also