Skip to content
Browse files

cleaned up the way our server sockets setup their listeners

  • Loading branch information...
1 parent 4317493 commit 5d00f76db5a1d5c9076f56335fc9c8ba9de719a8 Montana Rowe committed
Showing with 13 additions and 8 deletions.
  1. +13 −8 chat_app/server.js
View
21 chat_app/server.js
@@ -10,6 +10,8 @@
// getUser
// delUser
// MySocket
+// events
+// listener
// setname
// getUsers
// message
@@ -66,15 +68,18 @@ function delUser(name){
//a class for our sockets
function MySocket(socket){
this.socket = socket;
- for(var k in this.callbacks)
- this.socket.on(k, this[k]);
+ for(var i = 0; i < this.events.length; i++)
+ this.listenOn(this.events[i]);
+}
+MySocket.prototype.events = [
+ "setname",
+ "getUsers",
+ "message",
+ "disconnect"
+];
+MySocket.prototype.listenOn = function listenOn(name){
+ this.socket.on(name, this[name]);
}
-MySocket.prototype.callbacks = {
- setname: 1,
- getUsers: 1,
- message: 1,
- disconnect: 1
-};
MySocket.prototype.setname = function setname(name,fn){
if(getUser(name)){
fn(true);

0 comments on commit 5d00f76

Please sign in to comment.
Something went wrong with that request. Please try again.