Permalink
Browse files

stuffed our socket into a class, barely

  • Loading branch information...
1 parent 0c3c82c commit 2e1dfd4254bfce3c599f80d1d4725d8a0f57e07c Montana Rowe committed Feb 27, 2012
Showing with 15 additions and 0 deletions.
  1. +15 −0 chat_app/server.js
View
@@ -89,10 +89,25 @@ function handleDisconnect(){
io.sockets.emit("users",users);
}
function handleSocketConnect(socket){
+ return new MySocket(socket);
socket.on("setname", handleSetname);
socket.on("getUsers", handleGetUsers);
socket.on("message", handleMessage);
socket.on("disconnect", handleDisconnect);
}
+//our sockets as a class
+function MySocket(socket){
+ this.socket = socket;
+ for(var k in this.callbacks)
+ this.socket.on(k, this.calbacks[k]);
+}
+MySocket.prototype.callbacks = {
+ setname: handleSetname,
+ getUsers: handleGetUsers,
+ message: handleMessage,
+ disconnect: handleDisconnect
+};
+
+
io.sockets.on("connection", handleSocketConnect);

0 comments on commit 2e1dfd4

Please sign in to comment.