Class: Citrus::Common::Service::SessionService::Session
- Inherits:
-
Object
- Object
- Citrus::Common::Service::SessionService::Session
- Includes:
- Utils::EventEmitter
- Defined in:
- lib/citrus/common/service/session_service.rb
Overview
Session
Instance Attribute Summary collapse
-
#frontend_id ⇒ Object
readonly
Returns the value of attribute frontend_id.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#session_service ⇒ Object
readonly
Returns the value of attribute session_service.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Instance Method Summary collapse
-
#bind(uid) ⇒ Object
Bind the session with the uid.
-
#closed(reason = '') ⇒ Object
Closed callback for the session which would disconnect client in next tick.
-
#get(key) ⇒ Object
Get value from the session.
-
#initialize(sid, frontend_id, socket, service) ⇒ Session
constructor
Create a new session.
-
#send(msg) ⇒ Object
Send message to the session.
-
#send_batch(msgs) ⇒ Object
Send message to the session in batch.
-
#set(key, value) ⇒ Object
Set value for the session.
-
#to_frontend_session ⇒ Object
Export current session as frontend session.
-
#unbind(uid) ⇒ Object
Unbind the session with the uid.
Methods included from Utils::EventEmitter
Constructor Details
#initialize(sid, frontend_id, socket, service) ⇒ Session
Create a new session
288 289 290 291 292 293 294 295 296 297 |
# File 'lib/citrus/common/service/session_service.rb', line 288 def initialize sid, frontend_id, socket, service @id = sid @frontend_id = frontend_id @uid = nil @settings = {} @socket = socket @session_service = service @state = :state_inited end |
Instance Attribute Details
#frontend_id ⇒ Object (readonly)
Returns the value of attribute frontend_id.
280 281 282 |
# File 'lib/citrus/common/service/session_service.rb', line 280 def frontend_id @frontend_id end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
280 281 282 |
# File 'lib/citrus/common/service/session_service.rb', line 280 def id @id end |
#session_service ⇒ Object (readonly)
Returns the value of attribute session_service.
280 281 282 |
# File 'lib/citrus/common/service/session_service.rb', line 280 def session_service @session_service end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
280 281 282 |
# File 'lib/citrus/common/service/session_service.rb', line 280 def settings @settings end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
280 281 282 |
# File 'lib/citrus/common/service/session_service.rb', line 280 def uid @uid end |
Instance Method Details
#bind(uid) ⇒ Object
Bind the session with the uid
307 308 309 310 |
# File 'lib/citrus/common/service/session_service.rb', line 307 def bind uid @uid = uid emit :bind, uid end |
#closed(reason = '') ⇒ Object
Closed callback for the session which would disconnect client in next tick
352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/citrus/common/service/session_service.rb', line 352 def closed reason='' return if @state == :state_closed @state = :state_closed @service.remove @id emit :closed, to_frontend_session, reason @socket.emit :closing, reason EM.next_tick { @socket.disconnect } end |
#get(key) ⇒ Object
Get value from the session
331 332 333 |
# File 'lib/citrus/common/service/session_service.rb', line 331 def get key @settings[key] end |
#send(msg) ⇒ Object
Send message to the session
338 339 340 |
# File 'lib/citrus/common/service/session_service.rb', line 338 def send msg @socket.send msg end |
#send_batch(msgs) ⇒ Object
Send message to the session in batch
345 346 347 |
# File 'lib/citrus/common/service/session_service.rb', line 345 def send_batch msgs @socket.send_batch msgs end |
#set(key, value) ⇒ Object
Set value for the session
324 325 326 |
# File 'lib/citrus/common/service/session_service.rb', line 324 def set key, value @settings[key] = value end |
#to_frontend_session ⇒ Object
Export current session as frontend session
300 301 302 |
# File 'lib/citrus/common/service/session_service.rb', line 300 def to_frontend_session FrontendSession.new self end |
#unbind(uid) ⇒ Object
Unbind the session with the uid
315 316 317 318 |
# File 'lib/citrus/common/service/session_service.rb', line 315 def unbind uid @uid = nil emit :unbind, uid end |