Class: Faye::Transport
Defined Under Namespace
Classes: Http, Local, WebSocket
Constant Summary
collapse
- DEFAULT_PORTS =
{'http' => 80, 'https' => 433, 'ws' => 80, 'wss' => 443}
- SECURE_PROTOCOLS =
['https', 'wss']
Constants included
from Logging
Logging::LOG_LEVELS
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Timeouts
#add_timeout, #remove_all_timeouts, #remove_timeout
Methods included from Publisher
#unbind
Constructor Details
#initialize(dispatcher, endpoint) ⇒ Transport
Returns a new instance of Transport.
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/faye/transport/transport.rb', line 13
def initialize(dispatcher, endpoint)
super()
@dispatcher = dispatcher
@endpoint = endpoint
@outbox = []
@proxy = @dispatcher.proxy.dup
scheme = @endpoint.respond_to?(:scheme) ? @endpoint.scheme : nil
@proxy[:origin] ||= SECURE_PROTOCOLS.include?(scheme) ?
(ENV['HTTPS_PROXY'] || ENV['https_proxy']) :
(ENV['HTTP_PROXY'] || ENV['http_proxy'])
end
|
Class Attribute Details
.connection_type ⇒ Object
Returns the value of attribute connection_type.
134
135
136
|
# File 'lib/faye/transport/transport.rb', line 134
def connection_type
@connection_type
end
|
Instance Attribute Details
#endpoint ⇒ Object
Returns the value of attribute endpoint.
11
12
13
|
# File 'lib/faye/transport/transport.rb', line 11
def endpoint
@endpoint
end
|
Class Method Details
.connection_types ⇒ Object
170
171
172
|
# File 'lib/faye/transport/transport.rb', line 170
def connection_types
@transports.map { |t| t[0] }
end
|
.get(dispatcher, allowed, disabled, &callback) ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/faye/transport/transport.rb', line 136
def get(dispatcher, allowed, disabled, &callback)
endpoint = dispatcher.endpoint
select = lambda do |(conn_type, klass), resume|
conn_endpoint = dispatcher.endpoint_for(conn_type)
if disabled.include?(conn_type)
next resume.call
end
unless allowed.include?(conn_type)
klass.usable?(dispatcher, conn_endpoint) { |u| }
next resume.call
end
klass.usable?(dispatcher, conn_endpoint) do |is_usable|
next resume.call unless is_usable
transport = klass.respond_to?(:create) ? klass.create(dispatcher, conn_endpoint) : klass.new(dispatcher, conn_endpoint)
callback.call(transport)
end
end
error = lambda do
raise "Could not find a usable connection type for #{ endpoint }"
end
Faye.async_each(@transports, select, error)
end
|
.register(type, klass) ⇒ Object
165
166
167
168
|
# File 'lib/faye/transport/transport.rb', line 165
def register(type, klass)
@transports << [type, klass]
klass.connection_type = type
end
|
Instance Method Details
#batching? ⇒ Boolean
27
28
29
|
# File 'lib/faye/transport/transport.rb', line 27
def batching?
true
end
|
#close ⇒ Object
31
32
|
# File 'lib/faye/transport/transport.rb', line 31
def close
end
|
#connection_type ⇒ Object
38
39
40
|
# File 'lib/faye/transport/transport.rb', line 38
def connection_type
self.class.connection_type
end
|
#encode(messages) ⇒ Object
34
35
36
|
# File 'lib/faye/transport/transport.rb', line 34
def encode(messages)
''
end
|
#send_message(message) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/faye/transport/transport.rb', line 42
def send_message(message)
debug('Client ? sending message to ? via ?: ?', @dispatcher.client_id, @endpoint, connection_type, message)
unless batching?
promise = EventMachine::DefaultDeferrable.new
promise.succeed(request([message]))
return promise
end
@outbox << message
flush_large_batch
if message['channel'] == Channel::HANDSHAKE
return publish(0.01)
end
if message['channel'] == Channel::CONNECT
@connection_message = message
end
publish(Engine::MAX_DELAY)
end
|