webrtc - open source day€¦ · webrtc plug-in free real-time communication … webrtc is a free,...

53
WebRTC ... GWT & in-browser computation Alberto Mancini - [email protected] Francesca Tosi - [email protected]

Upload: others

Post on 14-May-2020

23 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC... GWT & in-browser computation

Alberto Mancini - [email protected]

Francesca Tosi - [email protected]

Page 2: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTCPlug-in free real-time communication …

WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities via simple Javascript APIs.

source: webrtc.org

Page 3: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTCJust another JS API

or

WebRTC is a new front in the long war for an open and unencumbered webBrendan Eich (Mozilla CTO and inventor of JavaScript)

?

Page 4: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTCJust another JS API

or

WebRTC is a new front in the long war for an open and unencumbered webBrendan Eich (Mozilla CTO and inventor of JavaScript)

?

Page 5: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

Once upon a time … browsers

(js-)applications were sandboxed and kept far away from the hosting computer’s resources.

Page 6: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

Once upon a time … browsers

(js-)applications were sandboxed and kept far away from the hosting computer’s resources.

Page 7: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

Browser Piercing (aka HTML5) a Javascript Application cannot

➔ access the filesystem

➔ open f/d socket connections

➔ use graphics accelerator

➔ span multiple threads

Page 8: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

Browser Piercing (aka HTML5) a Javascript Application cannot

➔ access the filesystem → and then FileAPI

➔ open f/d socket connections → and then WebSockets

➔ use graphics accelerator → and then WebGL

➔ span multiple threads → and then WebWorkers

Page 9: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

Browser Piercing

a Javascript Application cannot

➔ acquire audio and video

➔ communicate P2P

Page 10: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

Browser Piercing

a Javascript Application cannot

➔ acquire audio and video

➔ communicate P2P

Page 11: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC … secure enough?

“… WebRTC has encryption baked right into it; there's actually no way to send unencrypted media using a WebRTC implementation … both Chrome and Firefox implement.”

Page 12: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC … secure enough?But ...

“If the developers fail to carefully consider the security implications of their choices, the safeguards mandated by the specification will not be enough to guarantee the security of their WebRTC-based applications and the users.”

Page 13: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC … secure enough?Do not ...

“... it would be very easy to inadvertently click on something that gave camera or microphone control to someone I don't know and don't care to know.”

Courtney Sato - nerd queen @ConstellationRG

Page 15: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC across platforms● Chrome (mobile too)● Firefox (mobile too)● Opera● Native Java and Obj-C

Page 16: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC JS-API

Some code …

Page 17: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC JS-APIAcquiring video and audio

navigator.getUserMedia(constraints,

successCallback,

errorCallback);

Page 18: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC JS-APIAcquiring video and audio

navigator.getUserMedia(constraints, successCallback,

errorCallback);

Page 19: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC JS-APIConstraints

● Controls the contents of the MediaStream● Media type, resolution, frame rate

var constraints = {video: true};

video: { mandatory: { ... }, optional [{... }]}

Page 20: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC JS-APIConstraints

● Controls the contents of the MediaStream● Media type, resolution, frame rate

var constraints = {video: true};

video: { mandatory: { chromeMediaSource: ‘screen’ }, optional [{... }]}

Page 21: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC JS-APIAcquiring video and audio

navigator.getUserMedia(constraints,

successCallback,

errorCallback);

Page 22: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC JS-APIerrorCallback

function errorCallback(error) { console.log("error: ", error);}

;-)

Page 23: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC JS-APIAcquiring video and audio

navigator.getUserMedia(constraints,

successCallback,errorCallback);

Page 24: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC JS-APIsuccessCallback

function successCallback(stream) { ...}

stream: MediaStream; a flux of audio- or video-related data.

Page 25: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC JS-APIsuccessCallback

function successCallback(stream) { var video = ... video.src =

window.URL.createObjectURL(stream);

}

(W3C File API)

Page 26: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC JS-APIfull sample

var constraints = {video: true};

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

function errorCallback(error) { console.log("navigator.getUserMedia error: ", error);}

navigator.getUserMedia(constraints, successCallback, errorCallback);

Page 27: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC JS-APILive Demo - 1

http://goo.gl/7X91Ie

Page 28: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC JS-APIRTCPeerConnection

→getUserMedia

+RTCPeerConnection

Page 29: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

WebRTC JS-APIRTCDataChannel

Bidirectional communication of arbitrary data

var position = {x: 3.0, y: -2.0};

...var message = {txt: ‘...’, timestamp: ...};

Page 30: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

RTCPeerConnection samplepc = new RTCPeerConnection(null);pc.onaddstream = gotRemoteStream;pc.addStream(localStream);pc.createOffer(gotOffer);

function gotOffer(desc) { pc.setLocalDescription(desc); sendOffer(desc);}

function gotAnswer(desc) { pc.setRemoteDescription(desc);}

function gotRemoteStream(e) { attachMediaStream(remoteVideo, e.stream);}

Page 31: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

RTCPeerConnection

Live Demo - 2

https://apprtc.appspot.com

Page 32: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

RTCPeerConnection

Page 33: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

RTCPeerConnection

Page 34: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

RTCPeerConnection

Page 35: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

STUN

Page 36: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

TURN

Page 38: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

Our target

Page 39: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

Our target

● getUserMedia: gives us real time stream from the camera

● we can draw the <video/> into a <canvas/>

● from the canvas we can extract pixel data getImageData()

and then elaborate.

Page 40: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

Computing in the browsergoals- Almost native performance- Manage complex algorithms and applications on the browser

Page 41: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

Our target

cam WebRTC <video/> canvas ImageData

UInt8ArrayGWT(NyARToolkit)mv matrix

WebGL OBJ Model Loader3D Shaders

WebGL video

effects

Video

Page 42: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

Computing in the browserconstraints- reuse existing code- cross-browser (as much as possible)

Page 43: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

Computing in the browserour approach- javascript as a target language (GWT) - hand written optimized pieces of code

Page 44: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

GWTGWT Web Toolkit

- java to javascript (optimizing) compiler- emulated jre- widget set

- develop in java and execute in javascript

Page 45: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

JooinK’s WebRTC sample

Sample

http://picshare.jooink.com

Demo …

Page 46: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

PicShareTecnologies

● WebGL for 3D graphics● WebRTC for MediaSteams● ImgUR for pictures store● AppEngine to store indices

● GWT as the glue

Page 48: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

What’s nextChallanges

● real-time on mobile apps● real world recognition: computer vision

(BoofCV)

Page 49: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

What’s nextStrategy

● use TypedArrays everywhere ● offload computation to the graphic

accelerator through WebGL● help the JIT compiler/optimizer with asm.js

Page 50: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

References

● http://io13webrtc.appspot.com/#1(where we got inspiration and most of the pictures)

● http://www.youtube.com/watch?v=p2HzZkd2A40● http://www.webrtc.org (spec)

Page 51: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

References

● http://www.jooink.com

● http://jooink.blogspot.com

● http://www.mokabyte.it

Page 52: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

That’s all folks!!!

Francesca [email protected]

Alberto [email protected]

Page 53: WebRTC - Open Source Day€¦ · WebRTC Plug-in free real-time communication … WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities

Markers - use at picshare.jooink.com