rc-web@69: rc-web@69: /*! rc-web@69: * socket.io-node rc-web@69: * Copyright(c) 2011 LearnBoost rc-web@69: * MIT Licensed rc-web@69: */ rc-web@69: rc-web@69: /** rc-web@69: * Expose the constructor. rc-web@69: */ rc-web@69: rc-web@69: exports = module.exports = Store; rc-web@69: rc-web@69: /** rc-web@69: * Module dependencies. rc-web@69: */ rc-web@69: rc-web@69: var EventEmitter = process.EventEmitter; rc-web@69: rc-web@69: /** rc-web@69: * Store interface rc-web@69: * rc-web@69: * @api public rc-web@69: */ rc-web@69: rc-web@69: function Store (options) { rc-web@69: this.options = options; rc-web@69: this.clients = {}; rc-web@69: }; rc-web@69: rc-web@69: /** rc-web@69: * Inherit from EventEmitter. rc-web@69: */ rc-web@69: rc-web@69: Store.prototype.__proto__ = EventEmitter.prototype; rc-web@69: rc-web@69: /** rc-web@69: * Initializes a client store rc-web@69: * rc-web@69: * @param {String} id rc-web@69: * @api public rc-web@69: */ rc-web@69: rc-web@69: Store.prototype.client = function (id) { rc-web@69: if (!this.clients[id]) { rc-web@69: this.clients[id] = new (this.constructor.Client)(this, id); rc-web@69: } rc-web@69: rc-web@69: return this.clients[id]; rc-web@69: }; rc-web@69: rc-web@69: /** rc-web@69: * Destroys a client rc-web@69: * rc-web@69: * @api {String} sid rc-web@69: * @param {Number} number of seconds to expire client data rc-web@69: * @api private rc-web@69: */ rc-web@69: rc-web@69: Store.prototype.destroyClient = function (id, expiration) { rc-web@69: if (this.clients[id]) { rc-web@69: this.clients[id].destroy(expiration); rc-web@69: delete this.clients[id]; rc-web@69: } rc-web@69: rc-web@69: return this; rc-web@69: }; rc-web@69: rc-web@69: /** rc-web@69: * Destroys the store rc-web@69: * rc-web@69: * @param {Number} number of seconds to expire client data rc-web@69: * @api private rc-web@69: */ rc-web@69: rc-web@69: Store.prototype.destroy = function (clientExpiration) { rc-web@69: var keys = Object.keys(this.clients) rc-web@69: , count = keys.length; rc-web@69: rc-web@69: for (var i = 0, l = count; i < l; i++) { rc-web@69: this.destroyClient(keys[i], clientExpiration); rc-web@69: } rc-web@69: rc-web@69: this.clients = {}; rc-web@69: rc-web@69: return this; rc-web@69: }; rc-web@69: rc-web@69: /** rc-web@69: * Client. rc-web@69: * rc-web@69: * @api public rc-web@69: */ rc-web@69: rc-web@69: Store.Client = function (store, id) { rc-web@69: this.store = store; rc-web@69: this.id = id; rc-web@69: };