This repository was archived by the owner on Aug 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Clean way to subscribe to a filtered set of events #32
Comments
This is exactly what event filters are for. Primus and other (potential) real-time providers don't have a concept of rooms and everything that rooms can do - and more complex functionality (which you almost always need) - can also be done through event filters. There are two options:
app.use(socketio(function(io) {
io.on('connection', function(socket) {
socket.on('join', function(roomId) {
socket.feathers.rooms.push(roomId);
});
});
}));
app.service('messages').filter(function(data, connection) {
return connection.rooms.indexOf(data.room) !== -1;
}); |
Yup. That will do it! I'm going to close but this has come up a few times I'm wondering if we should put it in as an example in the docs under "rooms" or "channels". I dunno... maybe people just aren't seeing the that part of the docs too.... |
I added it to the FAQ at http://docs.feathersjs.com/help/faq.html#how-do-i-create-channels-or-rooms |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Say I wanted to implement a real-time chat app with multiple chat rooms that can be created and deleted dynamically. The client who is in chat room "football buddies" wants to subscribe to the messages service but is only interested in messages to that room. If I understand feathers correctly, feathers will send all events on the message service, which might be a lot if there are a lot of small chat rooms.
Perhaps the socket.io concept of namespaces and rooms is useful here, but I'm not sure of the best way to set it up within the feathers ecosystem.
I think feathers-reactive would effectively accomplish this from the point of view of my app, but the client side is still dealing with all the useless websocket traffic, which is undesirable.
I also see that event filtering might accomplish this, but it seems like I'd need to add some server-side functionality for tracking which users are currently connected to a given chat room, which seems less clean than simply being able to subscribe to a subset of the events on a service.
Any help is appreciated.
Thanks.
The text was updated successfully, but these errors were encountered: