Sha256: ae937d38893083c189f3168a0b74cfe991064fe5aa9b2830482b6e004d04f2e0

Contents?: true

Size: 812 Bytes

Versions: 2

Compression:

Stored size: 812 Bytes

Contents

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

  cometio.on :chat do |data, from|
    puts "#{data['name']} : #{data['message']}  (from:#{from})"
    push :chat, data
  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

  cometio.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
      sleep 60
    end
  end

  get '/' do
    haml :index
  end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sinatra-cometio-0.3.1 sample/main.rb
sinatra-cometio-0.3.0 sample/main.rb