class Myo::Band # messg ["event", {"myo"=>0, "timestamp"=>"52593461767", "type"=>"paired", "version"=>[1, 1, 5, 2]}] # messg ["event", {"myo"=>0, "timestamp"=>"56817670098", "type"=>"connected", "version"=>[1, 1, 5, 2]}] # messg ["event", {"arm"=>"left", "myo"=>0, "timestamp"=>"56908739636", "type"=>"arm_synced", "x_direction"=>"toward_wrist"}] def initialize(socket) @socket = socket @events = {} @callbacks = {} end def on_connect(event, &block) end def run EM.run do conn = EventMachine::WebSocketClient.connect(@socket) conn.callback do conn.send_msg "Hello!" conn.send_msg "done" end conn.errback do |e| puts "Got error: #{e}" end conn.stream do |msg| conn.close_connection if msg.data == "done" message = JSON.parse(msg.data)[1] case message['type'] when 'paired' puts "MYO PAIRED" puts "msg: #{msg.inspect}" when 'connected' puts 'MYO CONNECTED' puts "msg: #{msg.inspect}" when 'orientation' puts "msg: #{msg.inspect}" end end conn.disconnect do puts "gone" EM::stop_event_loop end end end end