set => map

This commit is contained in:
Darius
2026-02-05 04:31:54 +01:00
parent 8daeed6b5f
commit cdd2fcb59e
4 changed files with 22 additions and 26 deletions

15
dist/sse.js vendored
View File

@@ -1,21 +1,18 @@
import { logInfo } from "./logger.js";
export class SseService {
clients = new Set();
clients = new Map();
addClient(client) {
this.clients.add(client);
this.clients.set(client.id, client);
logInfo(`SSE client connected: ${client.id}. Total clients: ${this.clients.size}`);
}
removeClient(clientId) {
const client = [...this.clients].find((c) => c.id === clientId);
if (client) {
this.clients.delete(client);
logInfo(`SSE client disconnected: ${clientId}. Total clients: ${this.clients.size}`);
}
this.clients.delete(clientId);
logInfo(`SSE client disconnected: ${clientId}. Total clients: ${this.clients.size}`);
}
notifyClients(event) {
this.clients.forEach((client) => {
for (const client of this.clients.values()) {
client.send(event);
});
}
}
getClientCount() {
return this.clients.size;