Class: Faye::WebSocket::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
API
Defined in:
lib/faye/websocket/client.rb

Defined Under Namespace

Modules: Connection

Constant Summary collapse

DEFAULT_PORTS =
{ 'http' => 80, 'https' => 443, 'ws' => 80, 'wss' => 443 }
SECURE_PROTOCOLS =
['https', 'wss']

Constants included from API

API::CLOSED, API::CLOSE_TIMEOUT, API::CLOSING, API::CONNECTING, API::OPEN, API::TYPES

Instance Attribute Summary

Attributes included from API

#buffered_amount, #ready_state, #url

Instance Method Summary collapse

Methods included from API

#close, #ping, #protocol, #send, #write

Methods included from API::EventTarget

#add_event_listener, #add_listener, #dispatch_event, #remove_event_listener

Constructor Details

#initialize(url, protocols = nil, options = {}) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/faye/websocket/client.rb', line 15

def initialize(url, protocols = nil, options = {})
  @url = url
  super(options) { ::WebSocket::Driver.client(self, :max_length => options[:max_length], :protocols => protocols) }

  proxy       = options.fetch(:proxy, {})
  @endpoint   = URI.parse(proxy[:origin] || @url)
  port        = @endpoint.port || DEFAULT_PORTS[@endpoint.scheme]
  @origin_tls = options.fetch(:tls, {})
  @socket_tls = proxy[:origin] ? proxy.fetch(:tls, {}) : @origin_tls

  configure_proxy(proxy)

  EventMachine.connect(@endpoint.host, port, Connection) do |conn|
    conn.parent = self
  end
rescue => error
  on_network_error(error)
end