diff --git a/backend/collaboration-service/handler/socketHandler.js b/backend/collaboration-service/handler/socketHandler.js index 38c808aa91..e07524c8c6 100644 --- a/backend/collaboration-service/handler/socketHandler.js +++ b/backend/collaboration-service/handler/socketHandler.js @@ -19,14 +19,16 @@ const handleSocketIO = (io) => { socket.on("createSocketRoom", async ({ data, id, currentUser }) => { // Store the socket id for the user socketMap[currentUser] = socket.id; + socket.roomId = id; socket.join(id); console.log(`User with socket ID ${socket.id} joined room with ID ${id}`); if (activeUserInRoom[id]) { - activeUserInRoom[id] = 1 - } else { activeUserInRoom[id] = activeUserInRoom[id] + 1 + } else { + activeUserInRoom[id] = 1 } + console.log(`UactiveUserInRoom[id]: ${activeUserInRoom[id]}`); const room = io.sockets.adapter.rooms.get(id); @@ -71,7 +73,7 @@ const handleSocketIO = (io) => { if (haveNewData[id]) { haveNewData[id] = false; await collabRef.update(periodicData); - console.log(`Collab Data updated to Firebase at ${currentTime}`); + console.log(`Collab Data for roomid ${id} updated to Firebase at ${currentTime}`); } } else { @@ -79,7 +81,7 @@ const handleSocketIO = (io) => { roomId: id, ...periodicData }); - console.log(`New Collab page recorded to Firebase at ${currentTime}`); + console.log(`New Collab page for roomid ${id} recorded to Firebase at ${currentTime}`); } } catch (error) { @@ -117,6 +119,7 @@ const handleSocketIO = (io) => { activeUserInRoom[socket.roomId] = activeUserInRoom[socket.roomId] - 1; if(activeUserInRoom[socket.roomId] == 0) { + console.log(`All users in roomId ${socket.roomId} disconnected, deleting room data`); delete activeUserInRoom[socket.roomId]; clearInterval(intervalMap[socket.roomId]); @@ -133,7 +136,7 @@ const handleSocketIO = (io) => { break; } } - console.log(`User with socket ID ${socket.id} disconnected`); + console.log(`User with socket ID ${socket.id} disconnected, leaving ${socket.roomId}`); });