Sha256: ae4f2003a63427eca7a65bb502063bf01c2de9398d4314abf4eda27d0181644b

Contents?: true

Size: 866 Bytes

Versions: 1

Compression:

Stored size: 866 Bytes

Contents

# # frozen_string_literal: true
require 'faye/websocket'
require 'eventmachine'
require 'json'
require 'io/console'

module MKIt
  class LogWebSocketClient

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

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mkit-0.9.0 lib/mkit/client/log_websocket_client.rb