finishing touches

This commit is contained in:
Darius
2026-02-09 19:22:52 +01:00
parent 872d3755d0
commit 9983ba1215
6 changed files with 3 additions and 36 deletions

14
dist/ws.js vendored
View File

@@ -1,27 +1,13 @@
import { logInfo } from "./logger.js";
export class WsService {
clients = new Set();
listeners = [];
onClientChange(callback) {
this.listeners.push(callback);
return () => {
this.listeners = this.listeners.filter((cb) => cb !== callback);
};
}
emitClientChange() {
for (const callback of this.listeners) {
callback(this.clients.size);
}
}
addClient(ws) {
this.clients.add(ws);
logInfo(`Socket connected. Total clients: ${this.clients.size}`);
this.emitClientChange();
}
removeClient(ws) {
this.clients.delete(ws);
logInfo(`Socket disconnected. Total clients: ${this.clients.size}`);
this.emitClientChange();
}
broadcast(message) {
this.clients.forEach((socket) => {