Class: MKIt::LogWebSocketClient

Inherits:
Object
  • Object
show all
Defined in:
lib/mkit/client/log_websocket_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(uri, options) ⇒ LogWebSocketClient

Returns a new instance of LogWebSocketClient.



10
11
12
13
14
15
16
17
# File 'lib/mkit/client/log_websocket_client.rb', line 10

def initialize(uri, options)
  @uri = uri
  @options = options
  trap("SIGINT") do
    puts "Bye..."
    EventMachine.stop
  end
end

Instance Method Details

#doItObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mkit/client/log_websocket_client.rb', line 19

def doIt
  EM.run {
    ws = Faye::WebSocket::Client.new(@uri, nil, @options)

    ws.on :open do |_event|
      puts "Connected to remote server"
      puts "\r\n"
    end

    ws.on :message do |event|
      puts event.data
    end

    ws.on :error do |event|
      p [:error, event.message]
      ws = nil
      EventMachine.stop
    end

    ws.on :close do |_event|
      ws = nil
      puts "\r\n"
      EventMachine.stop
    end
  }
end