mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-07-31 17:29:19 +02:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2cbbdd3b9
|
||
|
|
f99ce973c1
|
||
|
|
6b5b48384f
|
||
|
|
e8d91086c7
|
||
|
|
c0ad53563e
|
||
|
|
e0753c2479
|
||
|
|
7042074b31
|
||
|
|
7ae8c4a24a
|
||
|
|
431fc937ce
|
@@ -1,5 +1,5 @@
|
||||
/* Libraries / Imports */
|
||||
const send_to_rawcomm = require('./rawcomm');
|
||||
const { send_xrd_online } = require('./xrd_server');
|
||||
const RDSDecoder = require("./rds.js");
|
||||
const { serverConfig } = require('./server_config');
|
||||
|
||||
@@ -33,7 +33,7 @@ var dataToSend = {
|
||||
ant: 0,
|
||||
txInfo: {
|
||||
tx: '', // Name
|
||||
pol: '', // Polarisation
|
||||
pol: '', // Polarization
|
||||
erp: '', // Power
|
||||
city: '',
|
||||
itu: '', // Country
|
||||
@@ -274,7 +274,7 @@ checkSerialPortStatus();
|
||||
function showOnlineUsers(currentUsers) {
|
||||
dataToSend.users = currentUsers;
|
||||
initialData.users = currentUsers;
|
||||
send_to_rawcomm(`o${currentUsers},0\n`);
|
||||
send_xrd_online(currentUsers);
|
||||
}
|
||||
|
||||
let prevFreq = initialData.freq || '87.500';
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ const dataHandler = require('./datahandler');
|
||||
const storage = require('./storage');
|
||||
const consoleCmd = require('./console');
|
||||
const { serverConfig, configSave } = require('./server_config');
|
||||
const send_to_rawcomm = require("./rawcomm")
|
||||
const { send_to_xrd } = require("./xrd_server")
|
||||
|
||||
let geoip = null;
|
||||
try {
|
||||
@@ -276,7 +276,7 @@ function resolveDataBuffer(data, wss, rdsWss) {
|
||||
|
||||
if (receivedData.length) {
|
||||
dataHandler.handleData(wss, receivedData, rdsWss);
|
||||
send_to_rawcomm(receivedData);
|
||||
send_to_xrd(receivedData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
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;
|
||||
@@ -0,0 +1,44 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
function send_xrd_online(fmusers) {
|
||||
send_to_xrd(`o${currentUsers},${fmusers}\n`);
|
||||
}
|
||||
|
||||
xrd.on('connection', (ws, request) => {
|
||||
const { initialData } = require('./datahandler');
|
||||
const { isAdminAuthenticated } = request.session || {};
|
||||
if(!isAdminAuthenticated) {
|
||||
ws.close(1008, "No admin");
|
||||
return;
|
||||
}
|
||||
|
||||
currentUsers++;
|
||||
send_xrd_online(initialData.users);
|
||||
ws.send(`T${initialData.freq * 1000}\n`);
|
||||
ws.send(`G${initialData.eq}${initialData.ims}\n`);
|
||||
ws.send(`Z${initialData.ant}\n`);
|
||||
ws.send(`A${initialData.agc}\n`);
|
||||
ws.send(`F${initialData.bw}\n`);
|
||||
ws.send(`W${initialData.bw}\n`);
|
||||
ws.send(`OK\n`);
|
||||
|
||||
ws.on('message', (message) => storage.ctl_output.write(message));
|
||||
ws.on('close', (code, reason) => {
|
||||
currentUsers--;
|
||||
send_xrd_online(initialData.users);
|
||||
});
|
||||
});
|
||||
|
||||
storage.websocket_delegation.set("/xrd", xrd);
|
||||
|
||||
module.exports = { send_to_xrd, send_xrd_online };
|
||||
Reference in New Issue
Block a user