Class: Capybara::Lightpanda::Client::WebSocket
- Inherits:
-
Object
- Object
- Capybara::Lightpanda::Client::WebSocket
- Defined in:
- lib/capybara/lightpanda/client/web_socket.rb
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(url, options) ⇒ WebSocket
constructor
A new instance of WebSocket.
- #send_message(message) ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(url, options) ⇒ WebSocket
Returns a new instance of WebSocket.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 15 def initialize(url, ) @url = url @options = @logger = .logger @socket = nil @driver = nil @thread = nil @status = :closed @messages = Queue.new @driver_mutex = Mutex.new connect end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
13 14 15 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 13 def @messages end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
13 14 15 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 13 def url @url end |
Instance Method Details
#close ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 36 def close return if @status == :closed @status = :closing @messages.close @driver_mutex.synchronize { @driver&.close } @thread&.join(1) || @thread&.kill @socket&.close @status = :closed end |
#closed? ⇒ Boolean
47 48 49 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 47 def closed? @status == :closed || @status == :error end |
#send_message(message) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 29 def () raise DeadBrowserError, "WebSocket is not open" unless @status == :open @logger&.puts("\n\n▶ #{@logger.elapsed_time} #{}") @driver_mutex.synchronize { @driver.text() } end |
#write(data) ⇒ Object
51 52 53 54 55 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 51 def write(data) @socket.write(data) rescue Errno::EPIPE, Errno::ECONNRESET, IOError mark_dead end |