var User = (function(){ var User = function(socket){ if(!(this instanceof User)){ return (new User(socket)); } /** * constructor here */ this.socket = socket; this._rooms = []; this._id = socket.id; this.generateName(); this._events(); }; var r = User.prototype; /** * methods && properties here * r.property = null; * r.getProperty = function() {...} */ r._id = null; r._name = null; r._rooms = null; r._inQueue = false; r.socket = null; r.disconnected = false; r.getID = function(){ return this._id; } r.send = function(event, data, room){ room = room || null; data = data || null; if(!room){ this.socket.emit(event, data); } else { this.socket.to(room).emit(event, data); } } r.generateName = function(){ var name = "Guest" + (((Math.random() * 8999) + 1000) | 0); this._name = name; return name; } r.setName = function(name) { name = name.slice(0, 20); console.log("user name changed from %s to %s", this._name, name); this._name = name; } r.getName = function() { return this._name; } r.getRoom = function() { return this._rooms[0]; } r.setDeck = function(deck) { //console.log("set deck: ", deck); this._deck = deck; } r.getDeck = function() { return this._deck; } r.addRoom = function(room) { this._rooms.push(room); } r.cleanUp = function() { for(var i=0; i