Class: Faye::WebSocket::Client

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

Defined Under Namespace

Modules: Connection

Constant Summary

Constants included from API

API::CLOSED, API::CLOSING, API::CONNECTING, API::OPEN

Instance Attribute Summary collapse

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.



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

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

  [:open, :error].each do |event|
    @driver.on(event) do
      @headers = @driver.headers
      @status  = @driver.status
    end
  end

  super(options)

  port = @uri.port || (@uri.scheme == 'wss' ? 443 : 80)
  EventMachine.connect(@uri.host, port, Connection) do |conn|
    @stream = conn
    conn.parent = self
  end
rescue => error
  event = Event.new('error', :message => "Network error: #{url}: #{error.message}")
  event.init_event('error', false, false)
  dispatch_event(event)
  finalize(error.message, 1006)
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/faye/websocket/client.rb', line 7

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/faye/websocket/client.rb', line 7

def status
  @status
end