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
290
291
292
293
|
# File 'lib/sockjs/transport.rb', line 290
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
274
275
276
|
# File 'lib/sockjs/transport.rb', line 274
def finish_response(response)
response.finish
end
|
301
302
303
|
# File 'lib/sockjs/transport.rb', line 301
def format_frame(response, frame)
frame.to_s + "\n"
end
|
#get_session(response) ⇒ Object
305
306
307
308
309
310
311
312
313
314
315
316
317
|
# File 'lib/sockjs/transport.rb', line 305
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
282
283
284
|
# File 'lib/sockjs/transport.rb', line 282
def heartbeat_frame(response)
send_data(response, format_frame(response, Protocol::HeartbeatFrame.instance))
end
|
#messages_frame(response, messages) ⇒ Object
286
287
288
|
# File 'lib/sockjs/transport.rb', line 286
def messages_frame(response, messages)
send_data(response, format_frame(response, Protocol::ArrayFrame.new(messages)))
end
|
#opening_frame(response) ⇒ Object
278
279
280
|
# File 'lib/sockjs/transport.rb', line 278
def opening_frame(response)
send_data(response, format_frame(response, Protocol::OpeningFrame.instance))
end
|
#process_session(session, response) ⇒ Object
259
260
261
262
263
264
265
266
267
268
|
# File 'lib/sockjs/transport.rb', line 259
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
270
271
272
|
# File 'lib/sockjs/transport.rb', line 270
def request_closed(session)
session.detach_consumer
end
|
#send_data(response, data) ⇒ Object
TODO: Consider absorbing format_frame into send_data
296
297
298
299
|
# File 'lib/sockjs/transport.rb', line 296
def send_data(response, data)
response.write(data)
return data.length
end
|