PadMessageHandler: Fix fetching of socket.io Sockets for a pad

This commit is contained in:
Richard Hansen 2021-02-27 00:54:59 -05:00 committed by John McLear
parent 9cd67cd990
commit 392d9dcfde

View file

@ -1409,16 +1409,14 @@ const composePadChangesets = async (padId, startNum, endNum) => {
};
const _getRoomSockets = (padID) => {
const roomSockets = [];
const room = socketio.sockets.adapter.rooms[padID];
if (room) {
for (const id of Object.keys(room.sockets)) {
roomSockets.push(socketio.sockets.sockets[id]);
}
}
return roomSockets;
const ns = socketio.sockets; // Default namespace.
const adapter = ns.adapter;
// We could call adapter.clients(), but that method is unnecessarily asynchronous. Replicate what
// it does here, but synchronously to avoid a race condition. This code will have to change when
// we update to socket.io v3.
const room = adapter.rooms[padID];
if (!room) return [];
return Object.keys(room.sockets).map((id) => ns.connected[id]).filter((s) => s);
};
/**