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