Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- socket.on('*', function(payload, callback) {
- function callMethod(method) {
- if(socket.uid) {
- user.updateLastOnlineTime(socket.uid);
- }
- method.call(null, socket, payload.args.length ? payload.args[0] : null, function(err, result) {
- if (callback) {
- callback(err?{message:err.message}:null, result);
- }
- });
- }
- if(!payload.name) {
- return winston.warn('[socket.io] Empty method name');
- }
- var parts = payload.name.toString().split('.'),
- namespace = parts.slice(0, 1),
- methodToCall = parts.reduce(function(prev, cur) {
- if (prev !== null && prev[cur]) {
- return prev[cur];
- } else {
- return null;
- }
- }, Namespaces);
- if(!methodToCall) {
- return winston.warn('[socket.io] Unrecognized message: ' + payload.name);
- }
- if (Namespaces[namespace].before) {
- Namespaces[namespace].before(socket, payload.name, function() {
- callMethod(methodToCall);
- });
- } else {
- callMethod(methodToCall);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement