Sha256: 5e605a3d979f596b5cf739d358e6eb2a74ba2f33ab1509ef158a3f8331b378b8

Contents?: true

Size: 807 Bytes

Versions: 29

Compression:

Stored size: 807 Bytes

Contents

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

  io.on :connect do |session|
    puts "new client <#{session}>"
    push :chat, {:name => "system", :message => "new client <#{session}> / #{io.sessions.size} clients connecting"}
    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

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

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

  get '/' do
    haml :index
  end

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

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
sinatra-websocketio-0.4.1 sample/main.rb
sinatra-websocketio-0.4.0 sample/main.rb
sinatra-websocketio-0.3.9 sample/main.rb
sinatra-websocketio-0.3.7 sample/main.rb
sinatra-websocketio-0.3.6 sample/main.rb
sinatra-websocketio-0.3.5 sample/main.rb
sinatra-websocketio-0.3.4 sample/main.rb
sinatra-websocketio-0.3.3 sample/main.rb
sinatra-websocketio-0.3.2 sample/main.rb
sinatra-websocketio-0.3.1 sample/main.rb
sinatra-websocketio-0.3.0 sample/main.rb
sinatra-websocketio-0.2.9 sample/main.rb
sinatra-websocketio-0.2.8 sample/main.rb
sinatra-websocketio-0.2.7 sample/main.rb
sinatra-websocketio-0.2.6 sample/main.rb
sinatra-websocketio-0.2.5 sample/main.rb
sinatra-websocketio-0.2.4 sample/main.rb
sinatra-websocketio-0.2.3 sample/main.rb
sinatra-websocketio-0.2.2 sample/main.rb
sinatra-websocketio-0.2.1 sample/main.rb