sample/main.rb in sinatra-cometio-0.2.0 vs sample/main.rb in sinatra-cometio-0.3.0

- old
+ new

@@ -1,30 +1,34 @@ -CometIO.on :chat do |data, from| - puts "#{data['name']} : #{data['message']} (from:#{from})" - self.push :chat, data -end +class ChatApp < Sinatra::Base + register Sinatra::CometIO -CometIO.on :connect do |session| - puts "new client <#{session}>" - CometIO.push :chat, {:name => "system", :message => "new client <#{session}>"} - CometIO.push :chat, {:name => "system", :message => "welcome <#{session}>"}, {:to => session} -end + cometio.on :chat do |data, from| + puts "#{data['name']} : #{data['message']} (from:#{from})" + push :chat, data + end -CometIO.on :disconnect do |session| - puts "disconnect client <#{session}>" - CometIO.push :chat, {:name => "system", :message => "bye <#{session}>"} -end + cometio.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 -EM::defer do - loop do - CometIO.push :chat, :name => 'clock', :message => Time.now.to_s - sleep 60 + cometio.on :disconnect do |session| + puts "disconnect client <#{session}>" + push :chat, {:name => "system", :message => "bye <#{session}>"} end -end -get '/' do - haml :index -end + EM::defer do + loop do + cometio.push :chat, :name => 'clock', :message => Time.now.to_s + sleep 60 + end + end -get '/:source.css' do - scss params[:source].to_sym + get '/' do + haml :index + end + + get '/:source.css' do + scss params[:source].to_sym + end end