diff --git a/README.markdown b/README.markdown index 698e2e8..43045f2 100644 --- a/README.markdown +++ b/README.markdown @@ -1,5 +1,7 @@ # socket.io-ruby +*NOTICE* This project is no longer maintained. I will accept tested pull requests, but that's it! + [Socket.io] for the Ruby Kids. A plugin for [Cramp](http://cramp.in/). Socket.io is a library that makes writing cross-borwser websockets super easy and resilient. ## Usage @@ -11,37 +13,41 @@ Cramp is similar in spirit to Rails but specializes in evented web apps. Simply Define a new Cramp::Action and include SocketIo::Websocket. Then define which method should handle certain events and messages. - # app/actions/akbar_action.rb - - class AkbarAction < Cramp::Websocket - include SocketIo::Websocket - - on :message, :read_message - on :trap, :report_trap - - # This is fired when the client sends a standard - # Socket.io message - def read_message(data) - puts "Our Bothan spies report #{data}" - end - - def report_trap(imperial_fleet) - puts "It's a trap!" - puts "Concentrate all firepower on #{imperial_fleet['super_stardestroyer']}" - return { 'move' => 'sector 227' } - end - end +```ruby +# app/actions/akbar_action.rb + +class AkbarAction < Cramp::Websocket + include SocketIo::Websocket + + on :message, :read_message + on :trap, :report_trap + + # This is fired when the client sends a standard + # Socket.io message + def read_message(data) + puts "Our Bothan spies report #{data}" + end + + def report_trap(imperial_fleet) + puts "It's a trap!" + puts "Concentrate all firepower on #{imperial_fleet['super_stardestroyer']}" + return { 'move' => 'sector 227' } + end +end +``` By default, Cramp uses HttpRouter in config/routes.rb to manage connections. SocketIo has a handy helper for that: - # config/routes.rb - - require 'socket.io' - require 'http_router' - - HttpRouter.new do - SocketIo.routes self, AkbarAction - end +```ruby +# config/routes.rb + +require 'socket.io' +require 'http_router' + +HttpRouter.new do + SocketIo.routes self, AkbarAction +end +``` Optionally, SocketIo.routes can take a path. The default is `/socket.io`. @@ -49,22 +55,26 @@ Throw that in with some [Thin](http://code.macournoyer.com/thin/) or [Rainbows]( Note that you'll need to configure cramp's websocket adapter to use thin or rainbows: - # config.ru - - Cramp::Websocket.backend = :rainbows # or :thin +```ruby +# config.ru + +Cramp::Websocket.backend = :rainbows # or :thin +``` Here's the client-side code to make it all happen: - - +```html + + +``` ## Note on Patches/Pull Requests