DEV Community

Hamit Demir
Hamit Demir

Posted on

WebRTC Components

We will use Client-A and Client-B as examples to explain WebRTC's components below.

SDP (Session Description Protocol)

SDP is a simple string-based protocol and it is to share supported codecs between browsers.

In our example,

Client-A creates its SDP ( called offer) and saves it as local SDP then shares it with Client-B.
Client-B receives the SDP of Client-A and saves it as a remote SDP.
Client-B creates its SDP (called answer) and saves it as a local SDP then shares it with Client-A.
Client-A receives the SDP of Client-B and saves it as a remote SDP.
The signaling server is responsible for these SDP transfers between peers.

Let assume Client-A may support H264, VP8, and VP9 codecs for video, Opus, and PCM codecs for audio. Client-B may support only H264 for video and only Opus codec for audio. For this case, Client-A and Client-B will use H264 and Opus for codecs. If there are no common codecs between peers, peer-to-peer communication cannot be established.

ICE (Interactivity Connection Establishment)

Interactive Connectivity Establishment (ICE) is used in problems where two nodes across the Internet must communicate as directly as possible, but the presence of NATs and Firewalls makes it difficult for nodes to communicate with each other. It is a Networking technique that makes use of STUN (Session Traversal Utilities for NAT) and TURN (Traversal Using Relays Around NAT) to establish a connection between two nodes that is as direct as possible.

WebRTC STUN Server (Session Traversal Utilities for NAT)

STUN Server is responsible to get all the addresses of a machine. For example, our computers generally have one local address in the network and there is a second address we see when we connect to, this IP address is actually the Public IP address of our Internet Gateway(modem, router, etc.) so let’s define STUN server; STUN servers let peers know theirs Public and Local IP addresses.

Btw, Google provides a free STUN server (

define stun- stun server Direct connection between peers[/caption]

WebRTC TURN Server (Traversal Using Relays around NAT)

TURN (Traversal Using Relays around NAT) is a protocol that assists in the traversal of network address translators (NAT) or firewalls for WebRTC applications. TURN Server allows clients to send and receive data through an intermediary server. The TURN protocol is the extension to STUN. Sometimes, addresses got from the STUN server cannot be used to establish for peer to peer connections between peers because of NAT/Firewall. In this case, data relays over TURN Server

WebRTC Basics & WebRTC Components 1 Connection over TURN server between peers

In our example,

Client-A finds out their local address and public Internet address by using the STUN server and sends these addresses to Client-B through Signalling Server. Each address received from the STUN server is an ICE candidate.
Client-B does the same, gets local and public IP addresses from the STUN server, and sends these addresses to Client-A through Signalling Server.
Client-A receives Client-B’s addresses and tries each IP address by sending special pings in order to create the connection with Client-B. If Client-A receives a response from any IP address, it puts that address in a list with its response time and other performance credentials. At last, Client-A chooses the best addresses according to its performance.
Client-B does the same in order to connect to Client-A
RTP (Real-Time Protocol)
RTP is a mature protocol for transmitting real-time data on top of UDP. Audio and Video are transmitted with RTP in WebRTC. There is a sister protocol of RTP which name is RTCP(Real-time Control Protocol) which provides QoS in RTP communication. RTSP(Real-time Streaming Protocol) uses RTP protocol as well in data communication.

WebRTC Signaling Server

The last part is the Signalling Server which is not defined in WebRTC. As mentioned above, Signaling Server is used to send SDP strings and ICE Candidates between Client-A and Client-B. The Signaling Server also decides which peers get connected to each other. WebSocket technology is the preferred way to Signalling Servers for communication.

Discussion (0)