class Citrus::Common::Service::SessionService::Session

Session

Attributes

frontend_id[R]
id[R]
session_service[R]
settings[R]
uid[R]

Public Class Methods

new(sid, frontend_id, socket, service) click to toggle source

Create a new session

@param [Integer] sid @param [String] frontend_id @param [Object] socket @param [Object] service

# 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

Public Instance Methods

bind(uid) click to toggle source

Bind the session with the uid

@param [String] uid

# File lib/citrus/common/service/session_service.rb, line 307
def bind uid
  @uid = uid
  emit :bind, uid
end
closed(reason='') click to toggle source

Closed callback for the session which would disconnect client in next tick

@param [String] reason

# 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) click to toggle source

Get value from the session

@param [String] key

# File lib/citrus/common/service/session_service.rb, line 331
def get key
  @settings[key]
end
send(msg) click to toggle source

Send message to the session

@param [Hash] msg

# File lib/citrus/common/service/session_service.rb, line 338
def send msg
  @socket.send msg
end
send_batch(msgs) click to toggle source

Send message to the session in batch

@param [Array] msgs

# File lib/citrus/common/service/session_service.rb, line 345
def send_batch msgs
  @socket.send_batch msgs
end
set(key, value) click to toggle source

Set value for the session

@param [String] key @param [Hash] value

# File lib/citrus/common/service/session_service.rb, line 324
def set key, value
  @settings[key] = value
end
to_frontend_session() click to toggle source

Export current session as frontend session

# File lib/citrus/common/service/session_service.rb, line 300
def to_frontend_session
  FrontendSession.new self
end
unbind(uid) click to toggle source

Unbind the session with the uid

@param [String] uid

# File lib/citrus/common/service/session_service.rb, line 315
def unbind uid
  @uid = nil
  emit :unbind, uid
end