OMG
DATA
CHANNELS
AND HOW TO USE THEM


ERIC ZHANG




                      1
BINARY TYPES IN
JAVASCRIPT
Yes binary types exists:


ArrayBuffer
Blob
ArrayBufferView: Uint8Array, etc..




                                     2
WHY IS THIS COOL


Binary support means we can do
anything we want with data




                                 3
BINARY TYPES IN
JAVASCRIPT
Do these things with them:


URL.createObjectURL(blob)
XHR2
WebSocket
DataChannel




                             4
BACK TO
DATACHANNEL


Video and audio is pretty cool


But I’m excited about DataChannel
because




                                    5
BACK TO
DATACHANNEL


Arbitrary binary data between
arbitrary people


That is a lot of power


No permissions. No flags.




                                6
BUT WAIT THERES
MORE


Based on UDP – essential when
transmission delay matters


Configurable with SCTP, for TCP like
reliability if you want




                                       7
WHAT I REALIZED
DataChannel fundamentally changes
the web.


Data has always flowed between
server and client.


DataChannel allows client to client
flow




                                      8
THE POSSIBILITIES


File transfer


Faster
No privacy issues
No bandwidth costs




                     9
THE POSSIBILITIES


Multiplayer games


Substantially higher performance
because of lower UDP latency +
binary data




                                   10
THE POSSIBILITIES


High frequency events and messaging


Higher message rates possible with
UDP based transport




                                      11
PRIVACY


Imagine a decentralized Facebook


Data actually downloaded from your
browser while you browse the web.


Seamless experience




                                     12
DATACHANNEL
CHALLENGES




              13
BROWSER
COMPATIBILITY
Google Chrome - March 7th 2013

                                 GOOD
                                 GOOD
                                 GOOD
                                 BAD
No SCTP implementation = No binary, reliable
Not coming until later in 27




                                               14
BROWSER
COMPATIBILITY
Firefox – March 7th 2013


