Files
dpu-shared/dist/ws.js
2026-02-09 19:22:52 +01:00

21 lines
559 B
JavaScript

import { logInfo } from "./logger.js";
export class WsService {
clients = new Set();
addClient(ws) {
this.clients.add(ws);
logInfo(`Socket connected. Total clients: ${this.clients.size}`);
}
removeClient(ws) {
this.clients.delete(ws);
logInfo(`Socket disconnected. Total clients: ${this.clients.size}`);
}
broadcast(message) {
this.clients.forEach((socket) => {
socket.send(JSON.stringify(message));
});
}
getClientCount() {
return this.clients.size;
}
}