Permalink
Browse files

pulled all function literals out of the calls to which they were passed

  • Loading branch information...
1 parent 4dc31d6 commit 158f4ec126b485deb9321ae487cb4498fc42180d Montana Rowe committed Feb 22, 2012
Showing with 31 additions and 30 deletions.
  1. +31 −30 chat_app/server.js
View
@@ -28,34 +28,35 @@ var io = sio.listen(
var users = {};
-io.sockets.on("connection", function handleSocketConnect(socket){
-
- socket.on("setname",function(name,fn){
- if(users[name]){
- fn(true);
- } else {
- fn(false);
- users[name] = socket.name = name;
- this.broadcast.emit("announcement", name + " connected.");
- io.sockets.emit("users",users);
- }
- this.emit("nameset",name);
- });
-
- socket.on("getUsers",function(){
- this.emit("users",users);
- });
-
- socket.on("message",function(message){
- io.sockets.emit("message", socket.name + ": " + message);
- });
-
- socket.on("disconnect",function(){
- if(this.name && users[this.name])
- {
- delete users[this.name];
- }
- this.broadcast.emit("announcement", this.name + " disconnected.");
+function handleSetname(name,fn){
+ if(users[name]){
+ fn(true);
+ } else {
+ fn(false);
+ users[name] = socket.name = name;
+ this.broadcast.emit("announcement", name + " connected.");
io.sockets.emit("users",users);
- });
-});
+ }
+ this.emit("nameset",name);
+}
+function handleGetUsers(){
+ this.emit("users", users);
+}
+function handleMessage(message){
+ io.sockets.emit("message", socket.name + ": " + message);
+}
+function handleDisconnect(){
+ if(this.name && users[this.name])
+ {
+ delete users[this.name];
+ }
+ this.broadcast.emit("announcement", this.name + " disconnected.");
+ io.sockets.emit("users",users);
+}
+function handleSocketConnect(socket){
+ socket.on("setname", handleSetname);
+ socket.on("getUsers", handleGetUsers);
+ socket.on("message", handleMessage);
+ socket.on("disconnect", handleDisconnect);
+}
+io.sockets.on("connection", handleSocketConnect);

0 comments on commit 158f4ec

Please sign in to comment.