From 734bc7681b88042d8979107e1709dff49cdbc87a Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 21 Jul 2022 19:48:46 +0530 Subject: [PATCH] fix(realtime): "X is viewing" doc broken --- socketio.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/socketio.js b/socketio.js index d393d7145b..9efde8c890 100644 --- a/socketio.js +++ b/socketio.js @@ -292,21 +292,14 @@ function send_users(args, action) { const room = action == 'view' ? open_doc_room: get_typing_room(args.socket, args.doctype, args.docname); - const socketio_room = io.sockets.adapter.rooms[room] || {}; - // for compatibility with both v1.3.7 and 1.4.4 - const clients_dict = ('sockets' in socketio_room) ? socketio_room.sockets : socketio_room; - - // socket ids connected to this room - const clients = Object.keys(clients_dict || {}); + const clients = Array.from(io.sockets.adapter.rooms.get(room) || []); let users = []; - for (let i in io.sockets.sockets) { - const s = io.sockets.sockets[i]; - if (clients.indexOf(s.id) !== -1) { - // this socket is connected to the room - users.push(s.user); + io.sockets.sockets.forEach((sock) => { + if (clients.includes(sock.id)) { + users.push(sock.user); } - } + }) const emit_event = action == 'view' ? 'doc_viewers' : 'doc_typers';