@@ 48,18 48,21 @@ setInterval(function () {
Deno.writeTextFile(appdir + 'log', logfile)
}, 25000)
-const clients = []
+const clients = new Map()
function dispatch (msg) {
- clients.forEach(client => {
- client.send(msg)
- })
+ for (const client of clients.values()) {
+ client.send(msg);
+ }
}
+let clientId = 0;
+
async function wsHandler (ws) {
- clients.push(ws)
+ const id = ++clientId;
+ clients.set(id, ws);
for await (const msg of ws) {
- if (typeof msg === "string"){
+ if (typeof msg === "string") {
if (msg.length > 44) {
if (!log.includes(msg)) {
log.push(msg)
@@ 81,11 84,12 @@ async function wsHandler (ws) {
}
}
dispatch(msg);
- } /*else if (isWebSocketCloseEvent(msg)) {
+ }
+ else if (isWebSocketCloseEvent(msg)) {
clients.delete(id);
dispatch(`Closed: [${id}]`);
- break
- }*/
+ break;
+ }
}
}