What sort of services does PubNub provide with respect to WebRTC and video chat?
Before we get started here please review 3 Things WebRTC Can Not Do.
We get this question quite frequently because many struggle to understand the role that PubNub plays in WebRTC and video chat applications. So we will provide you with some details that should leave you with a full understanding of all the moving parts and the role those parts play.
What is WebRTC?
Wikipedia says that WebRTC (Web Real-Time Communication) is an API definition drafted by the World Wide Web Consortium (W3C) that supports browser-to-browser applications for voice calling, video chat, and P2P file sharing without the need of either internal or external plugins.
But WebRTC is not a standalone API. It needs a signaling service to coordinate communication and metadata needs to be sent between callers before a connection can be established. This metadata includes information such as:
- Session control messages to open and close connections
- Error messages
- Codecs/Codec settings, bandwidth and media types
- Keys to establish a secure connection
- Network data such as host IP and port
What does PubNub bring to the table?
You are going to need a signal protocol service. In other words, a rock solid reliable, low latency messaging service (that would be PubNub) and a hosted WebRTC solution for the audio/video streaming (PubNub does not handle this sort of media).
PubNub IS the Signaling Protocol Service
Once signaling has taken place, video/audio/data is streamed directly between clients, using WebRTC’s PeerConnection API. This peer-to-peer direct connection allows you to stream high-bandwidth robust data, such as video. PubNub makes the signaling incredibly simple, and in addition, gives you the power to do so much more with your WebRTC applications.
What PubNub is NOT
PubNub is not a server for WebRTC. In other words, video and audio data is not streamed over the PubNub network.
- A signaling service specifies ICE servers that the video chat can stream over.
- Public STUN servers provided by google can be used, but they are not very reliable.
- STUN or TURN servers are required to circumnavigate a firewall, else it will fail.
- Many services provide the total package of signaling and server in one, that is not PubNub. Our audience are the people who want to build their own, more custom service.
What is purpose STUN & TURN?
- STUN gets IP address for the client in NAT'ed environments
- TURN will stream the binary media (audi/video) which does not flow through PubNub's network.
So STUN provides the IP but there is nothing in WebRTC to provide a means to exchange IPs between clients and that is where PubNub comes in to server the role of the signal protocol.
Additional PubNub Resources
More Complete Service Offerings
If you are ready to build it all using just WebRTC, a streaming service and PubNub for your signaling, then you are ready to rock with the above details. But if you want to have much of this abstracted away then keep on reading below to find out about some offerings that will get you to your end goal faster and with less effort.
Sinch - Powering Communications for Mobile Apps
Sinch is a cloud-hosted, mobile communications platform that makes adding calling, verification, video, SMS, and IM into apps easier than ever. They have an SDK that is powered by PubNub and many PubNub customers use Sinch in their applications.
WebRTC is just one of the many features they offer - POWERING COMMUNICATIONS FOR MOBILE APPS: use the Sinch APIs to enhance your app with Voice, SMS, Verification, Video, and Instant Messaging.
Xirsys - WebRTC Cloud
XirSys hosts STUN and TURN servers catering to the needs of WebRTC applications.
What are STUN and TURN server for?
When you deploy your WebRTC application, you may need STUN and/or TURN servers (not a PubNub service) to make it all work. See this Stack Overflow thread to get a better understand of this.
Open Source Options
There are a few open source STUN and TURN server projects that can be downloaded and hosted with ease:
- Amazon AWS VM: Pre-made ready to deploy
- RFC5766 TURN: Google Code, TURN server
- One-to-many: Instructions on MCU for 1-to-many media servers. Necessary for large group chats and streams with hundreds+ users.
So as you can see, we do not provide audio/video streaming services but if you are building this solution, PubNub is a necessary piece to tie it all together with the signal protocol.
Mobile Native Options
If you are looking to implement WebRTC features in a native Android or iOS app, check out these resources:
- PubNub AndroidRTC example by our interns.
- BUILDING AN ANDROID WEBRTC VIDEO CHAT APP, by Kevin Gleason
- Bowser WebRTC Demo for iOS
- Perch iOS Sample App
More WebRTC Resources and Streaming Services
If you are still hungry for more details, check out the following: