sample/bin/cui_chat_client.rb in sinatra-websocketio-0.1.7 vs sample/bin/cui_chat_client.rb in sinatra-websocketio-0.2.0

- old
+ new

@@ -1,38 +1,32 @@ #!/usr/bin/env ruby require 'rubygems' require 'bundler/setup' $:.unshift File.expand_path '../../lib', File.dirname(__FILE__) require 'eventmachine' -require 'em-websocketio-client' +require 'sinatra/websocketio/client' name = `whoami`.strip || 'shokai' -EM::run do - client = EM::WebSocketIO::Client.new('ws://localhost:8080').connect +client = Sinatra::WebSocketIO::Client.new('ws://localhost:8080').connect - client.on :connect do |session| - puts "connect!! (session_id:#{session})" - end +client.on :connect do |session| + puts "connect!! (session_id:#{session})" +end - client.on :chat do |data| - puts "<#{data['name']}> #{data['message']}" - end +client.on :chat do |data| + puts "<#{data['name']}> #{data['message']}" +end - client.on :error do |err| - STDERR.puts err - end +client.on :error do |err| + STDERR.puts err +end - client.on :disconnect do - puts "disconnected!!" - end - - EM::defer do - loop do - line = STDIN.gets.strip - next if line.empty? - client.push :chat, {:message => line, :name => name} - end - end +client.on :disconnect do + puts "disconnected!!" end - +loop do + line = STDIN.gets.strip + next if line.empty? + client.push :chat, {:message => line, :name => name} +end