feature/IO-3096-GlobalNotifications - Check-point

This commit is contained in:
Dave Richer
2025-02-10 11:24:20 -05:00
parent 6d343e9b7f
commit ba2d03176f
8 changed files with 203 additions and 51 deletions

View File

@@ -0,0 +1,7 @@
const { inspect } = require("node:util");
const consoleDir = (data) => {
console.log(inspect(data, { showHidden: false, depth: null, colors: true }));
};
module.exports = consoleDir;

View File

@@ -121,6 +121,27 @@ const applyRedisHelpers = ({ pubClient, app, logger }) => {
}
};
const addUserSocketMapping = async (email, socketId) => {
// Using a Redis set allows a user to have multiple active socket ids.
console.log(`Adding socket ${socketId} to user ${email}`);
return pubClient.sadd(`user:${email}:sockets`, socketId);
};
const removeUserSocketMapping = async (email, socketId) => {
console.log(`Removing socket ${socketId} from user ${email}`);
return pubClient.srem(`user:${email}:sockets`, socketId);
};
const getUserSocketMapping = async (email) => {
const key = `user:${email}:sockets`;
try {
return await pubClient.smembers(key);
} catch (error) {
console.error(`Error retrieving socket IDs for ${email}:`, error);
throw error;
}
};
const api = {
setSessionData,
getSessionData,
@@ -133,7 +154,10 @@ const applyRedisHelpers = ({ pubClient, app, logger }) => {
clearList,
addUserToRoom,
removeUserFromRoom,
getUsersInRoom
getUsersInRoom,
addUserSocketMapping,
removeUserSocketMapping,
getUserSocketMapping
};
Object.assign(module.exports, api);