Reputation: 3861
I need to list all connected clients in sails/socket, any easy way to do it?
I don't know if the best way is to use database or just get a list of users connected to the sails/socket.
Thanks in advance.
Upvotes: 3
Views: 2705
Reputation: 24958
When possible, it's best to use the built-in pubsub methods that Sails adds to models for you, documented here. Failing that, you can access low-level socket methods in v0.9.8 via sails.io
, so it would be:
var sockets = sails.io.sockets.clients();
to get an array of socket objects.
In v0.10 it will be:
var sockets = sails.sockets.subscribers();
to get an array of socket IDs, which you can use with the other sails.sockets
methods to publish messages and do other magic.
Upvotes: 6