Method: Faye::Client#initialize

Defined in:
lib/faye/protocol/client.rb

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

Returns a new instance of Client.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/faye/protocol/client.rb', line 23

def initialize(endpoint = nil, options = {})
  ::WebSocket::Driver.validate_options(options, [:interval, :timeout, :endpoints, :proxy, :retry, :scheduler, :websocket_extensions])
  super()
  info('New client created for ?', endpoint)

  @endpoint   = endpoint || RackAdapter::DEFAULT_ENDPOINT
  @channels   = Channel::Set.new
  @dispatcher = Dispatcher.new(self, @endpoint, options)

  @message_id = 0
  @state      = UNCONNECTED

  @response_callbacks = {}

  @advice = {
    'reconnect' => RETRY,
    'interval'  => 1000.0 * (options[:interval] || Engine::INTERVAL),
    'timeout'   => 1000.0 * (options[:timeout]  || CONNECTION_TIMEOUT)
  }
  @dispatcher.timeout = @advice['timeout'] / 1000.0

  @dispatcher.bind(:message, &method(:receive_message))
end