How to publish/subscribe custom list?

Hello,

I am working on an admin panel where you can give roles and groups to users.
Nothing hard in that. The thing is that I use the Roles package and to get all groups I have to call Roles.getAllRoles(); on the server.

I would like to be able to publish that, but how ? What do I call on the client once he’s subscribed ?

rXp

You should check out the added, changed, removed and ready methods of publications. This is a post I made while ago, which may give you some hints as to how to achieve this:

Alternatively, if you don’t need a reactive pub/sub, you could just call a method to get the current set of roles.

1 Like

IF the roles or groups are somewhat saved they should be in a Mongo Collection and then its a normal subscribe/publish pattern

2 Likes

Thanks I looked into it, so I would need to check every x seconds if something was changed/added/deleted and if it was I should push the change to the client ?

I understand that but I can only subscribe to a collection right ? If I do Roles.getAllRoles… I get a cursor.
I guess I’m a bit lost to publish/subscribe collections that I do not have direct control over.

Not necessarily. That example was polling a REST endpoint.

  • If you persist your roles/groups to MongoDB, you can do as @xan4fun suggests.
  • If the roles/groups are reasonably static, you may be able to use call/method.
  • If the roles/groups change as a result of changes to the Meteor users (or other) collection, you could set up an observer on that to kick off the appropriate action.
  • Only if the roles/groups data is changing frequently, and is otherwise independent of anything else in your app (like my REST endpoint), should you resort to polling.
1 Like

Thanks you :slight_smile:
It makes things clear.