Advertisement
Guest User

Untitled

a guest
Sep 15th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. socket.on('*', function(payload, callback) {
  2.  
  3.             function callMethod(method) {
  4.                 if(socket.uid) {
  5.                     user.updateLastOnlineTime(socket.uid);
  6.                 }
  7.  
  8.                 method.call(null, socket, payload.args.length ? payload.args[0] : null, function(err, result) {
  9.                     if (callback) {
  10.                         callback(err?{message:err.message}:null, result);
  11.                     }
  12.                 });
  13.             }
  14.  
  15.             if(!payload.name) {
  16.                 return winston.warn('[socket.io] Empty method name');
  17.             }
  18.  
  19.             var parts = payload.name.toString().split('.'),
  20.                 namespace = parts.slice(0, 1),
  21.                 methodToCall = parts.reduce(function(prev, cur) {
  22.                     if (prev !== null && prev[cur]) {
  23.                         return prev[cur];
  24.                     } else {
  25.                         return null;
  26.                     }
  27.                 }, Namespaces);
  28.  
  29.             if(!methodToCall) {
  30.                 return winston.warn('[socket.io] Unrecognized message: ' + payload.name);
  31.             }
  32.  
  33.             if (Namespaces[namespace].before) {
  34.                 Namespaces[namespace].before(socket, payload.name, function() {
  35.                     callMethod(methodToCall);
  36.                 });
  37.             } else {
  38.                 callMethod(methodToCall);
  39.             }
  40.         });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement