socketio/socket.io-adapter

Promisify socketRooms

DavraYoung opened this issue · 3 comments

Let's make socketRooms return promise.

Sometimes it's usefull to know what rooms the specific socket is in. In single node, the Adapter.socketRooms(socketId) function works as intended.

However, with multiple socket.io servers connected through socket.io-redis adapter, it is impossible to know what rooms the socket is in, if the socket is from different node.

Making Adapter.socketRooms function to return promise will allow other adapters to implement logic of getting socket rooms even if the socket is not stored in current node.

Hi! I was thinking about adding this feature with: 1c9827e

Syntax (open to discussion):

const sockets = await io.in("room3").fetchSockets();
for (const socket of sockets) {
  console.log(socket.rooms); // along with id & handshake
}

What do you think?

I needed to collect socket ids in order make them leave certain rooms and that functinality was covered in recent commit here. Thanks)

Good news, thanks a lot for the feedback 🙏