In the 0.9.x version, we can get socket by ID like this:
io.sockets.socket(socketId)
But in 1.0.x we can't. How to find a socket by id in 1.0.x?
In the 0.9.x version, we can get socket by ID like this:
io.sockets.socket(socketId)
But in 1.0.x we can't. How to find a socket by id in 1.0.x?
You can also use fetchSockets()
function to fetch the connection using socketId like below.
const sockets = await io.in(theSocketId).fetchSockets();
This solution works perfectly with socket.io redis/adaptor. For more API documentation, refer here https://socket.io/docs/v4/server-api/#namespacesockets
For socket.io 1.0 use:
For 0.9 its io.sockets.sockets[socketId] and not io.sockets.socket[socketId]