Files
dpu-shared/dist/sse.js
2026-02-05 04:31:54 +01:00

21 lines
619 B
JavaScript

import { logInfo } from "./logger.js";
export class SseService {
clients = new Map();
addClient(client) {
this.clients.set(client.id, client);
logInfo(`SSE client connected: ${client.id}. Total clients: ${this.clients.size}`);
}
removeClient(clientId) {
this.clients.delete(clientId);
logInfo(`SSE client disconnected: ${clientId}. Total clients: ${this.clients.size}`);
}
notifyClients(event) {
for (const client of this.clients.values()) {
client.send(event);
}
}
getClientCount() {
return this.clients.size;
}
}