send users to rawcomm

This commit is contained in:
2026-04-04 10:14:55 +02:00
parent 29301297bc
commit 134649f87e
3 changed files with 29 additions and 20 deletions
+25
View File
@@ -0,0 +1,25 @@
const storage = require('./storage');
const WebSocket = require('ws');
const rawComm = new WebSocket.Server({ noServer: true });
rawComm.on('connection', (ws, request) => {
const { isAdminAuthenticated } = request.session || {};
if(!isAdminAuthenticated) {
ws.close(1008, "No admin");
return;
}
ws.on('message', (message) => {
storage.ctl_output.write(`${message.toString()}\n`);
});
});
storage.websocket_delegation.set("/rawcomm", rawComm);
function send_to_rawcomm(data) {
rawComm.clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) client.send(data);
});
}
module.exports = send_to_rawcomm;