Sha256: f823197b682b88976ce8fd2336ad0f8bf7068f103c9a604dc0bda40b74d98bc2

Contents?: true

Size: 1 KB

Versions: 11

Compression:

Stored size: 1 KB

Contents

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

  io.once :start do
    puts "RocketIO start!!!"
  end

  io.on :connect do |client|
    puts "new client  - #{client}"
    push :chat, {:name => "system", :message => "new #{client.type} client <#{client.session}>"}, :channel => client.channel
    push :chat, {:name => "system", :message => "welcome <#{client.session}>"}, :to => client.session
  end

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

  io.on :chat do |data, client|
    puts "#{data['name']} : #{data['message']}  - #{client}"
    push :chat, data, :channel => client.channel
  end

  io.on :error do |err|
    STDERR.puts "error!! #{err}"
  end

  get '/' do
    redirect '/chat/1'
  end

  get '/chat/:channel' do
    @channel = params[:channel]
    haml :chat
  end

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sinatra-rocketio-0.3.3 sample/modular_style/main.rb
sinatra-rocketio-0.3.2 sample/modular_style/main.rb
sinatra-rocketio-0.3.1 sample/modular_style/main.rb
sinatra-rocketio-0.3.0 sample/modular_style/main.rb
sinatra-rocketio-0.2.6 sample/modular_style/main.rb
sinatra-rocketio-0.2.5 sample/modular_style/main.rb
sinatra-rocketio-0.2.4 sample/modular_style/main.rb
sinatra-rocketio-0.2.3 sample/main.rb
sinatra-rocketio-0.2.2 sample/main.rb
sinatra-rocketio-0.2.1 sample/main.rb
sinatra-rocketio-0.2.0 sample/main.rb