WebRTC Basics and WebRTC Components
I will introduce the WebRTC basics and technical terms: SDP, ICE, STUN Server, TURN Server, RTP, and Signaling.
Join the DZone community and get the full member experience.Join For Free
I will introduce the WebRTC basics and technical terms: SDP, ICE, STUN Server, TURN Server, RTP, and Signalling.
I want to explain the WebRTC concept with an example. Let Client-A and Client-B are two pairs who want to communicate via WebRTC. Assume that Client-A starts communication.
WebRTC (Web Real-Time Communication)
WebRTC is a set of technologies that enables peer to peer duplex real-time communication between browsers even behind NAT addresses.
In our example, WebRTC is the technology to establish communication between Client-A and Client-B.
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 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 as 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 transfer 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 the only H264 for video and only Opus codec for audio. For this case, the 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)
ICE is the magic that establishes WebRTC connection between peers even if they are behind NAT/Firewall devices.
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 192.168.0.0 network and there is a second address we see when we connect to www.whatismyip.com, 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.
Google provides a free STUN server (stun.l.google.com:19302).
Direct connection between peers[/caption]
TURN(Traversal Using Relays around NAT) Server
Sometimes, addresses got from the STUN server cannot be used to establish for peer-to-peer connection between peers because of NAT/Firewall. In this case, data relays over TURN Server
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 a connection with Client-B. If Client-A receives a response from any IP addresses, 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.
The last part is the Signalling Server which is not defined in WebRTC. As mentioned above, the Signalling 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 in Signalling Servers for communication.
Signaling Message Sequence
In this post, I have introduced the basic components and terms under WebRTC technology without coding details.
In order to get more details about WebRTC, you can check these great posts, Getting Started with WebRTC, WebRTC Technology Transforms Live Streaming, and How to Create WebRTC Peer-To-Peer Communication.
Opinions expressed by DZone contributors are their own.
Opportunities for Growth: Continuous Delivery and Continuous Deployment for Testers
Personalized Code Searches Using OpenGrok
13 Impressive Ways To Improve the Developer’s Experience by Using AI
Superior Stream Processing: Apache Flink's Impact on Data Lakehouse Architecture