Poh Zi How
Poh Zi How

Reputation: 1569

Meteor: display list of current users for document

I have a list of documents in meteor that only authorised users can access. It's kind of like google docs. Is there an easy way to get a list of users which are currently viewing them?

I thought of including a "currentUsers" field in my mongodb object, and push/remove users whenever users view or stop viewing the component. This feels like a strange way to do it since data is persisted and is probably prone to errors since it doesn't exactly represent users currently viewing the component at a moment in time

This stackoverflow question is kind of what I'm looking for, but the answer is a little old, and I'm not sure how to go about using sockjs either. If someone can provide a working example that will be great.

Any help is greatly appreciated!

Upvotes: 6

Views: 220

Answers (2)

App Nucleus
App Nucleus

Reputation: 66

You can easily find that like this-

Tracker.autorun(function() {
  if (Meteor.user()) {
    Meteor.subscribe('userList');
  }
});

More can be found from here.

Upvotes: 0

metalcamp
metalcamp

Reputation: 546

There are several options:

DIY solution - storing data in Collection

package meteor-user-status https://github.com/mizzao/meteor-user-status

package mrt:spy (which seems to be deprecated, but maybe you can build on top of it) https://atmospherejs.com/mrt/spy

socket.io https://atmospherejs.com/joncursi/socket-io-client

Upvotes: 4

Related Questions