Nightly 22.0a1 - Several spec issues
being fixed RIGHT NOW
Bug 837919 - WebRTC: RTCPeerConnection constructor: FQDN not yet implemented (only IP-
#s).
Bug 846110 - PeerConnection ondatachannel callback receives channel in Firefox, but
in Chrome an event is passed in
Bug 837035 - Hook up DataChannel SDP to implementation (in particular port and
options)


Aurora 21.01a2 - Flagless support




                                                                                         15
BROWSER
COMPATIBILITY


Binary, reliable, and FF/Chrome
interop in stable versions at most a
few months away




                                       16
PROBLEM: JSON


I now have a binary DataChannel
between two browsers.


I want to send some binary data.




                                   17
PROBLEM: JSON
JSON is an extremely bad choice for
binary data. Base64 uses 37% more
bandwidth and is slow to
encode/decode.
You can never do this in JSON:
JSON.stringify({x: 1, y: binary });




                                      18
PROBLEM: JSON
Our DataChannel supports binary,
why use string serialization at all?


Binary serialization options:
MsgPack, Thrift, Avro, BSON,
ProtoBufs, BERT, and many more




                                       19
PROBLEM: JSON


MessagePack: Most JSON like. Very
compact. No schema, not designed
for typed languages like others.


Shitty for Javascript. JS has distinct
string / byte array types unlike many
other dynamic languages.




                                         20
PROBLEM: JSON
Solution is simple. Add string type to
MessagePack.
They hate this.
https://github.com/msgpack/msgpack/issues/121
https://github.com/msgpack/msgpack/issues/128




Talk to me about this afterwards




                                                21
PROBLEM: JSON
With a binary serialization format you
can do this:

blob = pack({x: 1, y: binary });
unpack(blob)
-> {x:1, y: binary}

Caveat: JS makes serializing part of UTF8 to binary hard. JSON is
much better.




                                                                    22
PROBLEM:
NAT TRAVERSAL
WebRTC takes care of NAT traversal
for you
But not if they are behind symmetric
NATs


~8% of connections according to
Google Talk dev help page
https://code.google.com/p/libjingle/wiki/FAQ




                                               23
PROBLEM:
NAT TRAVERSAL


You must provide both a TURN server,
a proxy for connections when things
don’t work right.


No bandwidth , latency savings in this
case.




                                         24
PROBLEM:
NOTIFYING CLIENTS
In order to establish connection,
offer/answer and ICE candidates must
be exchanged.


Solution:
You have to keep a WebSocket or XHR
stream or similar open. Consider
scaling issues.




                                       25
WEBRTC IS
SUPER
HAPPENING
GUARANTEED




             26
THIS ISNT LIKE THE
IPHONE


Whether you like it or not, almost
everyone is going to have WebRTC
and DataChannels in their browser
within a year.




                                     27
THIS IS CRAZY



The model of the web can
fundamentally change




                           28
THIS IS CRAZY


Someone is going to build the P2P file
transfer app that is ridiculously easy




                                         29
THIS IS CRAZY


Someone is going to build the
networking library for MMOs in the
browser




                                     30
THIS IS CRAZY


Someone is going to build the
BitTorrent of the web – just go on the
damn page and start downloading
movies (I mean Ubuntu ISOs). Crazy.




                                         31
THIS IS CRAZY


Someone is going to build the Node.js
of the browser.


File/network I/O, Sessions, persistent
memory in HTML5 storage, database
drivers, etc.




                                         32
THIS IS CRAZY


Someone is going to replace Skype,
and fragmented VOIP apps , and
telephones in general with the one
that just works in your browser.




                                     33
THIS IS CRAZY


Someone is going to build the peer-to-
peer CDN of the future.


http://peerkit.com




                                         34
THIS IS CRAZY
These aren’t novel ideas.
These are real problems. People have
been talking about them forever.


The technology just hasn’t existed
until today.




                                       35
THANKS FOR PAYING
ATTENTION
Now go home and code.


Twitter: @reallyez
Github: ericz

I’m currently working on PeerJS and
PeerKit. If you’re interested in this stuff, I’d
love to talk to you.




                                                   36

Why WebRTC DataChannel excites me

  • 1.
    OMG DATA CHANNELS AND HOW TOUSE THEM ERIC ZHANG 1
  • 2.
    BINARY TYPES IN JAVASCRIPT Yesbinary types exists: ArrayBuffer Blob ArrayBufferView: Uint8Array, etc.. 2
  • 3.
    WHY IS THISCOOL Binary support means we can do anything we want with data 3
  • 4.
    BINARY TYPES IN JAVASCRIPT Dothese things with them: URL.createObjectURL(blob) XHR2 WebSocket DataChannel 4
  • 5.
    BACK TO DATACHANNEL Video andaudio is pretty cool But I’m excited about DataChannel because 5
  • 6.
    BACK TO DATACHANNEL Arbitrary binarydata between arbitrary people That is a lot of power No permissions. No flags. 6
  • 7.
    BUT WAIT THERES MORE Basedon UDP – essential when transmission delay matters Configurable with SCTP, for TCP like reliability if you want 7
  • 8.
    WHAT I REALIZED DataChannelfundamentally changes the web. Data has always flowed between server and client. DataChannel allows client to client flow 8
  • 9.
    THE POSSIBILITIES File transfer Faster Noprivacy issues No bandwidth costs 9
  • 10.
    THE POSSIBILITIES Multiplayer games Substantiallyhigher performance because of lower UDP latency + binary data 10
  • 11.
    THE POSSIBILITIES High frequencyevents and messaging Higher message rates possible with UDP based transport 11
  • 12.
    PRIVACY Imagine a decentralizedFacebook Data actually downloaded from your browser while you browse the web. Seamless experience 12
  • 13.
  • 14.
    BROWSER COMPATIBILITY Google Chrome -March 7th 2013 GOOD GOOD GOOD BAD No SCTP implementation = No binary, reliable Not coming until later in 27 14
  • 15.
    BROWSER COMPATIBILITY Firefox – March7th 2013 Nightly 22.0a1 - Several spec issues being fixed RIGHT NOW Bug 837919 - WebRTC: RTCPeerConnection constructor: FQDN not yet implemented (only IP- #s). Bug 846110 - PeerConnection ondatachannel callback receives channel in Firefox, but in Chrome an event is passed in Bug 837035 - Hook up DataChannel SDP to implementation (in particular port and options) Aurora 21.01a2 - Flagless support 15
  • 16.
    BROWSER COMPATIBILITY Binary, reliable, andFF/Chrome interop in stable versions at most a few months away 16
  • 17.
    PROBLEM: JSON I nowhave a binary DataChannel between two browsers. I want to send some binary data. 17
  • 18.
    PROBLEM: JSON JSON isan extremely bad choice for binary data. Base64 uses 37% more bandwidth and is slow to encode/decode. You can never do this in JSON: JSON.stringify({x: 1, y: binary }); 18
  • 19.
    PROBLEM: JSON Our DataChannelsupports binary, why use string serialization at all? Binary serialization options: MsgPack, Thrift, Avro, BSON, ProtoBufs, BERT, and many more 19
  • 20.
    PROBLEM: JSON MessagePack: MostJSON like. Very compact. No schema, not designed for typed languages like others. Shitty for Javascript. JS has distinct string / byte array types unlike many other dynamic languages. 20
  • 21.
    PROBLEM: JSON Solution issimple. Add string type to MessagePack. They hate this. https://github.com/msgpack/msgpack/issues/121 https://github.com/msgpack/msgpack/issues/128 Talk to me about this afterwards 21
  • 22.
    PROBLEM: JSON With abinary serialization format you can do this: blob = pack({x: 1, y: binary }); unpack(blob) -> {x:1, y: binary} Caveat: JS makes serializing part of UTF8 to binary hard. JSON is much better. 22
  • 23.
    PROBLEM: NAT TRAVERSAL WebRTC takescare of NAT traversal for you But not if they are behind symmetric NATs ~8% of connections according to Google Talk dev help page https://code.google.com/p/libjingle/wiki/FAQ 23
  • 24.
    PROBLEM: NAT TRAVERSAL You mustprovide both a TURN server, a proxy for connections when things don’t work right. No bandwidth , latency savings in this case. 24
  • 25.
    PROBLEM: NOTIFYING CLIENTS In orderto establish connection, offer/answer and ICE candidates must be exchanged. Solution: You have to keep a WebSocket or XHR stream or similar open. Consider scaling issues. 25
  • 26.
  • 27.
    THIS ISNT LIKETHE IPHONE Whether you like it or not, almost everyone is going to have WebRTC and DataChannels in their browser within a year. 27
  • 28.
    THIS IS CRAZY Themodel of the web can fundamentally change 28
  • 29.
    THIS IS CRAZY Someoneis going to build the P2P file transfer app that is ridiculously easy 29
  • 30.
    THIS IS CRAZY Someoneis going to build the networking library for MMOs in the browser 30
  • 31.
    THIS IS CRAZY Someoneis going to build the BitTorrent of the web – just go on the damn page and start downloading movies (I mean Ubuntu ISOs). Crazy. 31
  • 32.
    THIS IS CRAZY Someoneis going to build the Node.js of the browser. File/network I/O, Sessions, persistent memory in HTML5 storage, database drivers, etc. 32
  • 33.
    THIS IS CRAZY Someoneis going to replace Skype, and fragmented VOIP apps , and telephones in general with the one that just works in your browser. 33
  • 34.
    THIS IS CRAZY Someoneis going to build the peer-to- peer CDN of the future. http://peerkit.com 34
  • 35.
    THIS IS CRAZY Thesearen’t novel ideas. These are real problems. People have been talking about them forever. The technology just hasn’t existed until today. 35
  • 36.
    THANKS FOR PAYING ATTENTION Nowgo home and code. Twitter: @reallyez Github: ericz I’m currently working on PeerJS and PeerKit. If you’re interested in this stuff, I’d love to talk to you. 36