mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-07-30 16:59:15 +02:00
send users to rawcomm
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user