123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- /**
- * Remote session service for frontend server.
- * Set session info for backend servers.
- */
- var utils = require('../../../util/utils');
- module.exports = function(app) {
- return new Remote(app);
- };
- var Remote = function(app) {
- this.app = app;
- };
- Remote.prototype.bind = function(sid, uid, cb) {
- this.app.get('sessionService').bind(sid, uid, cb);
- };
- Remote.prototype.unbind = function(sid, uid, cb) {
- this.app.get('sessionService').unbind(sid, uid, cb);
- };
- Remote.prototype.push = function(sid, key, value, cb) {
- this.app.get('sessionService').import(sid, key, value, cb);
- };
- Remote.prototype.pushAll = function(sid, settings, cb) {
- this.app.get('sessionService').importAll(sid, settings, cb);
- };
- /**
- * Get session informations with session id.
- *
- * @param {String} sid session id binded with the session
- * @param {Function} cb(err, sinfo) callback funtion, sinfo would be null if the session not exist.
- */
- Remote.prototype.getBackendSessionBySid = function(sid, cb) {
- var session = this.app.get('sessionService').get(sid);
- if(!session) {
- utils.invokeCallback(cb);
- return;
- }
- utils.invokeCallback(cb, null, session.toFrontendSession().export());
- };
- /**
- * Get all the session informations with the specified userstate id.
- *
- * @param {String} uid userstate id binded with the session
- * @param {Function} cb(err, sinfo) callback funtion, sinfo would be null if the session does not exist.
- */
- Remote.prototype.getBackendSessionsByUid = function(uid, cb) {
- var sessions = this.app.get('sessionService').getByUid(uid);
- if(!sessions) {
- utils.invokeCallback(cb);
- return;
- }
- var res = [];
- for(var i=0, l=sessions.length; i<l; i++) {
- res.push(sessions[i].toFrontendSession().export());
- }
- utils.invokeCallback(cb, null, res);
- };
- /**
- * Kick a session by session id.
- *
- * @param {Number} sid session id
- * @param {Function} cb callback function
- */
- Remote.prototype.kickBySid = function(sid, cb) {
- this.app.get('sessionService').kickBySessionId(sid, cb);
- };
- /**
- * Kick sessions by userstate id.
- *
- * @param {Number|String} uid userstate id
- * @param {Function} cb callback function
- */
- Remote.prototype.kickByUid = function(uid, cb) {
- this.app.get('sessionService').kick(uid, cb);
- };
|