How WebRTC Powers Peer‑to‑Peer Video Calls and Modern Live Streaming
This article explains WebRTC fundamentals, including SDP, ICE, and signaling, outlines the peer‑to‑peer communication flow, and compares RTMP, direct WebRTC, and media‑server‑based WebRTC solutions for live streaming, highlighting their advantages and drawbacks.
Introduction
WebRTC is a free, open‑source real‑time communication technology that integrates audio/video capture, encoding/decoding, streaming, and rendering. It provides a simple JavaScript API on top of native code, enabling peer‑to‑peer communication with just a few lines of code and strong cross‑platform support in major browsers.
Basic Concepts
SDP (Session Description Protocol) describes media and transport information for a session, including media type, protocol, format, and remote address details. It is a multi‑line key‑value text document.
Offer – the SDP description generated by the initiating party.
Answer – the SDP description generated by the responding party.
Signaling – the channel that coordinates the exchange of SDP, session control, network, and error information between peers.
WebRTC Communication Flow
Client A initializes local audio/video devices and creates an SDP offer containing media information.
Client A sends the SDP offer to Client B via a signaling server.
Client B receives the offer, initializes its devices, and creates an SDP answer.
Client B sends the answer back to Client A through the signaling server.
Both clients exchange SDP details and establish a P2P channel for media transmission.
ICE (Interactive Connectivity Establishment)
Because most clients sit behind NATs with private IPs, direct connections often fail. WebRTC uses ICE to discover the best path:
ICE first tries host addresses obtained from the OS/network card.
If that fails, it sends a binding request to a STUN server, which discovers the public IP and returns it.
Both peers replace private addresses in SDP with the discovered public addresses.
If STUN cannot establish a path, a TURN server acts as a relay, forwarding traffic between the peers.
Open‑source TURN/STUN implementation: coturn (https://github.com/coturn/coturn). Configuration details can be found at the WebRTC samples page.
WebRTC vs. Traditional Live‑Streaming Solutions
1. RTMP
Clients capture audio/video and push streams to a media server via RTMP; the server then distributes the streams to viewers.
Advantages
Excellent CDN support from major providers.
Mature technology with easy SDK integration (e.g., Agora, Jiguang).
High concurrency, suitable for large‑scale live events.
Disadvantages
TCP‑based, leading to higher latency compared to UDP‑based solutions.
Does not support browser‑based publishing.
2. Peer‑to‑Peer WebRTC
Direct WebRTC connections are ideal for small‑scale video conferences where each participant establishes a P2P link.
Advantages
Simple integration in browsers; developers only need to call JavaScript APIs.
Reduces server bandwidth costs.
Lower latency thanks to UDP transport.
Disadvantages
Browser performance limits the number of simultaneous streams; multi‑user live streaming is challenging.
Limited audio/video processing capabilities; integrating advanced features (e.g., beauty filters) is difficult.
Quality cannot be guaranteed across regions and carriers.
Inconsistent support on mobile browsers, especially in China.
Content moderation and replay generation are hard to implement.
3. Media‑Server‑Based WebRTC
To overcome the limitations of pure P2P, a media server aggregates streams from publishers and redistributes them to viewers.
Open‑source media servers include:
Kurento – https://github.com/Kurento/kurento-media-server
licode – https://github.com/lynckia/licode
janus – https://github.com/meetecho/janus-gateway
Advantages
Eliminates client‑side performance bottlenecks and enables complex scenarios.
Supports many concurrent viewers with high scalability.
Browser‑based integration remains simple with low latency.
Disadvantages
Higher development cost; requires building or customizing a media server.
Less mature ecosystem compared to RTMP solutions.
Conclusion
Pure peer‑to‑peer WebRTC is unsuitable for large‑scale live streaming due to client limitations. Media‑server‑assisted WebRTC offers a viable path but lacks mature, turnkey solutions, requiring developers to weigh implementation effort against expected benefits.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Huajiao Technology
The Huajiao Technology channel shares the latest Huajiao app tech on an irregular basis, offering a learning and exchange platform for tech enthusiasts.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
