Class: Capybara::Apparition::WebSocketClient

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/apparition/driver/web_socket_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ WebSocketClient

Returns a new instance of WebSocketClient.



9
10
11
12
13
14
15
16
17
# File 'lib/capybara/apparition/driver/web_socket_client.rb', line 9

def initialize(url)
  @socket = Socket.new(url)
  @driver = ::WebSocket::Driver.client(@socket)
  @messages = []
  @status = :closed

  setup_driver
  start_driver
end

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver.



7
8
9
# File 'lib/capybara/apparition/driver/web_socket_client.rb', line 7

def driver
  @driver
end

#messagesObject (readonly)

Returns the value of attribute messages.



7
8
9
# File 'lib/capybara/apparition/driver/web_socket_client.rb', line 7

def messages
  @messages
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/capybara/apparition/driver/web_socket_client.rb', line 7

def status
  @status
end

Instance Method Details

#closeObject



28
29
30
# File 'lib/capybara/apparition/driver/web_socket_client.rb', line 28

def close
  @driver.close
end

#read_msgObject



23
24
25
26
# File 'lib/capybara/apparition/driver/web_socket_client.rb', line 23

def read_msg
  parse_input until (msg = messages.shift)
  msg
end

#send_msg(msg) ⇒ Object



19
20
21
# File 'lib/capybara/apparition/driver/web_socket_client.rb', line 19

def send_msg(msg)
  driver.text msg
end