Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[api] Cleanup primary socket.io handler. Switched to singular resourc…

…e name.
  • Loading branch information...
commit 8f2b1115d3d367caad3e8989f07f1f82c7bf8022 1 parent 2dbce2d
@Marak Marak authored
Showing with 14 additions and 14 deletions.
  1. +14 −14 lib/engines/socketio.js
View
28 lib/engines/socketio.js
@@ -7,31 +7,31 @@ engine.createServer = function (resources, options, callback) {
}
});
io.sockets.on('connection', function (socket) {
-
- //
- // Extend CRUD methods
- //
resources.forEach(function(resource) {
- socket.on(resource.lowerResource + 's', function (action, payload, callback) {
-
+ //
+ // For every resource, create a new socket.io handler
+ //
+ socket.on(resource.lowerResource, function (action, payload, callback) {
+ //
+ // Remark: Delegate the resource action to the appropiate engine method
+ //
+
+ //
+ // CRUD methods
+ //
if(typeof engine[action] === 'function') {
return engine[action](resource, payload, callback);
}
+ //
+ // Abritrary remote methods
+ //
if(typeof resource[action] === 'function' && resource[action].remote) {
return resource[action](payload.id, payload, callback);
}
-
return callback(new Error(action + ' is not a valid action.'));
-
});
});
-
-
- //
- // Extend abritrary remote methods
- //
-
socket.on('disconnect', function () {
console.log('got a disconnect');
});
Please sign in to comment.
Something went wrong with that request. Please try again.