From c0ad53563ef530cb2106552cfa95079ebda7409c Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Sat, 4 Apr 2026 22:19:00 +0200 Subject: [PATCH] count xrd users and also count the fm-dx users as secondary --- server/xrd_server.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/server/xrd_server.js b/server/xrd_server.js index 357d4fe..cd9fa53 100644 --- a/server/xrd_server.js +++ b/server/xrd_server.js @@ -2,6 +2,14 @@ const storage = require('./storage'); const WebSocket = require('ws'); const xrd = new WebSocket.Server({ noServer: true }); +let currentUsers = 0; + +function send_to_xrd(data) { + xrd.clients.forEach((client) => { + if (client.readyState === WebSocket.OPEN) client.send(data); + }); +} + xrd.on('connection', (ws, request) => { const { initialData } = require('./datahandler'); const { isAdminAuthenticated } = request.session || {}; @@ -10,7 +18,8 @@ xrd.on('connection', (ws, request) => { return; } - ws.send(`o${initialData.users},0\n`); + currentUsers++; + send_to_xrd(`o${currentUsers},${initialData.users}\n`); ws.send(`T${initialData.freq * 1000}\n`); ws.send(`G${initialData.eq}${initialData.ims}\n`); ws.send(`Z${initialData.ant}\n`); @@ -20,14 +29,12 @@ xrd.on('connection', (ws, request) => { ws.send(`OK\n`); ws.on('message', (message) => storage.ctl_output.write(`${message}\n`)); + ws.on('close', (code, reason) => { + currentUsers--; + send_to_xrd(`o${currentUsers},${initialData.users}\n`); + }); }); storage.websocket_delegation.set("/xrd", xrd); -function send_to_xrd(data) { - xrd.clients.forEach((client) => { - if (client.readyState === WebSocket.OPEN) client.send(data); - }); -} - module.exports = send_to_xrd; \ No newline at end of file