流星目前活跃的用户? [英] meteor currently active users?
问题描述
我在流星上做了一个简单的聊天室。我如何获得当前活跃用户的列表?有没有办法真正获得当前连接/客户端的列表?
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?
推荐答案
我昨天浏览了流星源,看看是否有已经是这样了。我找不到连接旗帜或任何东西......
I browsed the meteor sources yesterday to see if there is already anything like that. I couldn't find a connected flag or anything...
我认为你有两个选择:
-
在每个连接用户的客户端和服务器中实现心跳。我个人不太喜欢这个想法,因为这可能会导致数以万计服务器上运行的间隔时间。
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.
使用 sockjs 服务器获取打开的套接字。 Meteor.default_server.stream_server.all_sockets()
返回一个包含所有已打开套接字的数组。您可能只有一个间隔寻找其中的更改(或者您将更好地监听sockjs服务器本身的更改,有一个可能有用的 register
方法) ,将打开的套接字映射到您的用户,并使用集合将其推送到您的客户端。
每个客户都知道他的套接字ID,所以映射不应该很难。
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 a register
method 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.
这篇关于流星目前活跃的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!