Class: Puppeteer::WebSocketTransport
- Inherits:
-
Object
- Object
- Puppeteer::WebSocketTransport
- Defined in:
- lib/puppeteer/web_socket_transport.rb
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(web_socket) ⇒ WebSocketTransport
constructor
A new instance of WebSocketTransport.
- #on_close(&block) ⇒ Object
- #on_message(&block) ⇒ Object
- #send_text(message) ⇒ Object
Constructor Details
#initialize(web_socket) ⇒ WebSocketTransport
Returns a new instance of WebSocketTransport.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/puppeteer/web_socket_transport.rb', line 20 def initialize(web_socket) @ws = web_socket @ws. do |data| @on_message&.call(data) end @ws.on_close do |reason, code| @on_close&.call(reason, code) end @ws.on_error do |error| # Silently ignore all errors - we don't know what to do with them. end end |
Class Method Details
.create(url) ⇒ Puppeteer::WebSocketTransport
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/puppeteer/web_socket_transport.rb', line 4 def self.create(url) ws = Puppeteer::WebSocket.new( url: url, max_payload_size: 256 * 1024 * 1024, # 256MB ) (resolvable_future do |future| ws.on_open do future.fulfill(Puppeteer::WebSocketTransport.new(ws)) end ws.on_error do || future.reject(Puppeteer::WebSocket::TransportError.new()) end end).value! end |
Instance Method Details
#close ⇒ Object
38 39 40 41 42 |
# File 'lib/puppeteer/web_socket_transport.rb', line 38 def close @ws.close rescue EOFError # ignore EOLError. The connection is already closed. end |
#on_close(&block) ⇒ Object
44 45 46 |
# File 'lib/puppeteer/web_socket_transport.rb', line 44 def on_close(&block) @on_close = block end |
#on_message(&block) ⇒ Object
48 49 50 |
# File 'lib/puppeteer/web_socket_transport.rb', line 48 def (&block) @on_message = block end |
#send_text(message) ⇒ Object
34 35 36 |
# File 'lib/puppeteer/web_socket_transport.rb', line 34 def send_text() @ws.send_text() end |