Sha256: 02116e52fecb4150144a6a090c76a72703442bb1de5d89975ca6cad1de9eb80c

Contents?: true

Size: 816 Bytes

Versions: 23

Compression:

Stored size: 816 Bytes

Contents

class ChatApp < Sinatra::Base
  register Sinatra::CometIO
  io = Sinatra::CometIO

  io.on :chat do |data, from|
    puts "#{data['name']} : #{data['message']}  (from:#{from})"
    push :chat, data
  end

  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

  io.on :disconnect do |session|
    puts "disconnect client <#{session}>"
    push :chat, {:name => "system", :message => "bye <#{session}>"}
  end

  EM::defer do
    loop do
      io.push :chat, :name => 'clock', :message => Time.now.to_s
      sleep 60
    end
  end

  get '/' do
    haml :index
  end

  get '/:source.css' do
    scss params[:source].to_sym
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
sinatra-cometio-0.6.0 sample/main.rb
sinatra-cometio-0.5.9 sample/main.rb
sinatra-cometio-0.5.8 sample/main.rb
sinatra-cometio-0.5.7 sample/main.rb
sinatra-cometio-0.5.6 sample/main.rb
sinatra-cometio-0.5.5 sample/main.rb
sinatra-cometio-0.5.4 sample/main.rb
sinatra-cometio-0.5.3 sample/main.rb
sinatra-cometio-0.5.2 sample/main.rb
sinatra-cometio-0.5.1 sample/main.rb
sinatra-cometio-0.5.0 sample/main.rb
sinatra-cometio-0.4.3 sample/main.rb
sinatra-cometio-0.4.2 sample/main.rb
sinatra-cometio-0.4.1 sample/main.rb
sinatra-cometio-0.4.0 sample/main.rb
sinatra-cometio-0.3.9 sample/main.rb
sinatra-cometio-0.3.8 sample/main.rb
sinatra-cometio-0.3.7 sample/main.rb
sinatra-cometio-0.3.6 sample/main.rb
sinatra-cometio-0.3.5 sample/main.rb