56
RTW – WTF? Real Time Web – What’s That For? Makoto Inoue - Martyn Loughran Makoto

Real Time Web - What's that for?

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Real Time Web - What's that for?

RTW – WTF?Real Time Web – What’s That For?Makoto Inoue - Martyn Loughran

Makoto

Page 2: Real Time Web - What's that for?

Who are we?

Page 3: Real Time Web - What's that for?

RTWExciting

Page 4: Real Time Web - What's that for?
Page 5: Real Time Web - What's that for?

The big guys already do it

Google wave

Facebook live feed

Twitter

Page 6: Real Time Web - What's that for?

This is our story

Once upon a time...

Martyn

November 2009

Page 7: Real Time Web - What's that for?

Visualise web traffic

Rack

Existing app

Sinatra Stats Collector

Fancy Visualization

Page 8: Real Time Web - What's that for?
Page 9: Real Time Web - What's that for?

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?

WebSockets

http://www.flickr.com/photos/lenaah/2939721384/

Makoto

December 2009

Page 11: Real Time Web - What's that for?

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?

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?

Javascript API

Page 14: Real Time Web - What's that for?

Server Side

http://www.flickr.com/photos/lenaah/2939721384/

December 2009

Martyn

Page 15: Real Time Web - What's that for?

Fun problems

Concurrent

Stateful

Low latency (sometimes)

Page 16: Real Time Web - What's that for?

Asynchronous servers

Make all IO non-blocking

Single thread

Efficient CPU utilisation

Page 17: Real Time Web - What's that for?

Simple example

Page 18: Real Time Web - What's that for?

Other options

em-websocket

cramp

sunshowers

node.js (js)

Page 19: Real Time Web - What's that for?

http://github.com/markevans/websocket_test

Example: Drawing

Page 20: Real Time Web - What's that for?

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?

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?

Demo

Page 23: Real Time Web - What's that for?

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?

MandaysWork Schedule Management

Page 25: Real Time Web - What's that for?

TrueStoryBacklog Management

Page 26: Real Time Web - What's that for?

Data gets stale

People make conflicting changes

This discourages collaboration

Problems

Page 27: Real Time Web - What's that for?

Requirements

We didn’t want to re-write everything

Reusable by many apps

Really simple

Page 28: Real Time Web - What's that for?

Our solution

Page 29: Real Time Web - What's that for?

+

Page 30: Real Time Web - What's that for?
Page 31: Real Time Web - What's that for?
Page 32: Real Time Web - What's that for?
Page 33: Real Time Web - What's that for?
Page 34: Real Time Web - What's that for?
Page 35: Real Time Web - What's that for?

Look Ma

http://www.flickr.com/photos/jeremystockwell/2691931146/ February 2010

Page 36: Real Time Web - What's that for?
Page 37: Real Time Web - What's that for?
Page 38: Real Time Web - What's that for?

Case Study

Adding real time to TrueStory

Page 39: Real Time Web - What's that for?

Data Flow

Inspired by JS events

Trigger in on place

Bind in another

Page 40: Real Time Web - What's that for?

$('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?

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?

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?

Look MaMakoto

March 2010

Page 44: Real Time Web - What's that for?

Task Management Board

Page 45: Real Time Web - What's that for?
Page 46: Real Time Web - What's that for?

Debugging

Page 47: Real Time Web - What's that for?
Page 48: Real Time Web - What's that for?

Booking

Page 49: Real Time Web - What's that for?
Page 50: Real Time Web - What's that for?

Wife Notifier

Page 51: Real Time Web - What's that for?
Page 52: Real Time Web - What's that for?

http://www.flickr.com/photos/blueju38/2767019065/

Summary

Page 53: Real Time Web - What's that for?

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?

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?

One more thing...

Page 56: Real Time Web - What's that for?

http://pusherapp.com

Questions ?

Get hooked!