sample/main.rb in sinatra-cometio-0.3.1 vs sample/main.rb in sinatra-cometio-0.3.2
- old
+ new
@@ -1,26 +1,27 @@
class ChatApp < Sinatra::Base
register Sinatra::CometIO
+ io = Sinatra::CometIO
- cometio.on :chat do |data, from|
+ io.on :chat do |data, from|
puts "#{data['name']} : #{data['message']} (from:#{from})"
push :chat, data
end
- cometio.on :connect do |session|
+ io.on :connect do |session|
puts "new client <#{session}>"
push :chat, {:name => "system", :message => "new client <#{session}>"}
push :chat, {:name => "system", :message => "welcome <#{session}>"}, {:to => session}
end
- cometio.on :disconnect do |session|
+ io.on :disconnect do |session|
puts "disconnect client <#{session}>"
push :chat, {:name => "system", :message => "bye <#{session}>"}
end
EM::defer do
loop do
- cometio.push :chat, :name => 'clock', :message => Time.now.to_s
+ io.push :chat, :name => 'clock', :message => Time.now.to_s
sleep 60
end
end
get '/' do