alex carcea, radu macovei a story of how java script joined the big league

35

Upload: codecampiasi

Post on 01-Jul-2015

56 views

Category:

Technology


2 download

DESCRIPTION

CodeCampIasi25Oct2014

TRANSCRIPT

Page 1: Alex carcea, radu macovei   a story of how java script joined the big league
Page 2: Alex carcea, radu macovei   a story of how java script joined the big league

WELCOME!

Page 3: Alex carcea, radu macovei   a story of how java script joined the big league
Page 4: Alex carcea, radu macovei   a story of how java script joined the big league

A STORY OF HOW JAVASCRIPT JOINED THE BIG LEAGUE:

WEBSOCKETSAND OTHER GOODIES

Created by Alexandru Carcea & Radu Macovei

Page 5: Alex carcea, radu macovei   a story of how java script joined the big league
Page 6: Alex carcea, radu macovei   a story of how java script joined the big league

A FEW WORDS ABOUT

JAVASCRIPT

Page 7: Alex carcea, radu macovei   a story of how java script joined the big league

HISTORYOF JAVASCRIPT

Page 8: Alex carcea, radu macovei   a story of how java script joined the big league
Page 9: Alex carcea, radu macovei   a story of how java script joined the big league

OBJECTS AND CLASSESIN JAVASCRIPT

Page 10: Alex carcea, radu macovei   a story of how java script joined the big league

DOM MANIPULATIONIN JAVASCRIPT

Page 11: Alex carcea, radu macovei   a story of how java script joined the big league

EVENTSIN JAVASCRIPT

Page 12: Alex carcea, radu macovei   a story of how java script joined the big league

REAL TIME WEBWHEN USERS ALMOST FORGOT ABOUT

REFRESHING WEB PAGES

Page 13: Alex carcea, radu macovei   a story of how java script joined the big league

HTTPTHE PROTOCOL THAT ENABLES THE WEB

AND ITS SHORTCOMINGS

Page 14: Alex carcea, radu macovei   a story of how java script joined the big league
Page 15: Alex carcea, radu macovei   a story of how java script joined the big league

ALMOST REAL TIMEHACKS TO SIMULATE REAL TIME WEB

Page 16: Alex carcea, radu macovei   a story of how java script joined the big league

XMLHTTPREQUESTAND AJAX

RETRIEVING DATA WITHOUT FULL PAGE REFRESH

Page 17: Alex carcea, radu macovei   a story of how java script joined the big league

POLLING AND

LONG POLLINGTRYING TO ACHIEVE REAL TIME

Page 18: Alex carcea, radu macovei   a story of how java script joined the big league

WEBSOCKETSTHE PROTOCOL THAT PROVIDES REAL TIME, FULL-DUPLEX

COMMUNICATION

Page 19: Alex carcea, radu macovei   a story of how java script joined the big league
Page 20: Alex carcea, radu macovei   a story of how java script joined the big league

WS VS HTTPGETTING RID OF HEADERS THAT ARE NOT NEEDED

Page 21: Alex carcea, radu macovei   a story of how java script joined the big league

TMI! TMFI!GET / HTTP/1.1Host: www.example.comConnection: keep‐aliveAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8User‐Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2194.2 Safari/537.36Accept‐Encoding: gzip, deflate, sdchAccept‐Language: ro‐RO,ro;q=0.8,en‐US;q=0.6,en;q=0.4X‐Custom‐Headers: Whoa, overhead!

Page 22: Alex carcea, radu macovei   a story of how java script joined the big league

... AND THIS HAPPENSEVERY SINGLE TIME!

HTTP/1.1 200 OKAccept‐Ranges: bytesCache‐Control: max‐age=604800Content‐Type: text/htmlDate: Thu, 15 Jan 1970 00:00:00 GMTEtag: "359670651"Expires: Sat, 31 Jan 1970 00:00:00 GMTLast‐Modified: Thu, 01 Jan 1970 00:00:00 GMTServer: ApacheContent‐Length: 51

Hello World! My payload includes a trailing CRLF.

Page 23: Alex carcea, radu macovei   a story of how java script joined the big league

LET'S TRY WITHWEBSOCKETS

GET /chat HTTP/1.1Host: server.example.comUpgrade: websocketConnection: UpgradeSec‐WebSocket‐Key: x3JJHMbDL1EzLkh9GBhXDw==Sec‐WebSocket‐Protocol: chat, superchatSec‐WebSocket‐Version: 13Origin: http://example.com

Page 24: Alex carcea, radu macovei   a story of how java script joined the big league

THAT'S BETTER...HTTP/1.1 101 Switching ProtocolsUpgrade: websocketConnection: UpgradeSec‐WebSocket‐Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=Sec‐WebSocket‐Protocol: chat

Page 25: Alex carcea, radu macovei   a story of how java script joined the big league

JAVASCRIPTWEBSOCKETS

CLIENT APIWRITE WEBSOCKET CLIENT APPLICATIONS USING

WEBSOCKET CLASS

Page 26: Alex carcea, radu macovei   a story of how java script joined the big league

WEBSOCKET APIEVENTS

1. open2. message3. close4. error

Page 27: Alex carcea, radu macovei   a story of how java script joined the big league

WEBSOCKET APIMETHODS1. send(data)2. close()

Page 28: Alex carcea, radu macovei   a story of how java script joined the big league

WEBSOCKET APIif ("WebSocket" in window) {  // WebSocket is supported  var ws = new WebSocket("[ws|wss]://[host]:[port]/[uri]", [protocol(s)]);  ws.onopen = function (event) { ... };  ws.onmessage = function (event) { ... };  ws.onclose = function (event) { ... };  ws.onerror = function (event) { ... };    ws.send(data);  // ws.close(); when finished} else {  // WebSocket NOT supported}

Page 30: Alex carcea, radu macovei   a story of how java script joined the big league

USES FOR WEBSOCKETSSocial feedsMultiplayer gamesCollaborative toolsFinancial appsSports apps... and many more ...

Page 31: Alex carcea, radu macovei   a story of how java script joined the big league

A SMALL WEBSOCKETS

DEMO

Page 32: Alex carcea, radu macovei   a story of how java script joined the big league

USING NODE.JS AND SOCKET.IO

Page 33: Alex carcea, radu macovei   a story of how java script joined the big league
Page 34: Alex carcea, radu macovei   a story of how java script joined the big league

Q&A

Page 35: Alex carcea, radu macovei   a story of how java script joined the big league

THANK YOU!