Skip to content

Instantly share code, notes, and snippets.

@scalabl3
Last active April 27, 2018 18:04
Show Gist options
  • Save scalabl3/6ff8933efd73c19f22be0fa8cc84f09e to your computer and use it in GitHub Desktop.
Save scalabl3/6ff8933efd73c19f22be0fa8cc84f09e to your computer and use it in GitHub Desktop.
Summary of WebRTC & PubNub

What is WebRTC? [OS]

WebRTC is a Protocol specifically designed for Peer-To-Peer streaming of video + audio. It includes video/audio compression algorithms/codecs, key framing, session control, etc. It does offer some messaging but that part of the protocol doesn't work very well. As a Protocol, like ftp, http, smtp, etc., it requires support at a lower level than the Application tier in most cases. Currently, support for the WebRTC protocol is not on every device/operating system. Notably, Apple devices don't support WebRTC natively. You can see support here: http://iswebrtcreadyyet.com/ and http://caniuse.com/#feat=rtcpeerconnection. Since Apple doesn't support natively, an SDK for iOS is needed, there is an open source one, or you can go with a full service SaaS with an SDK. The upsides of WebRTC is that it is free, works pretty well, and handles automatic upgrading and downgrading of compression/quality based on latency. The downsides of WebRTC is that the standards are still evolving, changing, and thus support on different platforms varies highly, as well as requiring frequent changes to SDK's etc.

Signaling [PubNub]

Establishing a WebRTC P2P connection requires knowing the location of both peers, i.e. both IP addresses, and for both to use the best network path between the two, i.e. STUN/TURN server. That means the IP addresses need to be known and exchanged between both peers. This is called Signaling. Signaling also is the equivalent of "making a phone ring" which is an audio signal that there is an incoming call. In the old POTS system, the signaler was a human Operator, who physically connected copper phone lines with a patch cable and made phones ring. In the case of VOIP and WebRTC, signaling is data transfer rather than electrical signal. PubNub is the perfect Operator to handle this signaling. When both devices are connected to PubNub, you can signal incoming calls, exchange IP addresses, "make phone ring" etc.

PubNub also can be used for typed chat messages and works much much better than WebRTC's messaging.

Internet Pathing

Once both IP addresses are known, specialized services called ICE/STUN/TURN Servers are used to find the highest speed/reliable paths through the Internet between the two peers. They also can act as a middleman for streaming through to circumvent firewalls. This stage of the connection process is important so that the audio/video has the lowest stream latency. There are literally tens of thousands of paths between any two peers, so using the best ones is what creates a more reliable stream/connection between peers leading to better video and audio quality.

Putting It All Together

Using PubNub for Signaling and Chat, a STUN/TURN service (free or paid) for Internet pathing, and WebRTC protocol on supported devices/platforms/sdks allows you to create a WebRTC based video/audio + typed chat.

Links to Resources

Knowledge Base of Resources including SDKs/Demos: https://www.pubnub.com/knowledge-base/discussion/252/does-pubnub-provide-webrtc-and-video-chat

Full Service SaaS for WebRTC/Chat on mobile: www.sinch.com Full Service SaaS for WebRTC, but can be expensive: www.tokbox.com STUN/TURN Server SaaS: www.xirsys.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment