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.
- #open? ⇒ Boolean
- #send_message(message) ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(url, options) ⇒ WebSocket
Returns a new instance of WebSocket.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 13 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.
11 12 13 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 11 def @messages end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
11 12 13 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 11 def url @url end |
Instance Method Details
#close ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 34 def close return if @status == :closed @status = :closing @messages.close @driver&.close @thread&.join(1) || @thread&.kill @socket&.close @status = :closed end |
#closed? ⇒ Boolean
45 46 47 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 45 def closed? @status == :closed end |
#open? ⇒ Boolean
49 50 51 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 49 def open? @status == :open end |
#send_message(message) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 27 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
53 54 55 56 57 58 |
# File 'lib/capybara/lightpanda/client/web_socket.rb', line 53 def write(data) @socket.write(data) rescue Errno::EPIPE, Errno::ECONNRESET, IOError @status = :closed @messages.close end |