Class: Puppeteer::WebSocket::DriverImpl

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer/web_socket.rb

Overview

providing #url, #write(string)

Defined Under Namespace

Classes: SecureSocketFactory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ DriverImpl

Returns a new instance of DriverImpl.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/puppeteer/web_socket.rb', line 21

def initialize(url)
  @url = url

  endpoint = URI.parse(url)
  @socket =
    if endpoint.scheme == 'wss'
      SecureSocketFactory.new(endpoint.host, endpoint.port).create
    else
      TCPSocket.new(endpoint.host, endpoint.port)
    end
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



33
34
35
# File 'lib/puppeteer/web_socket.rb', line 33

def url
  @url
end

Instance Method Details

#disposeObject



49
50
51
# File 'lib/puppeteer/web_socket.rb', line 49

def dispose
  @socket.close
end

#readpartial(maxlen = 1024) ⇒ Object



43
44
45
46
47
# File 'lib/puppeteer/web_socket.rb', line 43

def readpartial(maxlen = 1024)
  @socket.readpartial(maxlen)
rescue Errno::ECONNRESET
  raise EOFError.new('closed by remote')
end

#write(data) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/puppeteer/web_socket.rb', line 35

def write(data)
  @socket.write(data)
rescue Errno::EPIPE
  raise EOFError.new('already closed')
rescue Errno::ECONNRESET
  raise EOFError.new('closed by remote')
end