feathersjs/feathers — pull request #50 by daffl (2014-04-06 02:20:44+00:00)
Title: SocketIO event filtering

This pull request implements event filtering for SocketIO. Letting you filter events based on the connected client information. For example the following only dispatches the `updated` event if the authorized user is in the same company than the updated todo:

```js
app.configure(feathers.socketio(function(io) {
io.set('authorization', function (handshake, callback) {
// Authorize using the /users service
app.lookup('users').find({
username: handshake.username,
password: handshake.password
}, function(error, user) {
if(!error || !user) {
return callback(error, false);
}

handshake.feathers = {
user: user
};

callback(null, true);
});
});
}));

app.use('todos', {
update: function(id, data, params, callback) {
// Update
callback(null, data);
},

updated: function(todo, params, callback) {
// params === handshake.feathers
if(todo.companyId === params.user.companyId) {
// Dispatch the todo data to this client
return callback(null, todo);
}

// Call back with a falsy value to prevent dispatching
callback(null, false);
}
});
```

On the client:

```js
socket.on('todo updated', function(data) {
// The client will only get this event
// if authorized and in the same company
});
```

Closes #44, closes #48.