SocketIO 3 -> Server API -> get socket objects by ID? #3804
-
According to docs I can do:
....and receive all connected socket IDs. But how to retrieve the actual socket objects based on those IDs? 🤔 |
Beta Was this translation helpful? Give feedback.
Answered by
darrachequesne
Feb 15, 2021
Replies: 1 comment 3 replies
-
You can use the for (const [id, socket] of io.of("/").sockets) {
console.log(id, socket.handshake);
} Please note that this Map contains only the socket instances on the current Socket.IO server, while the |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
tgbv
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the
namespace#sockets
attribute:Please note that this Map contains only the socket instances on the current Socket.IO server, while the
allSockets()
method returns all socket IDs across multiple Socket.IO servers.