RailsConf Europe 2008 Juggernaut Realtime Rails

1,156 views

Published on

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

RailsConf Europe 2008 Juggernaut Realtime Rails

  1. 1. RailsConf Europe 2008 Juggernaut Realtime Rails Alex MacCaw and Stuart Eccles
  2. 2. RailsConf Europe 2008 Juggernaut Realtime Rails Alex MacCaw and Stuart Eccles
  3. 3. http://www.madebymany.co.uk/
  4. 4. server push
  5. 5. HTTP HTTP GET/POST <html/> <script/> Client Server
  6. 6. Server Push Client Server
  7. 7. what is Juggernaut?
  8. 8. History Written by Alex MacCaw in 2006 Published at http://juggernaut.rubyforge.org/ Latest versions at GitHub just for Edge Rails MIT License
  9. 9. 3 Components Invisible Juggernaut Rails Plugin Flash SWF Server Client Messenger Broadcaster
  10. 10. Juggernaut is also
  11. 11. This guy.... what do we want?
  12. 12. This guy.... what do we want?
  13. 13. X-Men Character
  14. 14. X-Men Character
  15. 15. the other Juggernaut?
  16. 16. real world users
  17. 17. Collaboration
  18. 18. Real Time Interaction
  19. 19. Multiplayer Games
  20. 20. Multiplayer Games
  21. 21. Chat
  22. 22. Real Time Activity Feeds
  23. 23. Enhancing Traditional Media
  24. 24. juggernaut competition
  25. 25. res int ourc ens e ive
  26. 26. res int ourc ens e ive not realt ime
  27. 27. Fire me fox mo iss ry ues
  28. 28. Fire me fox mo iss ry ues not cro ss- dom ain
  29. 29. Fire me fox mo iss ry ues IE clic king not cro ss- dom ain
  30. 30. Fire me fox mo max 2 iss ry ues streams in IE IE clic king not cro ss- dom ain
  31. 31. features browser compatibility Flash 8 > 95% of all browsers cross-OS Prototype and JQuery versions
  32. 32. features scale with eventmachine 30k concurrent users and clustering support
  33. 33. features channels client can subscribe to one or more channels Broadcast can be channel selected Broadcast can even be client selected
  34. 34. features authentication IP whitelist shared secrets authentication callbacks
  35. 35. features callbacks client connect callback client disconnect callback
  36. 36. features queries query server for list of clients
  37. 37. in pictures
  38. 38. Rails Application Juggernaut Rails Plugin Juggernaut Push Server
  39. 39. Rails Application Juggernaut Rails Plugin Juggernaut Push Server
  40. 40. GET Rails Application Juggernaut Rails Plugin Juggernaut Push Server
  41. 41. OK Rails Application Juggernaut Rails Plugin Juggernaut Push Server
  42. 42. SUBSCRIBE Rails Application Juggernaut Rails Plugin Juggernaut Push Server
  43. 43. Rails Application DUPLEX Juggernaut Rails Plugin Juggernaut Push Server
  44. 44. Rails Application DUPLEX Juggernaut Rails Plugin callback Juggernaut Push Server
  45. 45. Rails Application DUPLEX Juggernaut Rails Plugin SUBSCRIBE Juggernaut Push Server
  46. 46. Rails Application DUPLEX Juggernaut Rails Plugin callback DUPLEX Juggernaut Push Server
  47. 47. Rails Application RJS DUPLEX Juggernaut Rails Plugin JSON MESSAGE DUPLEX Juggernaut Push Server
  48. 48. Rails Application DUPLEX Juggernaut Rails Plugin JS DUPLEX Juggernaut Push Server
  49. 49. JS Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server
  50. 50. Wonder-women has entered chat Rails Application DUPLEX Juggernaut Rails Plugin JS DUPLEX Juggernaut Push Server
  51. 51. Wonder-women has entered chat JS Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server
  52. 52. Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server
  53. 53. Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
  54. 54. AJAX Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
  55. 55. Rails Application RJS DUPLEX Juggernaut Rails Plugin JSON MESSAGE DUPLEX Juggernaut Push Server DUPLEX
  56. 56. Rails Application DUPLEX Juggernaut Rails Plugin JS DUPLEX Juggernaut Push JS Server JS DUPLEX
  57. 57. Rails Application DUPLEX Juggernaut Rails Plugin JS DUPLEX Juggernaut Push JS Server JS DUPLEX
  58. 58. Rails Application DUPLEX Juggernaut Rails Plugin JS JS DUPLEX Juggernaut Push Server JS DUPLEX
  59. 59. JS Rails Application DUPLEX Juggernaut Rails Plugin JS DUPLEX Juggernaut Push Server JS DUPLEX
  60. 60. SuperMan says ‘Hi!’ Rails Application SuperMan says ‘Hi!’ DUPLEX Juggernaut Rails Plugin DUPLEX SuperMan says ‘Hi!’ Juggernaut Push Server DUPLEX
  61. 61. Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
  62. 62. Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
  63. 63. RAKE Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
  64. 64. Rails Application RJS DUPLEX Juggernaut Rails Plugin JSON MESSAGE DUPLEX Juggernaut Push Server DUPLEX
  65. 65. Rails Application DUPLEX Juggernaut Rails Plugin JS DUPLEX Juggernaut Push JS Server JS DUPLEX
  66. 66. Rails Application DUPLEX Juggernaut Rails Plugin JS DUPLEX Juggernaut Push JS Server JS DUPLEX
  67. 67. Rails Application DUPLEX Juggernaut Rails Plugin JS JS DUPLEX Juggernaut Push Server JS DUPLEX
  68. 68. JS Rails Application DUPLEX Juggernaut Rails Plugin JS DUPLEX Juggernaut Push Server JS DUPLEX
  69. 69. Chat will be closing in 10 minutes! Rails Application Chat will be closing in 10 minutes! DUPLEX Juggernaut Rails Plugin DUPLEX Chat will be closing in 10 minutes! Juggernaut Push Server DUPLEX
  70. 70. Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
  71. 71. Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
  72. 72. notification Rails Application DUPLEX Juggernaut Rails Plugin DUPLEX Juggernaut Push Server DUPLEX
  73. 73. Rails Application Juggernaut Rails Plugin callback DUPLEX Juggernaut Push Server DUPLEX
  74. 74. Rails Application RJS Juggernaut Rails Plugin JSON MESSAGE DUPLEX Juggernaut Push Server DUPLEX
  75. 75. Rails Application Juggernaut Rails Plugin DUPLEX Juggernaut Push JS Server JS DUPLEX
  76. 76. Rails Application Juggernaut Rails Plugin DUPLEX Juggernaut Push JS Server JS DUPLEX
  77. 77. Rails Application Juggernaut Rails Plugin JS DUPLEX Juggernaut Push Server JS DUPLEX
  78. 78. Rails Application SuperMan has left the building! Juggernaut Rails Plugin DUPLEX SuperMan has left the building! Juggernaut Push Server DUPLEX
  79. 79. Audience Participation http://railsconf.madebymany.co.uk
  80. 80. def code
  81. 81. Partial Update Example
  82. 82. Install Juggernaut script/plugin install http://juggernaut.rubyforge.org/svn/trunk/juggernaut sudo gem install juggernaut (includes json and eventmachine dependencies)
  83. 83. Start the Push Server juggernaut -g juggernaut.yml juggernaut -c juggernaut.yml
  84. 84. View <html> <head> <%= javascript_include_tag :defaults, :juggernaut %> <%= juggernaut %> </head>
  85. 85. Controller render :juggernaut do |page| page.replace 'person-45', :partial => 'person' end
  86. 86. That’s it!
  87. 87. Demo 1: Chat
  88. 88. Subscribe to channels <%= juggernaut(:channels => ['one', 'two', 'three']) %>
  89. 89. Broadcast to channels render :juggernaut => { :type => :send_to_channels, :channels => ['one'] } do |page| page.alert('Hello World') end
  90. 90. Subscribe as a particular client <%= juggernaut(:client_id => current_user.id) %>
  91. 91. Broadcast to a particular client render :juggernaut => { :type => :send_to_client, :client_id => @user.id } do |page| page.alert('Hello World') end
  92. 92. Find connected clients Juggernaut.show_clients
  93. 93. Don’t want inline RJS? render_juggernaut('person_update.rjs')
  94. 94. 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)
  95. 95. Demo 2: Google Maps http://railsconf.madebymany.co.uk
  96. 96. tips
  97. 97. 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.
  98. 98. Thank You! http://juggernaut.rubyforge.org/ Q&A

×