README.rdoc in sinatra-cometio-0.0.2 vs README.rdoc in sinatra-cometio-0.0.3

- old
+ new

@@ -10,41 +10,88 @@ Node.js like Comet I/O plugin for Sinatra == SYNOPSIS: -server +=== Client --(Ajax)--> Server +Client Side + + <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> + <script src="<%= cometio_js %>"></script> + + var io = new CometIO().connect(); + io.push("chat", {name: "shokai", message: "hello"}); // client -> server + +Server Side + require 'sinatra' require 'sinatra/cometio' - ## echo CometIO.on :chat do |data, session| puts "#{data['name']} : #{data['message']} <#{session}>" - self.push :chat, data end + ## => "shokai : hello <12abcde345f6g7h8ijk>" -client HTML +=== Server --(Comet)--> Client - <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> - <script src="<%= cometio_js %>"></script> +Server Side + CometIO.push :temperature, 35 # broadcast + CometIO.push :light, {:value => 150}, {:to => session_id} # to specific client -client JavaScript +Client Side - var io = new CometIO().connect(); + io.on("temperature", function(value){ + console.log("server temperature : " + value); + }); - // client <-- server - io.on("chat", function(data){ - consle.log(data.name+" : "+data.message); + +=== On "connect" Event + +Client Side + + io.on("connect",function(session){ + alert("connect!!"); }); - // client --> server - io.push("chat", {name: "shokai", message: "hello"}); +Server Side + CometIO.on :connect do |session| + puts "new client <#{session}>" + end -see sample app => http://cometio-chat.herokuapp.com +=== On "error" Event + +Client Side + + io.on("error", function(err){ + console.error(err); + }); + + +=== Remove Event Listener + +Server Side + + id = CometIO.on :chat do |data, from| + puts "#{data} - from#{from}" + end + CometIO.removeListener id + +or + + CometIO.removeListener :chat # remove all chat listener + + +== Sample App + +chat app + +- http://cometio-chat.herokuapp.com +- https://github.com/shokai/sinatra-cometio/tree/master/sample + == REQUIREMENTS: * Ruby 1.8.7+ or 1.9.2+