Module: Faye::WebSocket::API
- Extended by:
- Forwardable
- Includes:
- EventTarget
- Included in:
- Faye::WebSocket, Client
- Defined in:
- lib/faye/websocket/api.rb,
lib/faye/websocket/api/event.rb,
lib/faye/websocket/api/event_target.rb
Defined Under Namespace
Modules: EventTarget
Classes: Event
Constant Summary
collapse
- CONNECTING =
0
- OPEN =
1
- CLOSING =
2
- CLOSED =
3
Instance Attribute Summary collapse
Instance Method Summary
collapse
#add_event_listener, #add_listener, #dispatch_event, #remove_event_listener
Instance Attribute Details
#buffered_amount ⇒ Object
Returns the value of attribute buffered_amount.
18
19
20
|
# File 'lib/faye/websocket/api.rb', line 18
def buffered_amount
@buffered_amount
end
|
#ready_state ⇒ Object
Returns the value of attribute ready_state.
18
19
20
|
# File 'lib/faye/websocket/api.rb', line 18
def ready_state
@ready_state
end
|
#url ⇒ Object
Returns the value of attribute url.
18
19
20
|
# File 'lib/faye/websocket/api.rb', line 18
def url
@url
end
|
Instance Method Details
#close ⇒ Object
97
98
99
100
|
# File 'lib/faye/websocket/api.rb', line 97
def close
@ready_state = CLOSING if @ready_state == OPEN
@driver.close
end
|
#initialize ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/faye/websocket/api.rb', line 20
def initialize
super
@ready_state = CONNECTING
@buffered_amount = 0
@driver.on(:open) { |e| open }
@driver.on(:message) { |e| receive_message(e.data) }
@driver.on(:close) { |e| finalize(e.reason, e.code) }
@driver.on(:error) do |error|
event = Event.new('error')
event.init_event('error', false, false)
dispatch_event(event)
end
if @ping
@ping_timer = EventMachine.add_periodic_timer(@ping) do
@ping_id += 1
ping(@ping_id.to_s)
end
end
end
|
#ping(message = '', &callback) ⇒ Object
92
93
94
95
|
# File 'lib/faye/websocket/api.rb', line 92
def ping(message = '', &callback)
return false if @ready_state > OPEN
@driver.ping(message, &callback)
end
|
#protocol ⇒ Object
102
103
104
|
# File 'lib/faye/websocket/api.rb', line 102
def protocol
@driver.protocol || ''
end
|
#send(message) ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/faye/websocket/api.rb', line 82
def send(message)
return false if @ready_state > OPEN
case message
when Numeric then @driver.text(message.to_s)
when String then @driver.text(message)
when Array then @driver.binary(message)
else false
end
end
|
#write(data) ⇒ Object
78
79
80
|
# File 'lib/faye/websocket/api.rb', line 78
def write(data)
@stream.write(data)
end
|