Class: Bixby::WebSocket::Client

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/bixby-common/websocket/client.rb

Overview

WebSocket Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log

#log, setup_logger

Constructor Details

#initialize(url, handler) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
# File 'lib/bixby-common/websocket/client.rb', line 15

def initialize(url, handler)
  @url = url
  @handler = handler
  @tries = 0
  @exiting = false
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



13
14
15
# File 'lib/bixby-common/websocket/client.rb', line 13

def api
  @api
end

#wsObject (readonly)

Returns the value of attribute ws.



13
14
15
# File 'lib/bixby-common/websocket/client.rb', line 13

def ws
  @ws
end

Instance Method Details

#startObject

Start the Client thread

NOTE: This call never returns!



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bixby-common/websocket/client.rb', line 25

def start

  @exiting = false

  Kernel.trap("EXIT") do
    @exiting = true
  end

  EM.run {
    connect()
  }
end

#stopObject



38
39
40
41
# File 'lib/bixby-common/websocket/client.rb', line 38

def stop
  @exiting = true
  EM.stop_event_loop
end