Class: Lightpanda::Client::WebSocket
- Inherits:
-
Object
- Object
- Lightpanda::Client::WebSocket
- Defined in:
- lib/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.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/lightpanda/client/web_socket.rb', line 12 def initialize(url, ) @url = url @options = @socket = nil @driver = nil @thread = nil @status = :closed @messages = Queue.new connect end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
10 11 12 |
# File 'lib/lightpanda/client/web_socket.rb', line 10 def @messages end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/lightpanda/client/web_socket.rb', line 10 def url @url end |
Instance Method Details
#close ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/lightpanda/client/web_socket.rb', line 30 def close return if @status == :closed @status = :closing @driver&.close @thread&.kill @socket&.close @status = :closed end |
#closed? ⇒ Boolean
40 41 42 |
# File 'lib/lightpanda/client/web_socket.rb', line 40 def closed? @status == :closed end |
#open? ⇒ Boolean
44 45 46 |
# File 'lib/lightpanda/client/web_socket.rb', line 44 def open? @status == :open end |
#send_message(message) ⇒ Object
24 25 26 27 28 |
# File 'lib/lightpanda/client/web_socket.rb', line 24 def () raise DeadBrowserError, "WebSocket is not open" unless @status == :open @driver.text() end |
#write(data) ⇒ Object
48 49 50 51 52 |
# File 'lib/lightpanda/client/web_socket.rb', line 48 def write(data) @socket.write(data) rescue Errno::EPIPE, Errno::ECONNRESET, IOError @status = :closed end |