Slide 1

Slide 1 text

WebRTC Basic & Workshop 2013.10.11 INFOCOM CORPORATION https://www.infocom.co.jp/english/aboutus/group/index.html [email protected] 1

Slide 2

Slide 2 text

References • This document is referring following web sites. – WebRTC official site • http://www.webrtc.org/ – HTML5 ROCKS • http://www.html5rocks.com/en/tutorials/webrtc/basics/ – WebRTC for Beginners Muaz Khan • https://www.webrtc-experiment.com/docs/webrtc-for-beginners.html • https://github.com/muaz-khan/WebRTC-Experiment – WebRTC Conference 2013 Atlanta • http://www.webrtcworld.com/conference/west/default.aspx • http://images.tmcnet.com/expo/webrtc- conference/pdfs/WebRTC%20SG13AtlantaRe-CapSml.pdf – And so many blogs. • All rights of each product is reserved by original right holder. – ®, TM are omitted. 2

Slide 3

Slide 3 text

What’s WebRTC • Web Real-Time Communication – Frameworks for realizing Real-Time Communication on Web Browser – A Part of HTML5 • Many technologies are combined – Do you know what are included? 3

Slide 4

Slide 4 text

WebRTC elements • User Media – Camera – Microphone – Screen capture • Stream (MediaStream) • P2P communication (RTCPeerConnection) • Data transfer (DataChannel) • Related API, HTML features – JavaScript (most important) – Video, Audio – WebScoket – WebAudio API – Canvas – WebGL – …, etc. 4

Slide 5

Slide 5 text

WebRTC ready browsers • Windows / Mac – Chrome 26 - (Camera, microphone. Configuration for screen capture) – FireFox 22 - (Camera, microphone. NO screen capture) – Opera 15 - (Camera, microphone. NO screen capture) *different prefix for JavaScript Chrome: webkit, FireFox: moz • Android – Chrome 29 - (Camera, microphone. NO screen capture) • iOS – Not supported yet – Google says, it is on progress. coming soon. • At WebRTC Conference 2013 Atlanta • * I hope it will be include in Chrome for iOS near future. 5

Slide 6

Slide 6 text

Why so interested in WebRTC? Because WebRTC is disruptive. Career fixed telephone mobile phone (TV broadcast) method Over The Top Skype, WebEx (YouTube, USTREAM) Web Browser WebRTC can speak to world- wide (with cost) for users can speak to world- wide with low cost no application, free to use only careers with infrastructure can participate market independent of careers, few venders can participate without special infrastructure, everyone can participate none for venders limited API, limited combination fully programmable, use as component single use usage user can combine built in to products / services call center, e-commerce, information site, etc.

Slide 7

Slide 7 text

Combination VS. Built in Combination  making estimate sheet with WORD and Calculator Total: 568,900 Automatic calculation Built in  making estimate sheet with EXCEL Total: 568,900 Calculate sum by hand, and type into WORD by hand

Slide 8

Slide 8 text

Media 8

Slide 9

Slide 9 text

Let’s try with Chrome • Prepare – OS: Windows, Mac OS X – Browser:Chrome 26 or later – Web cam, microphone – editor app, as you like • Contents – Handling User Media – Handling stream 9

Slide 10

Slide 10 text

