Why WebRTC DataChannel excites me

36
OMG DATA CHANNELS AND HOW TO USE THEM ERIC ZHANG 1

description

Presented at the March 2013 SF WebRTC meetup.

Transcript of Why WebRTC DataChannel excites me

Page 1: Why WebRTC DataChannel excites me

1

OMGDATA CHANNELSAND HOW TO USE THEM

ERIC ZHANG

Page 2: Why WebRTC DataChannel excites me

2

BINARY TYPES IN JAVASCRIPT

Yes binary types exists:

ArrayBuffer

Blob

ArrayBufferView: Uint8Array, etc..

Page 3: Why WebRTC DataChannel excites me

3

WHY IS THIS COOL

Binary support means we can do anything we want with data

Page 4: Why WebRTC DataChannel excites me

4

BINARY TYPES IN JAVASCRIPT

Do these things with them:

URL.createObjectURL(blob)

XHR2

WebSocket

DataChannel

Page 5: Why WebRTC DataChannel excites me

5

BACK TO DATACHANNEL

Video and audio is pretty cool

But I’m excited about DataChannel because

Page 6: Why WebRTC DataChannel excites me

6

BACK TO DATACHANNEL

Arbitrary binary data between arbitrary people

That is a lot of power

No permissions. No flags.

Page 7: Why WebRTC DataChannel excites me

7

BUT WAIT THERES MORE

Based on UDP – essential when transmission delay matters

Configurable with SCTP, for TCP like reliability if you want

Page 8: Why WebRTC DataChannel excites me

8

WHAT I REALIZED

DataChannel fundamentally changes the web.

Data has always flowed between server and client.

DataChannel allows client to client flow

Page 9: Why WebRTC DataChannel excites me

9

THE POSSIBILITIES

File transfer

Faster

No privacy issues

No bandwidth costs

Page 10: Why WebRTC DataChannel excites me

10

THE POSSIBILITIES

Multiplayer games

Substantially higher performance because of lower UDP latency + binary data

Page 11: Why WebRTC DataChannel excites me

11

THE POSSIBILITIES

High frequency events and messaging

Higher message rates possible with UDP based transport

Page 12: Why WebRTC DataChannel excites me

12

PRIVACY

Imagine a decentralized Facebook

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

Seamless experience

Page 13: Why WebRTC DataChannel excites me

13

DATACHANNELCHALLENGES

Page 14: Why WebRTC DataChannel excites me

14

BROWSER COMPATIBILITY

Google Chrome - March 7th 2013

GOODGOODGOODBAD

No SCTP implementation = No binary, reliableNot coming until later in 27

Page 15: Why WebRTC DataChannel excites me

15

BROWSER COMPATIBILITY

Firefox – March 7th 2013

Nightly 22.0a1 - Several spec issues being fixed RIGHT NOWBug 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

Page 16: Why WebRTC DataChannel excites me

16

BROWSER COMPATIBILITY

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

Page 17: Why WebRTC DataChannel excites me

17

PROBLEM: JSON

I now have a binary DataChannel between two browsers.

I want to send some binary data.

Page 18: Why WebRTC DataChannel excites me

18

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 });

Page 19: Why WebRTC DataChannel excites me

19

PROBLEM: JSON

Our DataChannel supports binary, why use string serialization at all?

Binary serialization options:

MsgPack, Thrift, Avro, BSON, ProtoBufs, BERT, and many more

Page 20: Why WebRTC DataChannel excites me

20

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.

Page 21: Why WebRTC DataChannel excites me

21

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

Page 22: Why WebRTC DataChannel excites me

22

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.

Page 23: Why WebRTC DataChannel excites me

23

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 pagehttps://code.google.com/p/libjingle/wiki/FAQ

Page 24: Why WebRTC DataChannel excites me

24

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.

Page 25: Why WebRTC DataChannel excites me

25

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.

Page 26: Why WebRTC DataChannel excites me

26

WEBRTC IS SUPER HAPPENINGGUARANTEED

Page 27: Why WebRTC DataChannel excites me

27

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.

Page 28: Why WebRTC DataChannel excites me

28

THIS IS CRAZY

The model of the web can fundamentally change

Page 29: Why WebRTC DataChannel excites me

29

THIS IS CRAZY

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

Page 30: Why WebRTC DataChannel excites me

30

THIS IS CRAZY

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

Page 31: Why WebRTC DataChannel excites me

31

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.

Page 32: Why WebRTC DataChannel excites me

32

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.

Page 33: Why WebRTC DataChannel excites me

33

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.

Page 34: Why WebRTC DataChannel excites me

34

THIS IS CRAZY

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

http://peerkit.com

Page 35: Why WebRTC DataChannel excites me

35

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.

Page 36: Why WebRTC DataChannel excites me

36

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.