Skip to main content

Introduction

Ant Media Server provides a comprehensive WebRTC API that enables real-time audio and video communication in web browsers and mobile applications. The WebRTC API consists of three main components:
  • IWebRTCAdaptor - Core WebRTC adapter interface for managing streams and clients
  • IWebRTCClient - Interface for WebRTC client connections and media transmission
  • IWebRTCMuxer - Interface for multiplexing streams to multiple clients

Architecture

The WebRTC architecture in Ant Media Server follows a client-server model with the following components:

Server-Side Components

WebRTC Adaptor (IWebRTCAdaptor)
  • Manages registration and unregistration of muxers and clients
  • Handles adaptive streaming quality based on network conditions
  • Tracks active streams and viewer statistics
  • Implements excessive bandwidth algorithms for optimal streaming
WebRTC Muxer (IWebRTCMuxer)
  • Multiplexes single stream to multiple WebRTC clients
  • Manages video and audio packet distribution
  • Supports multiple tracks for advanced use cases
  • Provides client registration and management
WebRTC Client (IWebRTCClient)
  • Represents individual WebRTC peer connection
  • Handles SDP offer/answer exchange
  • Manages ICE candidate gathering and exchange
  • Sends video and audio packets to connected peers

Client-Side Components

On the client side, you’ll use the JavaScript WebRTC SDK which communicates with the server through:
  1. WebSocket Signaling - For exchanging SDP and ICE candidates
  2. WebRTC Peer Connection - For actual media transmission
  3. Media Streams - For accessing camera/microphone or receiving remote streams

Signaling Flow

Publishing Flow

Playing Flow

Peer-to-Peer Flow

Browser Requirements

Supported Browsers

Ant Media Server WebRTC API is compatible with all modern browsers that support WebRTC:
BrowserMinimum VersionNotes
Chrome74+Full support
Firefox66+Full support
Safari12.1+Requires HTTPS
Edge79+Chromium-based
Opera62+Full support

Mobile Browser Support

PlatformBrowserMinimum Version
iOSSafari12.1+
iOSChrome74+
AndroidChrome74+
AndroidFirefox66+

Required Browser APIs

The following browser APIs must be supported:
  • getUserMedia - For accessing camera and microphone
  • RTCPeerConnection - For establishing peer connections
  • WebSocket - For signaling communication
  • MediaStream - For handling media streams

HTTPS Requirement

WebRTC requires a secure context (HTTPS) for accessing media devices in production environments. The only exception is:
  • localhost for development purposes
  • 127.0.0.1 for local testing

Key Features

Adaptive Bitrate Streaming

The server automatically adjusts stream quality based on network conditions:
  • Automatic Quality Selection - Server selects optimal bitrate for each client
  • Force Stream Quality - Override automatic selection for specific resolution
  • Multiple Resolutions - Support for ABR with multiple quality levels

Statistics and Monitoring

Comprehensive statistics available through the API:
  • Client Statistics - Bitrate, packet loss, RTT measurements
  • Stream Information - Number of viewers, active streams
  • Performance Metrics - Frame send periods, packet counts

Clustering Support

WebRTC API supports clustered deployments:
  • Automatic stream routing between nodes
  • Load balancing across cluster
  • Registration to specific resolutions in cluster mode

API Reference

See the following pages for detailed API documentation:
  • Publishing - Learn how to publish WebRTC streams
  • Playing - Learn how to play WebRTC streams
  • Peer-to-Peer - Learn about P2P and conference modes

Next Steps

Publishing Streams

Learn how to publish WebRTC streams to Ant Media Server

Playing Streams

Learn how to play WebRTC streams from Ant Media Server

Peer-to-Peer

Learn about P2P communication and conferencing

Build docs developers (and LLMs) love