Self camera (for Chrome) WebRTC Camera var video1 = document.getElementById('video1'); navigator.webkitGetUserMedia({audio:false, video:true}, function(stream) { // success video1.src = window.webkitURL.createObjectURL(stream); }, function(err) { // error console.log(err); } ); 10

Slide 11

Slide 11 text

Goal 11

Slide 12

Slide 12 text

Try in local machine (file:// ) • Nothing must be shown • Watch JavaScript console … – NavigatorUserMediaError {code: 1, PERMISSION_DENIED: 1} … – PERMISSION ERROR • Local HTML (file://) can not access to User Media •  So, please put it into your Web Server – Apache, nginx, IIS, as you like. 12

Slide 13

Slide 13 text

Goal, again 13

Slide 14

Slide 14 text

Sepia camera WebRTC Camera var video1 = document.getElementById('video1'); navigator.webkitGetUserMedia({audio:false, video:true}, function(stream) { // success video1.src = window.webkitURL.createObjectURL(stream); }, function(err) { // error console.log(err); } ); 14

Slide 15

Slide 15 text

Goal 15

Slide 16

Slide 16 text

Mirror Camera WebRTC Camera var video1 = document.getElementById('video1'); var video2 = document.getElementById('video2'); navigator.webkitGetUserMedia({audio:false, video:true}, function(stream) { // success video1.src = window.webkitURL.createObjectURL(stream); video2.src = window.webkitURL.createObjectURL(stream); }, function(err) { // error console.log(err); } ); 16

Slide 17

Slide 17 text

Goal 17

Slide 18

Slide 18 text

Other variations Thin camera Heavy camera Hang down camera Black and White Lean camera 18

Slide 19

Slide 19 text

2 video tag and MediaStream (in mirror camera) 19 1 MediaStream can connect to several outputs. MediaStream : output = 1 : n

Slide 20

Slide 20 text

Howling WebRTC Camera var video1 = document.getElementById('video1'); navigator.webkitGetUserMedia({audio:true, video:true}, function(stream) { // success video1.src = window.webkitURL.createObjectURL(stream); }, function(err) { // error console.log(err); } ); 20

Slide 21

Slide 21 text

How howling happens (local) 21 Most of samples are implemented like this  Headphone is necessary

Slide 22

Slide 22 text

summary • User Media (microphone, camera) – navigator.webkitGetUserMedia( {audio:true, video:true}, … • User Media (Screen Capture) – navigator.webkitGetUserMedia( video : { mandatory : { chromeMediaSource : "screen" } }, • Security (Access permission) • Media Stream – MediaStream (video, audio) 22

Slide 23

Slide 23 text

WebRTC Security Access permission 23

Slide 24

Slide 24 text

Media layer 24

Slide 25

Slide 25 text

Communication 25

Slide 26

Slide 26 text

Communication • RTCPeerConnection – Transfer root for MediaStream ( video and audio ) – P2P (Peer to Peer)  browser to browser – use UDP/IP 26 RTCPeerConnection RTCPeerConnection UDP/IP

Slide 27

Slide 27 text

Before starting P2P communication • Have to know IP address of each other • Have to know UPD port number to use – UDP port is decided dynamically • Negotiation process is necessary, before RTCPeerConnection communication – This process is called as “Signaling” 27 RTCPeerConnection RTCPeerConnection UDP/IP IP address of each other UDP port number to use

Slide 28

Slide 28 text

Signaling before P2P • Broker is needed, which is known by both browser – → Signaling server is prepared usually • No standard of signaling protocol – Your own way • WebSocket (TCP/IP) • Ajax (HTTP, HTTPS) – Existing protocol • SIP(for VoIP) with WebSocket(TCP/IP) • XMPP(for IM)with WebSocket(TCP/IP) 28

Slide 29

Slide 29 text

Exchanged information while signaling • Session Description Protocol (SDP) – Information of session contents, such as media type (video, audio), codec, etc. – IP address, port number – P2P data transfer protocol → Secure RTP is used in WebRTC – Band width – Session property (name, id, active time, etc.) • Interactive Connectivity Establishment (ICE) – Lists of possible transfer roots • Direct P2P • Using STUN to go through NAT port mapping • Using TRUN, with packet relay server – Shortest (less hop) root will be chosen 29

Slide 30

Slide 30 text

Direct P2p in same network 30 Dynamic UDP port (50000~65535)

Slide 31

Slide 31 text

IP addr / UDP port exchange via STUN Then P2P over NAT 31

Slide 32

Slide 32 text

Packet relay via TURN server (go through Firewall) 32

Slide 33

Slide 33 text

Sequence before P2P (1) with WebSocket 33 PeerConnection socket Application Signaling Server PeerConnection socket Application connect() connect connect() connect createOffer() offer sdp setLocalDescription(sdp) send(sdp) send sdp send sdp onMessage(sdp) setRemoteDescription(sdp) createAnswer() answer sdp send sdp send(sdp) send sdp onMessage(sdp) setRemoteDescription(sdp) setLocalDescription(sdp)

Slide 34

Slide 34 text

Sequence before P2P (2) with WebSocket 34 PeerConnection socket Application Signaling Server PeerConnection socket Application onIceCandidate(ice) send(ice) send ice send ice onMessage(ice) addIceCandidate(ice) send ice send(ice) send ice onMessage(ice) addIceCandidate(ice) onIceCandidate(ice) onIceCandidate() : end of candidate onIceCandidate() : end of candidate P2P stream transfer At last, P2P starts.

Slide 35

Slide 35 text

Advantage / disadvantage of P2P • Advantage – No server transfer, no overhead – Without high spec sever • Disadvantage – Communication path glows exponentially, for many participants • 2 node → 1 path • 3 node → 3 path • 4 node → 6 path • 5 node → 10 path • 6 node → 15 path 35 P2P Server-client P2P for 4 Server-client for 4

Slide 36

Slide 36 text

WebRTC communication types • bidirectional communication – 1 to 1 audio – 1 to 1 video (& audio) – 1 to 1 screen capture (& audio) – n to n audio – n to n video (& audio) – n to n screen capture (& audio) 36

Slide 37

Slide 37 text

WebRTC communication types • one-way communication – 1 → 1 audio – 1 → 1 video (& audio) – 1 → 1 screen capture (& audio) – 1 → n audio – 1 → n video (& audio) – 1 → n screen capture (& audio) 37

Slide 38

Slide 38 text

WebRTC communication types • standalone – microphone capture → speaker – camera capture → view in screen – screen capture – audio recording – video recording – Image capture (with Canvas) 38

Slide 39

Slide 39 text

WebRTC class relation 39

Slide 40

Slide 40 text

Howling prevention (local) 40 It seems to work…

Slide 41

Slide 41 text

…still happens with partner Howling with partner 41 Auto mute, or auto band filter should be needed. Is it possible in JavaScript? (I don’t know)

Slide 42

Slide 42 text

Screen capture & audio 42 2 MediaStream into 1 PeerConnection

Slide 43

Slide 43 text

Data transfer (DataChannel) • Data transfer over RTCPeerConnection • Using UDP/IP, so packet may be lost – → DataChannel has retry feature (not packet, but whole data) • Events of onOpen, onClose, onMessage • For text chat, file transfer, game • DataChannel VS. WebScoket – DataChannel is P2P, WebSocket is server-client – DataChannel is UDP/IP, WebSocket is TCP/IP • Specification is not determined yet. 43

Slide 44

Slide 44 text

Conclusion • WebRTC is powerful – Expand web browser potential. Camera, microphone, screen capture. – Combination with other HTML5 features • Canvas, CSS, WebAudio API, WebGL • WebRTC is flexible – Local, 1 to 1, n to n – Bidirectional, single-way • WebRTC is disruptive – Any one can participate • WebRTC is programmable – Built into your own products / services 44

Slide 45

Slide 45 text

WebRTC has no limit. Your imagination will define limit. END 45