RailsConf Europe 2008 Juggernaut Realtime Rails Alex MacCaw and Stuart Eccles
RailsConf Europe 2008 Juggernaut Realtime Rails Alex MacCaw and Stuart Eccles
http://www.madebymany.co.uk/
server push
HTTP HTTP GET/POST <html/> <script/> Client Server
Server Push Client Server
what is Juggernaut?
History Written by Alex MacCaw in 2006 Published at http://juggernaut.rubyforge.org/ Latest versions at GitHub just for Edge Rails MIT License
3 Components Invisible Juggernaut Rails Plugin Flash SWF Server Client Messenger Broadcaster
Juggernaut is also
This guy.... what do we want?
This guy.... what do we want?
X-Men Character
X-Men Character
the other Juggernaut?
real world users
Collaboration
Real Time Interaction
Multiplayer Games
Multiplayer Games
Chat
Real Time Activity Feeds
Enhancing Traditional Media
juggernaut competition
r e s o u i n r c t e e n s i v e
r e s o u i n r c t e e n s i v e not realtime
F i r e f m o x e m o i r s y s u e s
F i r e f m o x e m o i r s y s u e s not cross- domain
F i r e f m o x e m o i r s y s u e s IE clicking not cross- domain
F i r e f m o x e m max 2 o i r s y s u streams in e s IE IE clicking not cross- domain
features browser compatibility Flash 8 > 95% of all browsers cross-OS Prototype and JQuery versions
features scale with eventmachine 30k concurrent users and clustering support
features channels client can subscribe to one or more channels Broadcast can be channel selected Broadcast can even be client selected
features authentication IP whitelist shared secrets authentication callbacks
features callbacks client connect callback client disconnect callback
features queries query server for list of clients
in pictures
Rails Application Juggernaut Rails Plugin Juggernaut Push Server
Rails Application Juggernaut Rails Plugin Juggernaut Push Server
GET Rails Application Juggernaut Rails Plugin Juggernaut Push Server
OK Rails Application Juggernaut Rails Plugin Juggernaut Push Server
SUBSCRIBE Rails Application Juggernaut Rails Plugin Juggernaut Push Server
Rails Application DUPLEX Juggernaut Rails Plugin Juggernaut Push Server
Rails Application DUPLEX Juggernaut Rails Plugin callback Juggernaut Push Server
Rails Application DUPLEX Juggernaut Rails Plugin SUBSCRIBE Juggernaut Push Server
Rails Application DUPLEX Juggernaut Rails Plugin callback DUPLEX Juggernaut Push Server
Rails Application RJS DUPLEX Juggernaut Rails Plugin JSON MESSAGE DUPLEX Juggernaut Push Server
Rails Application DUPLEX Juggernaut Rails Plugin S J DUPLEX Juggernaut Push Server
S J Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server
Wonder-women has entered chat Rails Application DUPLEX Juggernaut Rails Plugin S J DUPLEX Juggernaut Push Server
Wonder-women has entered chat S J Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server
Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server
Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
AJAX Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
Rails Application RJS DUPLEX Juggernaut Rails Plugin JSON MESSAGE DUPLEX Juggernaut Push Server DUPLEX
Rails Application DUPLEX Juggernaut Rails Plugin S J DUPLEX S Juggernaut Push J Server S J DUPLEX
Rails Application DUPLEX Juggernaut Rails Plugin S J DUPLEX S Juggernaut Push J Server S J DUPLEX
Rails Application DUPLEX Juggernaut Rails Plugin S J S J DUPLEX Juggernaut Push Server S J DUPLEX
S J Rails Application DUPLEX Juggernaut Rails Plugin S J DUPLEX Juggernaut Push Server S J DUPLEX
SuperMan says ‘Hi!’ Rails Application SuperMan says ‘Hi!’ DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push SuperMan says ‘Hi!’ Server DUPLEX
Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
RAKE Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
Rails Application RJS DUPLEX Juggernaut Rails Plugin JSON MESSAGE DUPLEX Juggernaut Push Server DUPLEX
Rails Application DUPLEX Juggernaut Rails Plugin S J DUPLEX S Juggernaut Push J Server S J DUPLEX
Rails Application DUPLEX Juggernaut Rails Plugin S J DUPLEX S Juggernaut Push J Server S J DUPLEX
Rails Application DUPLEX Juggernaut Rails Plugin S J S J DUPLEX Juggernaut Push Server S J DUPLEX
S J Rails Application DUPLEX Juggernaut Rails Plugin S J DUPLEX Juggernaut Push Server S J DUPLEX
Chat will be closing in 10 minutes! Rails Application Chat will be closing in 10 minutes! DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Chat will be closing in 10 minutes! Server DUPLEX
Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
notification Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
Rails Application Juggernaut Rails Plugin callback DUPLEX Juggernaut Push Server DUPLEX
Rails Application RJS Juggernaut Rails Plugin JSON MESSAGE DUPLEX Juggernaut Push Server DUPLEX
Rails Application Juggernaut Rails Plugin DUPLEX S Juggernaut Push J Server S J DUPLEX
Rails Application Juggernaut Rails Plugin DUPLEX S Juggernaut Push J Server S J DUPLEX
Rails Application Juggernaut Rails Plugin S J DUPLEX Juggernaut Push Server S J DUPLEX
Rails Application SuperMan has left the building! Juggernaut Rails Plugin DUPLEX Juggernaut Push SuperMan has left the building! Server DUPLEX
Audience Participation http://railsconf.madebymany.co.uk
def code
Partial Update Example
Install Juggernaut script/plugin install \ http://juggernaut.rubyforge.org/svn/trunk/juggernaut sudo gem install juggernaut (includes json and eventmachine dependencies)
Start the Push Server juggernaut -g juggernaut.yml juggernaut -c juggernaut.yml
View <html> <head> <%= javascript_include_tag :defaults, :juggernaut %> <%= juggernaut %> </head>
Controller render :juggernaut do |page| page.replace 'person-45', :partial => 'person' end
That’s it!
Demo 1: Chat
Subscribe to channels <%= juggernaut(:channels => ['one', 'two', 'three']) %>
Broadcast to channels render :juggernaut => { :type => :send_to_channels, :channels => ['one'] } do |page| page.alert('Hello World') end
Subscribe as a particular client <%= juggernaut(:client_id => current_user.id) %>
Broadcast to a particular client render :juggernaut => { :type => :send_to_client, :client_id => @user.id } do |page| page.alert('Hello World') end
Find connected clients Juggernaut.show_clients
Don’t want inline RJS? render_juggernaut('person_update.rjs')
Don’t Want RJS? Juggernaut.send_to_all(“alert(‘foo’);”) Juggernaut.send_to_client(“alert(‘foo’);”, @user.id) Juggernaut.send_to_channel(“alert(‘foo’);”, @channel)
Demo 2: Google Maps http://railsconf.madebymany.co.uk
tips
Don’t push huge amounts of HTML to the browser. Trigger an AJAX request instead Don’t push huge amounts of Javascript to the browser. Trigger a function call already loaded by the browser. In callbacks Juggernaut will pass the session id so you can use existing session information. Escape your user inputs!! XSS is very dangerous in a Push JavaScript world.
http://juggernaut.rubyforge.org/ Thank You! Q & A
Recommend
More recommend