WebRTC

 
 

Real Time Collaboration with JS & HTML5

 
Om Shankar
JavaScript freak. HTML5 Aficionado.
Why HTML5
 

Why you speak HTML5 & WebRTC in a JavaScript Talk?

Answer Why HTML5
 

If something can be done in JavaScript,

it will be eventually done in JavaScript

- Jeff Attwood

HTML5 is meaningles without JavaScript APIs

All WebRTC is in JavaScript

Just Want Internet
 

I just want Internet, What the hell is HTML5?

Web as an Application

Answer Thinking
 

Communicate & Share? Record & Play? Create and Draw?

Drag Drop, 3D, Video Audio, Games?

Question
 

You tell me more!

You tell me right now!!

The POWER

 
HTML5 Features
WebRTC Logo 2

Web Real Time Communication

 
Real Time P2P communication of Audio, Video and Data
Without plugins.
API Standards & Specs @ W3C.

Browser Support

Chrome Firefox Safari Opera IE
 

Frameworks / Implementations

Where is JavaScript?

 
  • Acquiring Video and Audio
    getUserMedia ~ MediaStream
  • Sharing Streams with peers - AKA Communicating !
    RTCPeerConnection  RTCIceCandidate
  • Sharing data
    RTCDataChannel

Acquiring Video and Audio

getUserMedia
              
var constraints = {video: true, audio: true };

navigator.getUserMedia(constraints, successCallback, errorCallback);

function successCallback(stream) {
  var video = document.querySelector("video");
  video.src = window.URL.createObjectURL(stream);
}

function errorCallback(error) {
  alert("Error: ", error);
}
              
            
  • constraints - Must for getUserMedia, specifies Media type, resolution, etc.
  • video - HTML5 DOM element
Webcam toy

Communicating Streams

RTCPeerconnection
              
var peerCon = new window.RTCPeerConnection(configuration);

peerCon.addStream(localStream); // got from getUserMedia
peerCon.onaddstream = function(e) {
...

peerCon.addIceCandidate(candidate);
peerCon.onicecandidate = function(e) {
...

peerCon.setLocalDescription(description); peerCon.setRemoteDescription(new RTCSessionDescription(..));
peerCon.createOffer(IceCandidate); peerCon.createAnswer(...)
              
            
  • IceCandidate - ICE - f/w to bypass Firewalls
  • RTCSessionDescription - Metadata per SDP

ICE Breaker

ICE Breaker

Communicating Data

RTCDataChannel
              
var peerCon = new window.RTCPeerConnection( servers, {
    optional: [{ RtpDataChannels: true }]
  });

peerCon.ondatachannel = function(event) {
  receiverChannel = event.channel;
  receiverChannel.onmessage = function(event){ receiveDOMElement.innerHTML = event.data; };
};

XmitterChannel = pc.createDataChannel("sendDataChannel", {reliable: false});
XmitterChannel.send('Hello WebRTC');
              
            
  • RtpDataChannels: true - Arbitrary data via the same RTCPeerConnection.
  • onmessage , etc. - Same API as WebSockets.

ShareFest

Sharefest

Feature Support

getUserMedia

Chrome Desktop 20+, Chrome Android 29+

FireFox 17+

Opera, Opera Mobile 12+

RTCPeerConnection

Chrome Desktop 20+, Chrome Android 29+

FireFox 22+

RTCDataChannel

Chrome Desktop 26+, Chrome Android 29+

FireFox 22+

WebRTC & the Web

Architecture

Connectivity
Don't show me

I don't want to see that image again!

WebRTC: No Firewalls, STUN or TURN

Ideal Case
Courtesy: WebRTC - Google IO; and Self Modified

WebRTC: Behind NAT Firewall - STUN

Behind NAT Use STUN
Courtesy: WebRTC - Google IO

WebRTC: STUN Fails, try TURN

Using TURN
Courtesy: WebRTC - Google IO
Tell me

What is STUN, TURN, SDP and ICE?

You tell me! You tell me right now!!

WebRTC: Stuff

Terminologies

  • NAT - Network Address Translation
  • ICE - Interactive Connectivity Establishment
  • STUN - Session Traversal Utilities for NAT
  • TURN - Traversal Using Relays around NAT
  • Signal Channel - PUSH enabled communication channel
  • SDP - Session Description Protocol

The Exchange - STUN, TURN

STUN TURN

The Exchange - FLOW

Flow

The Exchange - Simple

Simple Flow

ICE Breaker

JSfoo Demo APP

ICE Breaker

WebRTC: Stuff

R & D over Internet

Cool Extras

 
 
JavaScript + HTML5 = Awesomeness

Thank You

 

Om Shankar

@om_invincible

invincible.om@gmail

github.com/OmShiv

geekyogi.tumblr.com

State