Download - Real Time Web - What's that for?
![Page 1: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/1.jpg)
RTW – WTF?Real Time Web – What’s That For?Makoto Inoue - Martyn Loughran
Makoto
![Page 2: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/2.jpg)
Who are we?
![Page 3: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/3.jpg)
RTWExciting
![Page 4: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/4.jpg)
![Page 5: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/5.jpg)
The big guys already do it
Google wave
Facebook live feed
![Page 6: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/6.jpg)
This is our story
Once upon a time...
Martyn
November 2009
![Page 7: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/7.jpg)
Visualise web traffic
Rack
Existing app
Sinatra Stats Collector
Fancy Visualization
![Page 8: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/8.jpg)
![Page 9: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/9.jpg)
Nginx HTTP_Push_Module
Long polling
Push handled by separate component
Worked, but fiddly to setup
Under the hood
![Page 10: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/10.jpg)
WebSockets
http://www.flickr.com/photos/lenaah/2939721384/
Makoto
December 2009
![Page 11: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/11.jpg)
WebSockets
HTML5 sub standard
Allows Socket in the browser
Now supported in the ‘non-shite’ browsers
Chrome & Webkit (nightly)
There is a library for flash emulation
![Page 12: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/12.jpg)
Ajax vs Comet vs WebSocket
Ajax(Polling)
Comet(Long polling)
WebSocket
Client
Server
Client
Client
Server
Server
![Page 13: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/13.jpg)
Javascript API
![Page 14: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/14.jpg)
Server Side
http://www.flickr.com/photos/lenaah/2939721384/
December 2009
Martyn
![Page 15: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/15.jpg)
Fun problems
Concurrent
Stateful
Low latency (sometimes)
![Page 16: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/16.jpg)
Asynchronous servers
Make all IO non-blocking
Single thread
Efficient CPU utilisation
![Page 17: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/17.jpg)
Simple example
![Page 18: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/18.jpg)
Other options
em-websocket
cramp
sunshowers
node.js (js)
![Page 19: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/19.jpg)
http://github.com/markevans/websocket_test
Example: Drawing
![Page 20: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/20.jpg)
class Connection class << self def add(websocket) connections << websocket end def all connections end def remove(websocket) connections.delete(websocket) end private def connections @connections ||= [] end endend
Keep connection objects in memory
![Page 21: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/21.jpg)
EventMachine.run { EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 3001) do |ws| ws.onopen { puts "WebSocket connection open" Connection.add(ws) }
ws.onclose { Connection.remove(ws) } ws.onmessage { |data| Connection.all.each do |ws| ws.send(data) unless ws == self end } end }
![Page 22: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/22.jpg)
Demo
![Page 23: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/23.jpg)
We wanted to add it to everything
http://www.flickr.com/photos/10737604@N02/1673136876/
January 2010
![Page 24: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/24.jpg)
MandaysWork Schedule Management
![Page 25: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/25.jpg)
TrueStoryBacklog Management
![Page 26: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/26.jpg)
Data gets stale
People make conflicting changes
This discourages collaboration
Problems
![Page 27: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/27.jpg)
Requirements
We didn’t want to re-write everything
Reusable by many apps
Really simple
![Page 28: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/28.jpg)
Our solution
![Page 29: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/29.jpg)
+
![Page 30: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/30.jpg)
![Page 31: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/31.jpg)
![Page 32: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/32.jpg)
![Page 33: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/33.jpg)
![Page 34: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/34.jpg)
![Page 35: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/35.jpg)
Look Ma
http://www.flickr.com/photos/jeremystockwell/2691931146/ February 2010
![Page 36: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/36.jpg)
![Page 37: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/37.jpg)
![Page 38: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/38.jpg)
Case Study
Adding real time to TrueStory
![Page 39: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/39.jpg)
Data Flow
Inspired by JS events
Trigger in on place
Bind in another
![Page 40: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/40.jpg)
$('form#sprint').submit(function(){ var url = $(this).attr('action'); var data = $(this).serialize(); $.ajax({ url: url, data: data });});
def create @sprint = Sprint.new(params) @sprint.save
Pusher['project-1'].trigger('sprints-create', @sprint.attributes)end
pusher.bind('sprints-create', function(attributes) {addSprint(attributes);
})
![Page 41: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/41.jpg)
Stateful client
http://github.com/benpickles/js-model
In memory object client side
Asynchronous persistence (e.g. to a REST API)
Used on TrueStory - let me show you
![Page 42: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/42.jpg)
var sprint = new Sprint( { name: "My Sprint Name" });sprint.save();
def create @sprint = Sprint.new(params) @sprint.save
Pusher['project-1'].trigger('sprints-create', @sprint.attributes) respond_to do |format| format.js { render :json => @sprint.to_json } endend
pusher.bind('sprints-create', function(attributes) { var sprint = new Sprint(attributes); Sprint.add(sprint);})
![Page 43: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/43.jpg)
Look MaMakoto
March 2010
![Page 44: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/44.jpg)
Task Management Board
![Page 45: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/45.jpg)
![Page 46: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/46.jpg)
Debugging
![Page 47: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/47.jpg)
![Page 48: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/48.jpg)
Booking
![Page 49: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/49.jpg)
![Page 50: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/50.jpg)
Wife Notifier
![Page 51: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/51.jpg)
![Page 52: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/52.jpg)
http://www.flickr.com/photos/blueju38/2767019065/
Summary
![Page 53: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/53.jpg)
RTW (our take)
More than just chat
Another layer of progressive enhancement
Work well with other HTML5 features
![Page 54: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/54.jpg)
ResourcesWebSockets
• http://dev.w3.org/html5/websockets
• http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75
• http://blog.new-bamboo.co.uk/2009/12/30/brain-dump-of-real-time-web-rtw-and-websocket
Javascript (Client side)• http://blog.new-bamboo.co.uk/2010/2/10/json-event-based-convention-websockets
• http://blog.new-bamboo.co.uk/2010/3/7/the-js-model-layer
Ruby (Server side)• http://github.com/igrigorik/em-websocket
• http://github.com/lifo/cramp
• http://rainbows.rubyforge.org/sunshowers
![Page 55: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/55.jpg)
One more thing...
![Page 56: Real Time Web - What's that for?](https://reader038.vdocuments.mx/reader038/viewer/2022110302/54749b07b4af9fa30a8b57b8/html5/thumbnails/56.jpg)
http://pusherapp.com
Questions ?
Get hooked!