io.sockets.sockets deprecated - get all sockets in v3.
See original GitHub issueIt seems that io.sockets.sockets
is deprecated in v3 and following does not work anymore:
socket.userId = id;
// Later
for (let s in io.sockets.sockets) {
let socket = io.sockets.sockets[s];
if (socket.userId === ...) {
socket.emit(f, ...params);
}
}
Tried also following (https://socket.io/docs/server-api/#namespace-clients-callback)…
io.clients((error, clients) => {
if (error) throw error;
console.log(clients);
});
But:
Uncaught TypeError: io.clients is not a function
Also io.engine.clients
does not seem to expose client’s socket object, so if that’s the only way, I’d need to make custom client-id to userId table and try to keep it in sync, which feels bad idea. And if it really is, how it should be used exactly?
socket.on('v3test', function() {
console.log(socket.id);
for (let s in io.engine.clients) {
let socket2 = io.engine.clients[s];
console.log(socket2.id);
}
});
In localhost with 1 client you’d expect 2 identical ids, but:
a9C3bHfHsfoA1aPJAAAB
FrOECbewjLGBnAzFAAAA
Please advice how to go through all connected clients in v3?
(and to clarify, the room approach is not viable in this case as the exact recipients are checked case-by-case)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Migrating from 2.x to 3.0 - Socket.IO
The connected object (used to store all the Socket connected to the given Namespace) could be used to retrieve a Socket object from...
Read more >How do I get a list of connected sockets/clients with Socket.IO?
In Socket.IO 0.7 you have a clients method on the namespaces. This returns an array of all connected sockets. API for no namespace:...
Read more >ssl — TLS/SSL wrapper for socket objects — Python 3.11.1 ...
SSL version 3 is insecure. Its use is highly discouraged. Deprecated since version 3.6: OpenSSL has deprecated all version specific protocols. Use the...
Read more >@types/socket.io - npm
This package has been deprecated. Author message: This is a stub types definition. socket.io provides its own type definitions, ...
Read more >Reading from and Writing to a Socket (The Java™ Tutorials ...
The EchoClient example creates a socket, thereby getting a connection to the echo server. It reads input from the user on the standard...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, totally 👍
I’m having to do a major refactor on multiple package implementations after a hiatus from a project.
I used to have:
within:
In order to use
await
(per the examples here):The containing function needs to be
async
.It is allowed to make
io.on('connection', (socket) => {
an async function?