Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 5e030c1ff3b6d4d6b73e1d6f18537c95b9f444fa @dmongeau dmongeau committed Dec 4, 2012
Showing with 97 additions and 0 deletions.
  1. +20 −0 LICENSE
  2. +4 −0 README.md
  3. +49 −0 index.js
  4. +24 −0 package.json
@@ -0,0 +1,20 @@
+node-client-manager: Copyright (c) 2010 David Mongeau-Petitpas
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
+Client-manager
+===========
+
+A really simple script to manage clients
@@ -0,0 +1,49 @@
+
+var EventEmitter = require('events').EventEmitter;
+
+var ClientManager = function() {
+
+ //Call eventemitter constructor
+ EventEmitter.call(this);
+
+ this.count = 0;
+ this.clients = {};
+ this.clientsQueue = [];
+
+};
+
+//Extend EventEmitter
+ClientManager.prototype = Object.create(EventEmitter.prototype);
+
+
+ClientManager.prototype.addClient = function(id,client) {
+ this.clients[id] = client;
+ this.clientsQueue.push(id);
+ this.count = this.clientsQueue.length;
+
+ if(this.count == 0) {
+ this.emit('add',client);
+ }
+};
+
+ClientManager.prototype.removeClient = function(id) {
+ this.clients[id] = null;
+ var newClientsQueue = [];
+ for(var i = 0; i < this.clientsQueue.length; i++) {
+ if(this.clientsQueue[i] != id) {
+ newClientsQueue.push(this.clientsQueue[i]);
+ }
+ }
+ this.clientsQueue = newClientsQueue;
+ this.count = this.clientsQueue.length;
+
+ if(this.count == 0) {
+ this.emit('empty');
+ }
+};
+
+function factory() {
+ return new ClientManager();
+}
+
+module.exports = exports = factory;
@@ -0,0 +1,24 @@
+{
+ "name": "client-manager",
+ "description" : "A really simple script to manage clients",
+ "keywords" : [
+ "clients",
+ "socket",
+ "manager"
+ ],
+ "author": "Folklore <info@atelierfolklore.ca>",
+ "maintainers": [
+ "David Mongeau-Petitpas <dmp@atelierfolklore.ca>"
+ ],
+ "version": "0.0.1",
+ "dependencies": {},
+ "main": "index.js",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/Folkloreatelier/node-client-manager.git"
+ },
+ "license": {
+ "type": "MIT",
+ "url": "http://github.com/Folkloreatelier/node-client-manager/raw/master/LICENSE"
+ }
+}

0 comments on commit 5e030c1

Please sign in to comment.