What is WebRTC?
Published: 2024-03-05 21:03:40

### WebRTC Defined

[WebRTC](https://webrtc.org/), 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](https://www.pubnub.com/solutions/digital-health/), and [real-time collaboration tools](https://www.pubnub.com/solutions/multiuser-collaboration/), 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.
    

![](https://www.pubnub.com/cdn/3prze68gbwl1/6RGxRNvHpjDnS55Yackzm8/5c5d8953204d4735a8e1c9ba5fc23859/PeertoPeer.jpg)

### 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**
------------------------------------------------------

![](https://www.pubnub.com/cdn/3prze68gbwl1/4QbGEgmhK9dXPOVj0XHIiv/4a6775807145a9efcd70e83e638a2f30/WebRTC-Diagram.png)

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](https://www.pubnub.com/blog/getting-started-swift-pubnub-storage-playback-presence/) feature allows users to see a history of past conversations over a desired period of time.

Basically; PubNub provides:

-   SDP Signaling
    
-   [Presence status](https://www.pubnub.com/how-to/admin-portal-presence/)
    
-   Chat message storage
    

WebRTC vs. WebSockets
---------------------

[WebSockets](https://www.pubnub.com/blog/what-are-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](https://www.pubnub.com/blog/integrating-video-calling-in-chat-with-webrtc-and-pubnub/) that runs entirely on [WebRTC and PubNub](https://github.com/stephenlb/webrtc-sdk).

![](https://www.pubnub.com/cdn/3prze68gbwl1/3hU9HWjdkEj3Y15NfmostG/aa805363e6a0d2afe4b1d365e1625201/WebRTCSkype.png)

**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](https://www.pubnub.com/solutions/gaming/), and healthcare. 

#### Contents

[WebRTC Defined](#h-0)[History of WebRTC](#h-1)[Common WebRTC Use Cases](#h-2)[How Does WebRTC Work?](#h-3)[Using WebRTC through RTCPeerConnection](#h-4)[How to Use WebRTC Through RTCDataChannel & MediaStream](#h-5)[How to Use PubNub and WebRTC to Build Applications](#h-6)[A Note on WebRTC protocol and texting](#h-7)[WebRTC vs. WebSockets](#h-8)[How to Use Audio & Video with WebRTC](#h-9)[What is the Future of WebRTC?](#h-10)

How can PubNub help you?
========================

This article was originally published on [PubNub.com](https://www.pubnub.com/blog/what-is-webrtc/)

Our platform helps developers build, deliver, and manage real-time interactivity for web apps, mobile apps, and IoT devices.

The foundation of our platform is the industry's largest and most scalable real-time edge messaging network. With over 15 points-of-presence worldwide supporting 800 million monthly active users, and 99.999% reliability, you'll never have to worry about outages, concurrency limits, or any latency issues caused by traffic spikes.

Experience PubNub
-----------------

Check out [Live Tour](https://www.pubnub.com/tour/introduction/) to understand the essential concepts behind every PubNub-powered app in less than 5 minutes

Get Setup
---------

Sign up for a [PubNub account](https://admin.pubnub.com/signup/) for immediate access to PubNub keys for free

Get Started
-----------

The [PubNub docs](https://www.pubnub.com/docs) will get you up and running, regardless of your use case or [SDK](https://www.pubnub.com/docs)