Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SessionService

Session service maintains the internal session for each client connection.

Session service is created by session component and is only available in frontend servers. You can access the service by app.get('sessionService') or app.sessionService in frontend servers.

param

constructor parameters

class
constructor

Hierarchy

Index

Constructors

constructor

Properties

abind

abind: function = utils.promisify(this.bind)

Type declaration

    • (sid: SID, uid: UID): Promise<void>
    • Parameters

      Returns Promise<void>

aimport

aimport: function = utils.promisify(this.import)

Type declaration

    • (sid: SID, key: string, value: any): Promise<void>
    • Parameters

      • sid: SID
      • key: string
      • value: any

      Returns Promise<void>

aimportAll

aimportAll: function = utils.promisify(this.importAll)

Type declaration

    • (sid: SID, settings: any): Promise<void>
    • Parameters

      • sid: SID
      • settings: any

      Returns Promise<void>

akick

akick: function = utils.promisify(this.kick)

Type declaration

    • (uid: UID, reason?: string): Promise<void>
    • Parameters

      • uid: UID
      • Optional reason: string

      Returns Promise<void>

akickBySessionId

akickBySessionId: function = utils.promisify(this.kickBySessionId)

Type declaration

    • (sid: SID, reason?: string): Promise<void>
    • Parameters

      • sid: SID
      • Optional reason: string

      Returns Promise<void>

aunbind

aunbind: function = utils.promisify(this.unbind)

Type declaration

    • (sid: SID, uid: UID): Promise<void>
    • Parameters

      Returns Promise<void>

sessions

sessions: object

Type declaration

singleSession

singleSession: Session

uidMap

uidMap: object

Type declaration

Methods

bind

  • bind(sid: SID, uid: UID, cb: function): void
  • Bind the session with a user id.

    memberof

    SessionService

    api

    private

    Parameters

    • sid: SID
    • uid: UID
    • cb: function
        • (err: Error | null, result?: void): void
        • Parameters

          • err: Error | null
          • Optional result: void

          Returns void

    Returns void

create

  • Create and return internal session.

    memberof

    SessionService

    api

    private

    Parameters

    • sid: SID

      uniqe id for the internal session

    • frontendId: FRONTENDID

      frontend server in which the internal session is created

    • socket: ISocket

      the underlying socket would be held by the internal session

    Returns Session

forEachBindedSession

  • forEachBindedSession(cb: function): void
  • Iterate all the binded session in the session service.

    api

    private

    Parameters

    • cb: function

      callback function to fetch session

    Returns void

forEachSession

  • forEachSession(cb: function): void

get

getByUid

getClientAddressBySessionId

  • getClientAddressBySessionId(sid: SID): any

getSessionsCount

  • getSessionsCount(): number

import

  • import(sid: SID, key: string, value: string, cb: function): void
  • Import the key/value into session.

    api

    private

    Parameters

    • sid: SID
    • key: string
    • value: string
    • cb: function
        • (err?: Error, result?: void): void
        • Parameters

          • Optional err: Error
          • Optional result: void

          Returns void

    Returns void

importAll

  • importAll(sid: SID, settings: object, cb: function): void
  • Import new value for the existed session.

    memberof

    SessionService

    api

    private

    Parameters

    • sid: SID
    • settings: object
      • [key: string]: any
    • cb: function
        • (err?: Error, result?: void): void
        • Parameters

          • Optional err: Error
          • Optional result: void

          Returns void

    Returns void

kick

  • kick(uid: UID, reason?: string, cb?: function): void
  • Kick all the session offline under the user id.

    memberof

    SessionService

    Parameters

    • uid: UID

      user id asscociated with the session

    • Optional reason: string
    • Optional cb: function

      callback function

        • (err?: Error, result?: void): void
        • Parameters

          • Optional err: Error
          • Optional result: void

          Returns void

    Returns void

kickBySessionId

  • kickBySessionId(sid: SID, reason?: string, cb?: function): void
  • Kick a user offline by session id.

    memberof

    SessionService

    Parameters

    • sid: SID

      session id

    • Optional reason: string
    • Optional cb: function

      callback function

        • (err?: Error, result?: void): void
        • Parameters

          • Optional err: Error
          • Optional result: void

          Returns void

    Returns void

remove

  • remove(sid: SID): void

sendMessage

  • sendMessage(sid: SID, msg: any): boolean
  • Send message to the client by session id.

    memberof

    SessionService

    api

    private

    Parameters

    • sid: SID

      session id

    • msg: any

      message to send

    Returns boolean

sendMessageByUid

  • sendMessageByUid(uid: UID, msg: any): boolean

unbind

  • unbind(sid: SID, uid: UID, cb: function): void
  • Unbind a session with the user id.

    memberof

    SessionService

    api

    private

    Parameters

    • sid: SID
    • uid: UID
    • cb: function
        • (err?: Error, result?: void): void
        • Parameters

          • Optional err: Error
          • Optional result: void

          Returns void

    Returns void