I’m making a simple chatroom in meteor. How would I get a list of currently active users? Is there a way to actually get a list of current connections / clients?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I browsed the meteor sources yesterday to see if there is already anything like that. I couldn’t find a connected flag or anything…
I think you’ll have two options:
Implement a heartbeat in the client and the server for every connected user. I personally don’t like this idea very much, as this could result in zillions of intervals running on your server.
Use the sockjs server to get the open sockets.
Meteor.default_server.stream_server.all_sockets()returns an array with all opened sockets. You could than have a single interval looking for changes in that (or better you’ll listen to changes of the sockjs server itself, there is aregistermethod that could be useful), map the open sockets with your users and use a collection to push it to your clients.Each client knows his socket id, so the mapping shouldnt be to hard.
I didn’t implement it yet, so these are only ideas where to start.