class Rookout::ComWs::WebsocketClient
Public Class Methods
new(url, proxy, token)
click to toggle source
# File lib/rookout/com_ws/websocket_client.rb, line 12 def initialize url, proxy, token @token = token @connection = WebsocketConnection.new url, proxy @proxy = proxy @driver = nil end
Public Instance Methods
close()
click to toggle source
# File lib/rookout/com_ws/websocket_client.rb, line 63 def close return if @driver.nil? begin @driver.close rescue RuntimeError, Errno::EPIPE # Protocol close may fail if the connection is already closed nil end @connection.close end
connect()
click to toggle source
# File lib/rookout/com_ws/websocket_client.rb, line 19 def connect connection_error = nil @driver = WebSocket::Driver.client @connection headers.each do |key, value| @driver.set_header key, value end @driver.on :error do |error| connection_error = error end # Connect to the remote server # TODO: ADD CONNECT TIMEOUT @connection.connect @driver @driver.start while @driver.state == :connecting recv_data = @connection.read_char @driver.parse recv_data end raise Exceptions::RookWebsocketException, connection_error if @driver.state != :open end
connection_pump(message_handler)
click to toggle source
# File lib/rookout/com_ws/websocket_client.rb, line 44 def connection_pump message_handler @driver.on :message do |e| message_handler.call e.data end until @driver.state == :closed recv_data = @connection.read_char @driver.parse recv_data end end
ping(message, &callback)
click to toggle source
# File lib/rookout/com_ws/websocket_client.rb, line 59 def ping message, &callback @driver.ping message, &callback end
send_frame(msg)
click to toggle source
# File lib/rookout/com_ws/websocket_client.rb, line 55 def send_frame msg @driver.binary msg end
Private Instance Methods
headers()
click to toggle source
# File lib/rookout/com_ws/websocket_client.rb, line 77 def headers result = { "User-Agent" => "RookoutAgent/#{Config.rookout_version}+#{Config.rookout_commit}" } result["X-Rookout-Token"] = @token unless @token.nil? result end