examples/shoutchat.rb in rev-websocket-0.1.2 vs examples/shoutchat.rb in rev-websocket-0.1.3

- old
+ new

@@ -39,30 +39,28 @@ $pubsub = PubSub.new $record = [] class ShoutChatConnection < Rev::WebSocket def on_open - @host = request['HTTP_HOST'] - return unless @host + @host = peeraddr[2] puts "connection opened: <#{@host}>" @sid = $pubsub.subscribe {|data| send_message data } $pubsub.publish(["count", $pubsub.size].to_json) $record.each {|data| send_message data } end def on_message(data) - puts "broadcasting: <#{@host}> #{data}" + puts "broadcasting: <#{@host}> '#{data}'" $pubsub.publish(data) $record.push(data) $record.shift while $record.size > 20 end def on_close - return unless @host puts "connection closed: <#{@host}>" $pubsub.unsubscribe(@sid) $pubsub.publish(["count", $pubsub.size].to_json) end