Home

 / Blog / 

WebRTC - Everything You Need To Know

WebRTC - Everything You Need To Know

November 3, 20234 min read

Share

WebRTC.png

Definition

WebRTC, standing for "Web Real-Time Communication," facilitates direct peer-to-peer communication on the web. This means that users can exchange information – be it video, audio, or data – in real time without needing intermediary servers to relay this data. Key benefits include reduced latency, lower server costs, and a more seamless user experience.

What does it really mean?

Imagine you're at a toy store, and you see a set of walkie-talkies. These devices allow two people to communicate directly with each other without any wires, just by pressing a button. Similarly, WebRTC is a tool that allows computers (like your laptop or smartphone) to "talk" to each other directly, without needing a central server to connect them. Just like how the walkie-talkies don't need a central radio tower to relay messages, computers using WebRTC can share video, audio, and data directly. So, when you're video-calling a friend using an app powered by WebRTC, it's like using a digital walkie-talkie.

History of WebRTC

What was used before WebRTC?

In the early days of the Internet, communication followed a server-client model. It was linear and one-directional: your computer requested data, and a server delivered it. It's reminiscent of a librarian fetching a book for you upon request. This model, though reliable, was sluggish, especially when applied to real-time activities like voice or video calls.

What challenges did it face?

The primary challenge was the internet's inherent lack of support for real-time communication (RTC). Three significant roadblocks were:

  • The internet, in its native form, was more about fetching and delivering data, akin to 'asking and receiving.' It wasn't built for real-time exchanges.
  • Foundational protocols, such as TCP, facilitated reliable but delayed communication. Think of it as sending a letter and then waiting for a reply.
  • The early internet could not handle multimedia, meaning it couldn't naturally understand or transmit data from cameras or microphones.

How does WebRTC solve it?

WebRTC, an evolution of RTC adapted for the web, was the game-changer. It embedded RTC functionalities right into browsers, eliminating the need for external software or plugins. Key transformative features of WebRTC included:

  • NAT Traversal Techniques: Through technologies like STUN and TURN, WebRTC enabled devices to communicate directly, bypassing intermediary servers. Imagine having a direct chat instead of playing the 'telephone game' through intermediaries.
  • UDP Integration: Unlike the 'letter-like' TCP, UDP facilitates a live chat experience, vital for real-time activities where timely exchange matters.
  • Multimedia Enhancement: WebRTC can recognize and transmit multimedia, turning our devices into potent tools for communication without external software's need.

WebRTC - Underlying Protocols and Methodologies

WebRTC represents a convergence of many advanced protocols and methodologies to enable real-time communication in a decentralized manner.

i) API Components: At its core, WebRTC has three main API components:

  • MediaStream (getUserMedia): Grants web access to the user's camera and microphone.
  • RTCPeerConnection: Manages the entire lifecycle of the P2P connection, including signal processing, codec handling, peer discovery, and more.
  • RTCDataChannel: Allows bidirectional transfer of generic data between peers.

ii) Signaling: While WebRTC handles P2P communication, it doesn't inherently define the signaling method. Developers must implement this (using WebSocket, for example) to exchange metadata for coordination between peers, like session control messages and network configuration.

iii) NAT Traversal: One of the key challenges that WebRTC addresses is NAT traversal. It uses the STUN (Session Traversal Utilities for NAT) server to discover public IP addresses and the TURN (Traversal Using Relays around NAT) server as a fallback to relay traffic when direct connection fails.

iv) Codec Support: WebRTC has had debates on mandatory codecs, it commonly supports VP8 and H.264 for video and Opus for audio.

v) Extensibility: Developers can utilize WebRTC not just for audio/video communication but also for data transfers, gaming, and other real-time applications, thanks to the extensible nature of the RTCDataChannel

How WebRTC Works

How WebRTC Works

  1. RTCPeerConnection: Both Peer A and Peer B create an RTCPeerConnection object to manage the connection.
  2. Offer Creation: Peer A generates an offer using createOffer() and sets it as the local description with setLocalDescription().
  3. Offer Exchange: This offer is sent to Peer B via a signaling server (Using SDP).
  4. Answer Creation: Peer B receives the offer and sets it as the remote description using setRemoteDescription(). Then, Peer B creates an answer using createAnswer() and sets it as the local description.
  5. Answer Exchange: The answer is sent back to Peer A via the signaling server.
  6. Final Setup: Peer A receives the answer and sets it as the remote description, completing the initial setup.
  7. ICE Candidates: Both peers exchange ICE candidates to find the best possible path for the data to travel between them. This is done using the onicecandidate callback and addIceCandidate() method.
  8. Connection Established: By the end of this process, a peer-to-peer connection is established, allowing for the exchange of audio, video, or data.

Frequently Asked Questions

Why is WebRTC popular?

WebRTC is popular because it offers real-time peer-to-peer communication without plugins, is supported by major browsers, and ensures encrypted and high-quality communication.

Is WebRTC safe to use?

WebRTC is designed with security in mind, employing end-to-end encryption for data, audio, and video streams. However, its safety also depends on implementation details and proper handling of the signaling process. Users should ensure they're using reputable applications that leverage WebRTC's security features effectively.

Is WebRTC supported by all browsers?

WebRTC is supported by most major browsers, including Chrome, Firefox, Edge, and Safari. However, some older browsers or specific versions might not support it. Always check the browser's documentation or compatibility tables for the most up-to-date information.

References

  • https://web.dev/articles/webrtc-basics
  • https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API
  • https://en.wikipedia.org/wiki/WebRTC
  • https://www.100ms.live/blog/webrtc-video-call

Glossary

Share

Related articles

See all articles