Skip to content
Browse files

Identification of how handle_close works.

  • Loading branch information...
1 parent 6eb57da commit 99eb044546ab561b1805b881ddd09fa573c44cfc @botanicus botanicus committed Apr 16, 2012
Showing with 21 additions and 3 deletions.
  1. +21 −3 lib/sockjs/transports/websocket.rb
View
24 lib/sockjs/transports/websocket.rb
@@ -48,8 +48,27 @@ def handle_message(request, event)
@ws.close # Close the connection abruptly, no closing frame.
end
+ # There are two distinct situations
+ # when this handler will be called:
+ #
+ # 1) User app closes the response.
+ # In this case we need to send
+ # the closing frame and close
+ # the WebSocket connection.
+ #
+ # 2) Client closes the response
+ # If client closes the response,
+ # there's not much we can do,
+ # only to mark the session
+ # as terminated and delete
+ # it after the 5s timeout.
def handle_close(request, event)
puts "~ Closing WS connection."
+
+ # If it's the user app who closed
+ # the response, we won't ever get
+ # to pass this point as we'll get
+ # SessionUnavailableError.
session = self.get_session(request.path_info)
if session
@@ -58,15 +77,14 @@ def handle_close(request, event)
# Send the closing frame.
frame = session.process_buffer || 'c[3000,"Go away!"]'# FIXME: This is a hack for the time being. Where's the bloody "c" frame?
session.send_data(frame)
-
- session.transport = nil
+ session.after_close
else
puts "~ Session can't be retrieved, something went pretty damn wrong."
session.send_data('c[3000,"Go away!"]') # ONLY a temporary fallback for the time being!
end
rescue SockJS::SessionUnavailableError
- puts "~ Session is already closing"
+ puts "~ Session is already closing, handle_close won't be called."
end
end
end

0 comments on commit 99eb044

Please sign in to comment.
Something went wrong with that request. Please try again.