Class: SockJS::ConsumingTransport
Instance Attribute Summary
Attributes inherited from Endpoint
#connection, #http_origin, #options, #remote_addr
#method, #prefix
Instance Method Summary
collapse
Methods inherited from Transport
#exception_response, #handle_request, #handle_session_unavailable, #request_data, #response_beginning, #server_key, #session_key
routing_prefix
Methods inherited from Endpoint
#build_error_response, #build_response, #call, #empty_string, #error_content_type, #handle, #handle_http_error, #handle_request, #initialize, #inspect, #response_class, #setup_response
#add_route, #add_routes, #endpoints, #register, #route_conditions, #routing_prefix
Instance Method Details
#closing_frame(response, status, message) ⇒ Object
288
289
290
291
|
# File 'lib/sockjs/transport.rb', line 288
def closing_frame(response, status, message)
send_data(response, format_frame(response, Protocol::ClosingFrame.new(status, message)))
finish_response(response)
end
|
#finish_response(response) ⇒ Object
272
273
274
|
# File 'lib/sockjs/transport.rb', line 272
def finish_response(response)
response.finish
end
|
299
300
301
|
# File 'lib/sockjs/transport.rb', line 299
def format_frame(response, frame)
frame.to_s + "\n"
end
|
#get_session(response) ⇒ Object
303
304
305
306
307
308
309
310
311
312
313
314
315
|
# File 'lib/sockjs/transport.rb', line 303
def get_session(response)
begin
session = connection.get_session(session_key(response))
response_beginning(response)
return session
rescue KeyError
SockJS::debug("Missing session for #{session_key(response)} - creating new")
session = connection.create_session(session_key(response))
response_beginning(response)
opening_frame(response)
return session
end
end
|
#heartbeat_frame(response) ⇒ Object
280
281
282
|
# File 'lib/sockjs/transport.rb', line 280
def heartbeat_frame(response)
send_data(response, format_frame(response, Protocol::HeartbeatFrame.instance))
end
|
#messages_frame(response, messages) ⇒ Object
284
285
286
|
# File 'lib/sockjs/transport.rb', line 284
def messages_frame(response, messages)
send_data(response, format_frame(response, Protocol::ArrayFrame.new(messages)))
end
|
#opening_frame(response) ⇒ Object
276
277
278
|
# File 'lib/sockjs/transport.rb', line 276
def opening_frame(response)
send_data(response, format_frame(response, Protocol::OpeningFrame.instance))
end
|
#process_session(session, response) ⇒ Object
257
258
259
260
261
262
263
264
265
266
|
# File 'lib/sockjs/transport.rb', line 257
def process_session(session, response)
session.attach_consumer(response, self)
response.request.on_close do
begin
request_closed(session)
rescue Object => ex
SockJS::debug "Exception when closing request: #{ex.inspect}"
end
end
end
|
#request_closed(session) ⇒ Object
268
269
270
|
# File 'lib/sockjs/transport.rb', line 268
def request_closed(session)
session.detach_consumer
end
|
#send_data(response, data) ⇒ Object
TODO: Consider absorbing format_frame into send_data
294
295
296
297
|
# File 'lib/sockjs/transport.rb', line 294
def send_data(response, data)
response.write(data)
return data.length
end
|