Insights

What is WebRTC?

4 min read Darryn Campbell on Mar 6, 2024

WebRTC Defined

WebRTC, which stands for Web Real-Time Communication, is an open-source project that provides real-time, peer-to-peer communication for data, audio, and video between two endpoints such as web browsers or within apps using JavaScript APIs. This technology has seen significant advancements and improvements since its inception, including better network traversal, enhanced data streaming, and bandwidth capabilities. Given its robust functionalities, WebRTC has gained widespread adoption in various sectors including e-learning, telehealth, and real-time collaboration tools, solidifying its stand in the current market.

History of WebRTC

WebRTC was first released in 2011 by Google and over time, received the backing of major companies such as Apple, Microsoft, Mozilla, and Opera. It's compatibility with both mobile and desktop browsers like Google Chrome, Safari, Mozilla Firefox, Edge, and others, allows developers to integrate communication capabilities directly into browser-based applications or mobile applications without needing additional plugins.

In recent years, WebRTC has seen a surge in adoption due to advancements in internet connectivity and demand for real-time communication apps. Its continuous evolution is a testament to the collaborative efforts of the tech community, including corporations, independent contributors, and standard bodies.

Common WebRTC Use Cases

WebRTC serves numerous use cases, from real-time audio and video calling and chat to peer-to-peer file sharing. Advancements in technology have further expanded the application of WebRTC to health care, live streaming platforms, and video conferencing:

  • In-browser / in-app customer support chat, now enhanced with features like screen sharing and real-time annotations.

  • Telemedicine applications facilitate doctor-patient video/audio calls, aiding in video communication, now supporting high-definition streams, and secure data channels for sharing health records.

  • Peer-to-peer file sharing is now capable of handling larger files and faster transfer speeds.

  • Real-time gaming and live streaming platforms, with WebRTC's low-latency streaming capabilities.

  • Collaborative tools featuring live video and audio conferencing, document editing, and more.

How Does WebRTC Work?

WebRTC operates by connecting two browsers through the RTCPeerConnection, facilitated by signaling protocols such as Session Description Protocol (SDP). Network traversing procedures like STUN (Session Traversal Utilities for NAT) and TURN (Traversal Using Relays around NAT) protocols have been incorporated into WebRTC's working mechanism to handle connectivity in different network scenarios. This includes establishing a direct connection even through firewalls or NATs, determining public IP addresses, and relaying data if necessary using TURN servers.

Using WebRTC through RTCPeerConnection

WebRTC provides an RTCPeerConnection interface for setting up a peer-to-peer connection. The RTCPeerConnection allows for the establishment of a connection with low-latency, high-quality voice and video calling, by handling signal processing, codec handling, peer-to-peer communication, security, and bandwidth management. Additional methods like getStats() have been introduced to fetch statistical data about the connection, aiding developers in monitoring and optimizing the call's performance.

How to Use WebRTC Through RTCDataChannel & MediaStream

WebRTC allows data exchange through the RTCDataChannel, a component of the RTCPeerConnection. The RTCDataChannel API allows bidirectional communication of arbitrary data between peers. It uses the Stream Control Transmission Protocol (SCTP), providing reliable and secure data transfer and opening up possible use cases of direct file sharing and real-time gaming. The MediaStream API, also known as getUserMedia, enables access to local cameras and microphones, with user consent. Recent updates allow more granular control over the media streams, such as adjusting the video resolution, frame rate, and audio quality.

How to Use PubNub and WebRTC to Build Applications

Initially, you need some way to transfer the SDP from browser A to browser B. The PubNub network can be used as a signaling server for these apps. Features, such as Presence and Storage/Playback also can be used to enhance those apps.

When calling another user through a WebRTC protocol or app, the caller needs to know if the callee is currently online or offline and what device they’re using, if they’re available to accept the call, etc. 

Presence gives you all that information and enables you to show the users they can connect with. This is essential for signaling, to prevent users from trying to connect to other users that aren’t available.

A Note on WebRTC protocol and texting

The WebRTC protocol does not provide storage capabilities, and as a result, there are no records of what messages have been sent. Specifically, with text chat, users expect a history of previous chat conversations. PubNub’s Storage/Playback feature allows users to see a history of past conversations over a desired period of time.

Basically; PubNub provides:

WebRTC vs. WebSockets

WebSockets provide a TCP-based, full-duplex communication protocol between client and server. Conversely, WebRTC supports peer-to-peer exchanges over UDP, allowing for real-time video and audio data streams. The distinction between WebRTC and WebSockets has become more significant with the increasing demand for real-time applications, prompting many developers to leverage the unique strengths of both technologies.

How to Use Audio & Video with WebRTC

With WebRTC, video and voice communication can be easily implemented into any website. This adds advanced levels of interaction to a website, allowing users to communicate in context and in real time, with either site operators or with each other. Such capabilities are more desirable than current limitations whereby users need to call a number, download a plugin, or leave your website. For example, a financial institution website could easily embed a WebRTC communication app to allow users to quickly speak to a financial representative (rather than forcing them to use their phone to endlessly talk with an automated representative).

Another example of WebRTC with voice and video would be a Skype-like video chat application, that can be used entirely in the web browser. This means that end users don’t have to install any software or plugins, and can easily connect to one another, through video, audio, and text chat, browser to browser. We built WebRTC.co, a JavaScript video chat application that runs entirely on WebRTC and PubNub.

What is the Future of WebRTC?

As a video and data service, WebRTC is pretty much here to stay; with buy-in from the major browser players and commitment to keep the mobile and desktop APIs up to date, you will find more and more apps moving to keep consumers on the platform with tools that support video chats for services such as dating, gaming, and healthcare. 

0