fix user count broadcast timing

This commit is contained in:
jwinterm
2025-12-24 20:43:57 -05:00
parent 4a423576ac
commit 371945fc21
2 changed files with 10 additions and 3 deletions
+8 -1
View File
@@ -17,7 +17,14 @@ class BroadcastManager {
* Broadcast connected user count to all clients
*/
broadcastUserCount() {
const count = this.io.engine ? this.io.engine.clientsCount : 0;
// Try multiple ways to get the count
let count = 0;
if (this.io.sockets && this.io.sockets.sockets) {
count = this.io.sockets.sockets.size || 0;
} else if (this.io.engine) {
count = this.io.engine.clientsCount || 0;
}
// Only broadcast if count changed to avoid spam
if (count !== this._lastUserCount) {
this._lastUserCount = count;
+2 -2
View File
@@ -64,8 +64,8 @@ class ConnectionHandler {
// Send current state
this._sendConnectionStatus(socket);
// Broadcast updated user count to all clients
this.broadcastManager.broadcastUserCount();
// Broadcast updated user count to all clients (small delay to ensure socket is registered)
setTimeout(() => this.broadcastManager.broadcastUserCount(), 100);
return { sessionInfo, memUser };