feature/IO-3096-GlobalNotifications - Check-point
This commit is contained in:
7
server/utils/consoleDir.js
Normal file
7
server/utils/consoleDir.js
Normal 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;
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user