feat(chat): send online user in a single socketio message

This commit is contained in:
Maieul BOYER 2025-12-18 13:51:06 +01:00 committed by Maix0
parent 41fdbfbaaa
commit bcba86ed8a
9 changed files with 42 additions and 78 deletions

View file

@ -13,6 +13,7 @@ export function connectedUser(io?: Server, target?: string): number {
let count = 0;
const seen = new Set<string>();
// <- only log/count unique usernames
const listBud: string[] = [];
for (const [socketId, username] of clientChat) {
// Basic checks
if (typeof socketId !== 'string' || socketId.length === 0) {
@ -38,11 +39,15 @@ export function connectedUser(io?: Server, target?: string): number {
// socket exists and is connected
seen.add(username.user);
count++;
const targetSocketId = target;
io.to(targetSocketId!).emit('listBud', username.user);
// const targetSocketId = target;
// io.to(targetSocketId!).emit('listBud', username.user);
listBud.push(username.user);
continue;
}
count++;
}
if (io && typeof io.sockets?.sockets?.get === 'function' && target) {
io.to(target).emit('listBud', listBud);
}
return count;
}
}