Skip to content

Commit

Permalink
fix(userId): replace usedId with userId
Browse files Browse the repository at this point in the history
  • Loading branch information
Suraj-kumar00 committed Feb 2, 2025
1 parent 7db404d commit 024cb62
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions backend/src/lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ const userSocketMap = {}; // { userId: socketId }
io.on("connection", (socket) => {
console.log("A user connected", socket.id);

const usedId = socket.handshake.query.userId;
if (usedId) {
userSocketMap[usedId] = socket.id;
const userId = socket.handshake.query.userId;
if (userId) {
userSocketMap[userId] = socket.id;
}
// io.emit() is used to sends events to all connected clients
io.emit("getOnlineUsers", Object.keys(userSocketMap));

socket.on("disconnect", () => {
console.log("A user disconnected", socket.id);
delete userSocketMap[usedId];
delete userSocketMap[userId];
io.emit("getOnlineUsers", Object.keys(userSocketMap));
});
});
Expand Down

0 comments on commit 024cb62

Please sign in to comment.