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