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 ) promise = resolvable_future ws.on_open do promise.fulfill(Puppeteer::WebSocketTransport.new(ws)) end ws.on_error do || promise.reject(Puppeteer::WebSocktTransportError.new()) end promise.value! end |
Instance Method Details
#close ⇒ Object
38 39 40 |
# File 'lib/puppeteer/web_socket_transport.rb', line 38 def close @ws.close end |
#on_close(&block) ⇒ Object
42 43 44 |
# File 'lib/puppeteer/web_socket_transport.rb', line 42 def on_close(&block) @on_close = block end |
#on_message(&block) ⇒ Object
46 47 48 |
# File 'lib/puppeteer/web_socket_transport.rb', line 46 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 |