RTCPeerConnection, Signaling, and DataChannels

In notebook:
FrontEndMasters Real-Time Web with Node.js
Created at:
2015-10-14
Updated:
2015-10-15
Tags:
JavaScript
4:58:56 - 5:11:51 RTCPeerConnection, Signaling, and DataChannels RTCPeerConnection is an object instantiated in your browser that allows direct communication with an RTCPeerConnection object in another browser. Once connected, streams like video or audio can then be attached to the connection. Kyle explains how this connections is facilitated through something called signaling. He also introduces DataChannelsthese are object that you instantiate and then to clients can connect.
then you can attach video or audio streams to this object very simply

to create the peer connection object:
  1. we attach the audio or video stream to the RTCPeerConnection object
  2. goes through the cloud
  3. since the other side is connected 
  4. it can connect the stream to the ​<audio>​ or ​<video>​ element
concept of Signaling
it's like setting up a blind date - a third person setting up the date, and the two person go at the specified date

once the browsers have been introduced we call the middleman

(serverless RTC - without any server)

the signaling process

  1. distinguish one browser as caller and other as receiver (doesn't matter which one is which)
  2. create a signaling server (typically with websockets)
  3. the caller creates an Offer SDP (codecs, network information)
  4. and sends it to the signaling server
  5. and the signaling server forwards the Offer SDP without modifying it

webRTC is p2p but is possible to have more clients connected, usually they elect a broadcast peer that broadcasts to everybody else

webRTC can work with firewalls (through STUN server - one by mozilla and one by google) - this is the Offer SDP
depending on the network you might need several rounds of communication - through ICE

the user doesn't need to be aware of this complexity

DataChannel

arbitrary two way datachannel between clients - transfer files, games

audio stream and video stream are one way but the DataChannel is duplex (two way) and encrypted

shows some example code. looks complex but most of it is vendor prefix

mostly it's ​return new RTCPeerConnection​ 
and
​return new RTCIceCandiate​ 
and
​return new RTCSessionDescription

then you can

​funciton signal(message){
  if (socket) {
    socket.emit("message", message)
  }
}

and ​socket.on​