mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-07-31 17:29:19 +02:00
rename
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/* Libraries / Imports */
|
/* Libraries / Imports */
|
||||||
const { send_xrd_online } = require('./xrd_server');
|
const { send_xdr_online } = require('./xdr_server');
|
||||||
const RDSDecoder = require("./rds.js");
|
const RDSDecoder = require("./rds.js");
|
||||||
const { serverConfig } = require('./server_config');
|
const { serverConfig } = require('./server_config');
|
||||||
|
|
||||||
@@ -274,7 +274,7 @@ checkSerialPortStatus();
|
|||||||
function showOnlineUsers(currentUsers) {
|
function showOnlineUsers(currentUsers) {
|
||||||
dataToSend.users = currentUsers;
|
dataToSend.users = currentUsers;
|
||||||
initialData.users = currentUsers;
|
initialData.users = currentUsers;
|
||||||
send_xrd_online(currentUsers);
|
send_xdr_online(currentUsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
let prevFreq = initialData.freq || '87.500';
|
let prevFreq = initialData.freq || '87.500';
|
||||||
|
|||||||
+2
-2
@@ -7,7 +7,7 @@ const dataHandler = require('./datahandler');
|
|||||||
const storage = require('./storage');
|
const storage = require('./storage');
|
||||||
const consoleCmd = require('./console');
|
const consoleCmd = require('./console');
|
||||||
const { serverConfig, configSave } = require('./server_config');
|
const { serverConfig, configSave } = require('./server_config');
|
||||||
const { send_to_xrd } = require("./xrd_server")
|
const { send_to_xdr } = require("./xdr_server")
|
||||||
|
|
||||||
let geoip = null;
|
let geoip = null;
|
||||||
try {
|
try {
|
||||||
@@ -276,7 +276,7 @@ function resolveDataBuffer(data, wss, rdsWss) {
|
|||||||
|
|
||||||
if (receivedData.length) {
|
if (receivedData.length) {
|
||||||
dataHandler.handleData(wss, receivedData, rdsWss);
|
dataHandler.handleData(wss, receivedData, rdsWss);
|
||||||
send_to_xrd(receivedData);
|
send_to_xdr(receivedData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -117,7 +117,7 @@ function connectToSerial() {
|
|||||||
pluginsApi.setOutput(serialport);
|
pluginsApi.setOutput(serialport);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
serialport.write('x\n');
|
serialport.write('x\n');
|
||||||
}, 2500);
|
}, 1000);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
serialport.write('Q0\n');
|
serialport.write('Q0\n');
|
||||||
@@ -456,7 +456,7 @@ wss.on('connection', (ws, request) => {
|
|||||||
}, 10000);
|
}, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentUsers === 0 && serverConfig.autoShutdown === true && serverConfig.xdrd.wirelessConnection === true) client.write('X\n');
|
if (currentUsers === 0 && serverConfig.autoShutdown === true && serverConfig.xdrd.wirelessConnection) client.write('X\n');
|
||||||
|
|
||||||
if (code !== 1008) logInfo(`Web client \x1b[31mdisconnected\x1b[0m (${clientIp}) \x1b[90m[${currentUsers}]`);
|
if (code !== 1008) logInfo(`Web client \x1b[31mdisconnected\x1b[0m (${clientIp}) \x1b[90m[${currentUsers}]`);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
const storage = require('./storage');
|
const storage = require('./storage');
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const xrd = new WebSocket.Server({ noServer: true });
|
const xdr = new WebSocket.Server({ noServer: true });
|
||||||
const { serverConfig } = require('./server_config');
|
const { serverConfig } = require('./server_config');
|
||||||
|
|
||||||
let currentUsers = 0;
|
let currentUsers = 0;
|
||||||
let clients = []
|
let clients = []
|
||||||
|
|
||||||
function send_to_xrd(data) {
|
function send_to_xdr(data) {
|
||||||
clients.forEach((client) => {
|
clients.forEach((client) => {
|
||||||
if (client.readyState === WebSocket.OPEN) client.send(data);
|
if (client.readyState === WebSocket.OPEN) client.send(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function send_xrd_online(fmusers) {
|
function send_xdr_online(fmusers) {
|
||||||
send_to_xrd(`o${currentUsers},${fmusers}\n`);
|
send_to_xdr(`o${currentUsers},${fmusers}\n`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function randomString(length) {
|
function randomString(length) {
|
||||||
@@ -26,7 +26,7 @@ function randomString(length) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function xrd_auth(ws, salt) {
|
function xdr_auth(ws, salt) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const expected = crypto.createHash('sha1')
|
const expected = crypto.createHash('sha1')
|
||||||
.update(salt + serverConfig.password.adminPass).digest('hex');
|
.update(salt + serverConfig.password.adminPass).digest('hex');
|
||||||
@@ -44,14 +44,14 @@ function xrd_auth(ws, salt) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
xrd.on('connection', async (ws, request) => {
|
xdr.on('connection', async (ws, request) => {
|
||||||
const { initialData } = require('./datahandler');
|
const { initialData } = require('./datahandler');
|
||||||
|
|
||||||
const salt = randomString(16);
|
const salt = randomString(16);
|
||||||
ws.send(`${salt}\n`);
|
ws.send(`${salt}\n`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await xrd_auth(ws, salt);
|
await xdr_auth(ws, salt);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ws.send("a0\n");
|
ws.send("a0\n");
|
||||||
ws.close(1008, err.message);
|
ws.close(1008, err.message);
|
||||||
@@ -59,7 +59,7 @@ xrd.on('connection', async (ws, request) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentUsers++;
|
currentUsers++;
|
||||||
send_xrd_online(initialData.users);
|
send_xdr_online(initialData.users);
|
||||||
ws.send(`T${initialData.freq * 1000}\n`);
|
ws.send(`T${initialData.freq * 1000}\n`);
|
||||||
ws.send(`G${initialData.eq}${initialData.ims}\n`);
|
ws.send(`G${initialData.eq}${initialData.ims}\n`);
|
||||||
ws.send(`Z${initialData.ant}\n`);
|
ws.send(`Z${initialData.ant}\n`);
|
||||||
@@ -80,12 +80,12 @@ xrd.on('connection', async (ws, request) => {
|
|||||||
|
|
||||||
ws.on('close', () => {
|
ws.on('close', () => {
|
||||||
currentUsers--;
|
currentUsers--;
|
||||||
send_xrd_online(initialData.users);
|
send_xdr_online(initialData.users);
|
||||||
|
|
||||||
clients = clients.filter(client => client !== ws);
|
clients = clients.filter(client => client !== ws);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
storage.websocket_delegation.set("/xrd", xrd);
|
storage.websocket_delegation.set("/xdr", xdr);
|
||||||
|
|
||||||
module.exports = { send_to_xrd, send_xrd_online };
|
module.exports = { send_to_xdr, send_xdr_online };
|
||||||
Reference in New Issue
Block a user