Class: EventMachine::Wssh::Client::Ws
- Inherits:
-
Object
- Object
- EventMachine::Wssh::Client::Ws
- Defined in:
- lib/em/wssh/client.rb
Instance Method Summary collapse
- #bye ⇒ Object
-
#initialize(uri) ⇒ Ws
constructor
A new instance of Ws.
- #onclose ⇒ Object
- #onerror(error) ⇒ Object
- #onmessage(data) ⇒ Object
- #onopen ⇒ Object
- #queue(data) ⇒ Object
Constructor Details
#initialize(uri) ⇒ Ws
Returns a new instance of Ws.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/em/wssh/client.rb', line 26 def initialize uri @buf=[] @ws=Faye::WebSocket::Client.new uri @ws.on :open do |event| onopen end @ws.on :message do |event| event.data end @ws.on :close do |event| onclose end @ws.on :error do |error| onerror error end end |
Instance Method Details
#bye ⇒ Object
62 63 64 65 66 67 |
# File 'lib/em/wssh/client.rb', line 62 def bye @ws.close if @ws @ws=nil @buf=nil EM.stop_event_loop end |
#onclose ⇒ Object
54 55 56 |
# File 'lib/em/wssh/client.rb', line 54 def onclose bye end |
#onerror(error) ⇒ Object
58 59 60 |
# File 'lib/em/wssh/client.rb', line 58 def onerror error bye end |
#onmessage(data) ⇒ Object
50 51 52 |
# File 'lib/em/wssh/client.rb', line 50 def data print data.pack 'C*' end |
#onopen ⇒ Object
45 46 47 48 |
# File 'lib/em/wssh/client.rb', line 45 def onopen @buf.each{|data| @ws.send data} @buf=nil end |
#queue(data) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/em/wssh/client.rb', line 37 def queue data if @buf @buf << data else @ws.send data end end |