Class: SockJS::Connection
- Inherits:
-
Object
- Object
- SockJS::Connection
- Defined in:
- lib/sockjs/connection.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #create_session(session_key) ⇒ Object
- #get_session(session_key) ⇒ Object
-
#initialize(session_class, options) ⇒ Connection
constructor
A new instance of Connection.
-
#sessions ⇒ Object
XXX TODO: remove dead sessions as they’re get_session’d, along with a recurring clearout.
Constructor Details
#initialize(session_class, options) ⇒ Connection
Returns a new instance of Connection.
6 7 8 9 10 |
# File 'lib/sockjs/connection.rb', line 6 def initialize(session_class, ) self.status = :not_connected @session_class = session_class @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/sockjs/connection.rb', line 11 def @options end |
#status ⇒ Object
Returns the value of attribute status.
11 12 13 |
# File 'lib/sockjs/connection.rb', line 11 def status @status end |
Instance Method Details
#create_session(session_key) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/sockjs/connection.rb', line 36 def create_session(session_key) SockJS.debug "Creating session at #{session_key.inspect}" raise "Session already exists for #{session_key.inspect}" if sessions.has_key?(session_key) session = @session_class.new(self) sessions[session_key] = session session.opened session end |
#get_session(session_key) ⇒ Object
31 32 33 34 |
# File 'lib/sockjs/connection.rb', line 31 def get_session(session_key) SockJS.debug "Looking up session at #{session_key.inspect}" sessions.fetch(session_key) end |
#sessions ⇒ Object
XXX TODO: remove dead sessions as they’re get_session’d, along with a recurring clearout
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sockjs/connection.rb', line 15 def sessions SockJS.debug "Refreshing sessions" if @sessions @sessions.delete_if do |_, session| unless session.alive? SockJS.debug "Removing closed session #{_}" end !session.alive? end else @sessions = {} end end |