SessionService(opts)

new SessionService(opts)

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.
Parameters:
Name Type Description
opts Object constructor parameters

Methods

bind()

Bind the session with a user id.

create(sid, frontendId, socket) → {Session}

Create and return internal session.
Parameters:
Name Type Description
sid Integer uniqe id for the internal session
frontendId String frontend server in which the internal session is created
socket Object the underlying socket would be held by the internal session
Returns:
Session

forEachBindedSession(cb)

Iterate all the binded session in the session service.
Parameters:
Name Type Description
cb function callback function to fetch session

forEachSession(cb)

Iterate all the session in the session service.
Parameters:
Name Type Description
cb function callback function to fetch session

get(id) → {Session}

Get session by id.
Parameters:
Name Type Description
id Number The session id
Returns:
Session

getByUid(uid) → {Array}

Get sessions by userId.
Parameters:
Name Type Description
uid Number User id associated with the session
Returns:
Array - list of session binded with the uid

getClientAddressBySessionId(sid) → {Object}

Get client remote address by session id.
Parameters:
Name Type Description
sid Number session id
Returns:
Object - remote address of client

getSessionsCount()

Get sessions' quantity in specified server.

import()

Import the key/value into session.

importAll()

Import new value for the existed session.

kick(uid, cb)

Kick all the session offline under the user id.
Parameters:
Name Type Description
uid Number user id asscociated with the session
cb function callback function

kickBySessionId(sid, cb)

Kick a user offline by session id.
Parameters:
Name Type Description
sid Number session id
cb function callback function

remove(sid)

Remove session by key.
Parameters:
Name Type Description
sid Number The session id

sendMessage(sid, msg)

Send message to the client by session id.
Parameters:
Name Type Description
sid String session id
msg Object message to send

sendMessageByUid(uid, msg)

Send message to the client by user id.
Parameters:
Name Type Description
uid String userId
msg Object message to send

unbind()

Unbind a session with the user id.