Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SocketIO event filtering #50

Merged
merged 4 commits into from
Apr 8, 2014
Merged

SocketIO event filtering #50

merged 4 commits into from
Apr 8, 2014

Conversation

daffl
Copy link
Member

@daffl daffl commented Apr 6, 2014

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:

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:

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

Closes #44, closes #48.

@daffl daffl added this to the 0.4.0 milestone Apr 6, 2014
@daffl
Copy link
Member Author

daffl commented Apr 6, 2014

This is probably the biggest feature for the next release so we should make sure that this works nicely.

/cc @Glavin001, @ekryski

@Glavin001
Copy link
Contributor

This will be great! I'll try and test it out tomorrow.

@daffl
Copy link
Member Author

daffl commented Apr 6, 2014

So #51 is based on this PR and implements the whole thing for Primus which I think should finalize this functionality.

@daffl
Copy link
Member Author

daffl commented Apr 7, 2014

If there are no comments or concerns I'll merge this one and #51 in tonight so that we can get a 0.4.0 out this week.

@Glavin001
Copy link
Contributor

👍 I looked over all of the changes and everything looked good. I have not had a chance to personal test it, but I didn't notice any missing Tests either and Travis CI is still happy.
Merge away! This is going to be an awesome feature for 0.4.0

daffl added a commit that referenced this pull request Apr 8, 2014
@daffl daffl merged commit a887226 into master Apr 8, 2014
@daffl daffl deleted the event-filtering branch April 8, 2014 00:57
daffl pushed a commit that referenced this pull request Aug 19, 2018
* chore(package): update semistandard to version 11.0.0

https://greenkeeper.io/

* Fix for latest Semistandard
daffl pushed a commit that referenced this pull request Aug 21, 2018
* chore(package): update semistandard to version 11.0.0

https://greenkeeper.io/

* Fix for latest Semistandard
daffl added a commit that referenced this pull request Aug 21, 2018
daffl added a commit that referenced this pull request Aug 22, 2018
daffl pushed a commit that referenced this pull request Aug 23, 2018
daffl added a commit that referenced this pull request Aug 25, 2018
daffl added a commit that referenced this pull request Aug 29, 2018
* Rename repository and use npm scope

* Update debug dependency
daffl added a commit that referenced this pull request Aug 29, 2018
* Rename repository and use npm scope

* Update debug dependency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants