What is WebRTC?

5 min read Joe Hanson on Jan 15, 2014
Try PubNub Today

Free up to 1MM monthly messages. No credit card required.

Subscribe to our newsletter

By submitting this form, you are agreeing to our Terms and Conditions and Privacy Policy.

What is WebRTC and why should I use it?

Since we wrote this post, we’ve made some changes to our what we do, and what we don’t do with WebRTC. Learn more here.

Web Real-time CommunicationsWebRTC (Web Real-time Communications) enables peer to peer video, audio, and data communication between two web browsers. This allows for video calling, video chat, and peer to peer file sharing entirely in the web browser, with no plugins.

Why You Should Use WebRTC

Because WebRTC requires no plugins, frameworks or applications, all you need is a compatible browser. To an end user, these applications “just work” right out of the box. No Flash, no Silverlight, no JavaScript API, just pure video, audio, and data communication on any webpage.

It is entirely peer to peer, so you don’t have to pay for any of the bandwidth across the wire. Additionally, because it is entirely browser to browser, you get the highest performance and lowest latency possible. For example, say a user is trying to share a file. Without it, the user has to upload said file to a server, and the recipient user has to download that file. With it, these files are transferred directly through the WebRTC Data Channel, no servers or infrastructure required.

Peer to Peer WebRTC

WebRTC to a Developer

From a developer’s standpoint, there is a bit more that goes into making a this type of application work. It is an integral part of the HTML5 specification, managed by the IETF and W3C. It is exposed in the browser using JavaScript.

WebRTC works by connecting two browsers through the RTCPeerConnection. First, the browsers are connected through signaling, by passing the Session Description Protocol (SDP). This signaling discovers where the two users are and how to connect. Once the RTCPeerConnection is open, video, audio, and data communication can be sent between the two browsers.

To make it work, all you need is two web browsers and a way to transfer a SDP between them. The SDP includes information about your computer, what audio codecs you support, how you can transmit data between computers, and what ports are available on your computer that you can connect to. You can read more about SDPs here.

Think of SDPs like business cards. You exchange them with somebody else, and now you know how to contact each other. Because methods of transferring SDPs are not detailed in the specification, you have to provide your own signaling implementation. This is done by implementing your own way to transfer the SDP data.

Right now, WebRTC is compatible with Chrome, Firefox and most recently Opera, on both desktops and Android devices (this includes interoperability between the two). Internet Explorer and Safari have remained silent so far, but are expected to have implementations in the near future.

How Does PubNub Work With WebRTC?

WebRTC Diagram

So where does PubNub fit into this? You need some way to transfer the SDP from browser A to browser B. The PubNub Data Stream Network can be used as a scalable signaling server for these apps. PubNub features, such as Presence and Storage/Playback also can be used to enhance those apps.

When calling another user through a WebRTC 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. PubNub 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.

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.

Use Cases

Because WebRTC enables voice, video, and data communication, there are many use cases, ranging from basic video/voice chat to multiplayer gaming to file sharing and so on.

Video and Audio

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 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, a JavaScript video chat application that runs entirely on WebRTC and PubNub.

Skype-like WebRTC video chat application

Data Channel

The Data Channel adds another unique dimension to WebRTC applications. Sending data between two users in today’s browser world is a tough process with JavaScript, and most developers rely on a server as the middle man. With this, the Data Channel API allows the passing of arbitrary data across the connection. This allows for large scale file sharing, fast action multiplayer games, and even remote control applications.

The Data Channel eliminates the need to upload files to cloud services, such as Dropbox or Google Drive, to perform file transfers or share with others. Similar to these cloud services, the Data Channel allows users to transfer large amounts of data very quickly, all in the web browser in true peer to peer fashion. Check out PubShare, a peer to peer file transfer application powered by WebRTC and PubNub.

Universal remote control applications are another interesting implementation of the Data Channel. Smartphones use the RTCDataChannel to connect to SmartTVs, and this allows users to send data packets between the two devices (for example, this data can then be used to send instructions such as pausing or playing a streaming audio or video service). Anything in a web browser can easily be controlled by utilizing the data channel.

Additional Resources


JavaScript Skype with WebRTC and PubNub


Get Started
Try our APIs for free

More from PubNub

Building a Core Product Strategy that Meets a Market Need
News Jun 1, 20221 min read

Building a Core Product Strategy that Meets a Market Need

Patrick Ng, Innovation Director at Spark Launchpad, joins Casey Clegg, COO at PubNub, to discuss effective ideation and the...

PubNub Staff

PubNub Staff

Can Empathy Exist in the Metaverse
News May 16, 20221 min read

Can Empathy Exist in the Metaverse

A roundtable discussion led by PubNub’s COO, Casey Clegg, exploring the topics of what it means to be human in a virtual world.

PubNub Staff

PubNub Staff

How to Advance Telehealth and Virtual Care Technologies
News May 2, 20221 min read

How to Advance Telehealth and Virtual Care Technologies

Dr. Joe Kvedar, Chair of the Board for the American Telemedicine Association, joins our COO, Casey Clegg, to discuss why...

PubNub Staff

PubNub Staff