Sha256: 50cc1f4d93c7480b435a95bd0aaadc97454ac7950ca5cbd83699408537c1f7a8

Contents?: true

Size: 1.07 KB

Versions: 18

Compression:

Stored size: 1.07 KB

Contents

class Puppeteer::WebSocketTransport
  # @param {string} url
  # @return [Puppeteer::WebSocketTransport]
  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 |error_message|
        future.reject(Puppeteer::WebSocket::TransportError.new(error_message))
      end
    end).value!
  end

  # @param {!WebSocket::Driver} web_socket
  def initialize(web_socket)
    @ws = web_socket
    @ws.on_message 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

  # @param message [String]
  def send_text(message)
    @ws.send_text(message)
  end

  def close
    @ws.close
  end

  def on_close(&block)
    @on_close = block
  end

  def on_message(&block)
    @on_message = block
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
puppeteer-ruby-0.30.0 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.29.0 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.28.1 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.27 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.26 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.25 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.23 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.22 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.21 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.20 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.19 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.18 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.17 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.16 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.15 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.14 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.13 lib/puppeteer/web_socket_transport.rb
puppeteer-ruby-0.0.12 lib/puppeteer/web_socket_transport.rb