WebRTC (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
WebRTC is entirely peer to peer, so you don’t have to pay for any of the bandwidth across the wire. Additionally, because WebRTC 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 WebRTC, the user has to upload said file to a server, and the recipient user has to download that file. With WebRTC, these files are transferred directly through the WebRTC Data Channel, no servers or infrastructure required.
WebRTC to a Developer
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?
So where does PubNub fit into WebRTC? 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 WebRTC 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.
WebRTC Use Cases
Because WebRTC enables voice, video, and data communication, there are many use cases for WebRTC, 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).
The WebRTC 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 utalizing the WebRTC data channel.
PubShare (P2P WebRTC Filesharing)