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::ReadyStates

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

Instance Attribute Summary collapse

Attributes included from API

#buffered_amount, #ready_state, #url

Attributes included from API::EventTarget

#onclose, #onerror, #onmessage, #onopen

Instance Method Summary collapse

Methods included from API

#close, #receive, #send

Methods included from API::EventTarget

#add_event_listener, #dispatch_event, #remove_event_listener

Constructor Details

#initialize(url, protocols = nil) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/faye/websocket/client.rb', line 8

def initialize(url, protocols = nil)
  @parser = HybiParser.new(self, :masking => true, :protocols => protocols)
  @url    = url
  @uri    = URI.parse(url)
  
  @protocol = ''
  @ready_state = CONNECTING
  @buffered_amount = 0
  
  port = @uri.port || (@uri.scheme == 'wss' ? 443 : 80)
  
  EventMachine.connect(@uri.host, port, Connection) do |conn|
    @stream = conn
    conn.parent = self
  end
end

Instance Attribute Details

#protocolObject (readonly)

Returns the value of attribute protocol.



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

def protocol
  @protocol
end

#uriObject (readonly)

Returns the value of attribute uri.



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

def uri
  @uri
end