You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-26 22:13:53 +01:00
bugfixes & plugins WS & UI fixes
This commit is contained in:
@@ -234,7 +234,9 @@ var dataToSend = {
|
||||
itu: '',
|
||||
dist: '',
|
||||
azi: '',
|
||||
id: ''
|
||||
id: '',
|
||||
reg: '',
|
||||
pi: '',
|
||||
},
|
||||
country_name: '',
|
||||
country_iso: 'UN',
|
||||
@@ -294,6 +296,7 @@ function handleData(wss, receivedData, rdsWss) {
|
||||
initialData.freq = (parsedValue / 1000).toFixed(3);
|
||||
dataToSend.freq = (parsedValue / 1000).toFixed(3);
|
||||
dataToSend.pi = '?';
|
||||
dataToSend.txInfo.reg = false;
|
||||
|
||||
rdsWss.clients.forEach((client) => {
|
||||
client.send("G:\r\nRESET-------\r\n\r\n");
|
||||
@@ -401,7 +404,9 @@ function handleData(wss, receivedData, rdsWss) {
|
||||
itu: currentTx.itu,
|
||||
dist: currentTx.distance,
|
||||
azi: currentTx.azimuth,
|
||||
id: currentTx.id
|
||||
id: currentTx.id,
|
||||
pi: currentTx.pi,
|
||||
reg: currentTx.reg
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// index.js - Mod by Highpoint
|
||||
// Version for loading server-side plugins
|
||||
|
||||
// Library imports
|
||||
const express = require('express');
|
||||
const endpoints = require('./endpoints');
|
||||
@@ -15,7 +12,7 @@ const WebSocket = require('ws');
|
||||
const wss = new WebSocket.Server({ noServer: true });
|
||||
const chatWss = new WebSocket.Server({ noServer: true });
|
||||
const rdsWss = new WebSocket.Server({ noServer: true });
|
||||
const ExtraWss = new WebSocket.Server({ noServer: true });
|
||||
const pluginsWss = new WebSocket.Server({ noServer: true });
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const net = require('net');
|
||||
@@ -537,14 +534,14 @@ rdsWss.on('connection', (ws, request) => {
|
||||
});
|
||||
|
||||
//additional web socket for using plugins
|
||||
ExtraWss.on('connection', (ws, request) => {
|
||||
pluginsWss.on('connection', (ws, request) => {
|
||||
ws.on('message', message => {
|
||||
|
||||
const messageData = JSON.parse(message);
|
||||
const modifiedMessage = JSON.stringify(messageData);
|
||||
|
||||
//Broadcast the message to all other clients
|
||||
ExtraWss.clients.forEach(client => {
|
||||
pluginsWss.clients.forEach(client => {
|
||||
if (client.readyState === WebSocket.OPEN) {
|
||||
client.send(modifiedMessage); // Send the message to all clients
|
||||
}
|
||||
@@ -582,10 +579,10 @@ httpServer.on('upgrade', (request, socket, head) => {
|
||||
rdsWss.emit('connection', ws, request);
|
||||
});
|
||||
});
|
||||
} else if (request.url === '/extra') {
|
||||
} else if (request.url === '/data_plugins') {
|
||||
sessionMiddleware(request, {}, () => {
|
||||
ExtraWss.handleUpgrade(request, socket, head, (ws) => {
|
||||
ExtraWss.emit('connection', ws, request);
|
||||
pluginsWss.handleUpgrade(request, socket, head, (ws) => {
|
||||
pluginsWss.emit('connection', ws, request);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
@@ -599,25 +596,28 @@ app.use(express.static(path.join(__dirname, '../web'))); // Serve the entire web
|
||||
checkIPv6Support((isIPv6Supported) => {
|
||||
const ipv4Address = serverConfig.webserver.webserverIp === '0.0.0.0' ? 'localhost' : serverConfig.webserver.webserverIp;
|
||||
const ipv6Address = '::'; // This will bind to all available IPv6 interfaces
|
||||
|
||||
if (isIPv6Supported) {
|
||||
// Start server on both IPv4 and IPv6 addresses
|
||||
httpServer.listen(serverConfig.webserver.webserverPort, ipv4Address, () => {
|
||||
logInfo(`Web server has started on address \x1b[34mhttp://${ipv4Address}:${serverConfig.webserver.webserverPort}\x1b[0m.`);
|
||||
});
|
||||
const port = serverConfig.webserver.webserverPort;
|
||||
|
||||
httpServer.listen(serverConfig.webserver.webserverPort, ipv6Address, () => {
|
||||
logInfo(`Web server has started on address \x1b[34mhttp://[${ipv6Address}]:${serverConfig.webserver.webserverPort}\x1b[0m.`);
|
||||
});
|
||||
} else {
|
||||
// Start server only on IPv4 address
|
||||
httpServer.listen(serverConfig.webserver.webserverPort, ipv4Address, () => {
|
||||
if (configExists()) {
|
||||
logInfo(`Web server has started on address \x1b[34mhttp://${ipv4Address}:${serverConfig.webserver.webserverPort}\x1b[0m.`);
|
||||
const logServerStart = (address, isIPv6) => {
|
||||
const formattedAddress = isIPv6 ? `[${address}]` : address;
|
||||
logInfo(`Web server has started on address \x1b[34mhttp://${formattedAddress}:${port}\x1b[0m.`);
|
||||
};
|
||||
|
||||
const startServer = (address, isIPv6) => {
|
||||
httpServer.listen(port, address, () => {
|
||||
if (!isIPv6 && !configExists()) {
|
||||
logInfo(`Open your browser and proceed to \x1b[34mhttp://${address}:${port}\x1b[0m to continue with setup.`);
|
||||
} else {
|
||||
logInfo(`Open your browser and proceed to \x1b[34mhttp://${ipv4Address}:${serverConfig.webserver.webserverPort}\x1b[0m to continue with setup.`);
|
||||
logServerStart(address, isIPv6);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (isIPv6Supported) {
|
||||
startServer(ipv4Address, false); // Start on IPv4
|
||||
startServer(ipv6Address, true); // Start on IPv6
|
||||
} else {
|
||||
startServer(ipv4Address, false); // Start only on IPv4
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -50,42 +50,69 @@ function processData(data, piCode, rdsPs) {
|
||||
let txAzimuth;
|
||||
let maxDistance;
|
||||
let esMode = checkEs();
|
||||
let detectedByPireg = false; // To track if the station was found by pireg
|
||||
|
||||
// Helper function to calculate score and update matching station/city
|
||||
function evaluateStation(station, city, distance) {
|
||||
let weightDistance = distance.distanceKm;
|
||||
if (esMode && distance.distanceKm > 500) {
|
||||
weightDistance = Math.abs(distance.distanceKm - 1500);
|
||||
}
|
||||
let erp = station.erp && station.erp > 0 ? station.erp : 1;
|
||||
const score = (10 * Math.log10(erp * 1000)) / weightDistance; // Calculate score
|
||||
if (score > maxScore) {
|
||||
maxScore = score;
|
||||
txAzimuth = distance.azimuth;
|
||||
matchingStation = station;
|
||||
matchingCity = city;
|
||||
maxDistance = distance.distanceKm;
|
||||
}
|
||||
}
|
||||
|
||||
// First attempt: Try to match station using the piCode
|
||||
for (const cityId in data.locations) {
|
||||
const city = data.locations[cityId];
|
||||
if (city.stations) {
|
||||
for (const station of city.stations) {
|
||||
if (station.pi === piCode.toUpperCase() && !station.extra && station.ps && station.ps.toLowerCase().includes(rdsPs.replace(/ /g, '_').replace(/^_*(.*?)_*$/, '$1').toLowerCase())) {
|
||||
const distance = haversine(serverConfig.identification.lat, serverConfig.identification.lon, city.lat, city.lon);
|
||||
let weightDistance = distance.distanceKm
|
||||
if (esMode && (distance.distanceKm > 500)) {
|
||||
weightDistance = Math.abs(distance.distanceKm-1500);
|
||||
}
|
||||
let erp = (station.erp && station.erp > 0) ? station.erp : 1;
|
||||
const score = (10*Math.log10(erp*1000)) / weightDistance; // Calculate score
|
||||
if (score > maxScore) {
|
||||
maxScore = score;
|
||||
txAzimuth = distance.azimuth;
|
||||
matchingStation = station;
|
||||
matchingCity = city;
|
||||
maxDistance = distance.distanceKm;
|
||||
evaluateStation(station, city, distance);
|
||||
detectedByPireg = false; // Detected by pi, not pireg
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If no matching station is found, fallback to pireg
|
||||
if (!matchingStation) {
|
||||
for (const cityId in data.locations) {
|
||||
const city = data.locations[cityId];
|
||||
if (city.stations) {
|
||||
for (const station of city.stations) {
|
||||
if (station.pireg && station.pireg.toUpperCase() === piCode.toUpperCase() && !station.extra && station.ps && station.ps.toLowerCase().includes(rdsPs.replace(/ /g, '_').replace(/^_*(.*?)_*$/, '$1').toLowerCase())) {
|
||||
const distance = haversine(serverConfig.identification.lat, serverConfig.identification.lon, city.lat, city.lon);
|
||||
evaluateStation(station, city, distance);
|
||||
detectedByPireg = true; // Detected by pireg
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return the results if a station was found, otherwise return undefined
|
||||
if (matchingStation) {
|
||||
return {
|
||||
station: matchingStation.station.replace("R.", "Radio "),
|
||||
pol: matchingStation.pol.toUpperCase(),
|
||||
erp: (matchingStation.erp && matchingStation.erp > 0) ? matchingStation.erp : '?',
|
||||
erp: matchingStation.erp && matchingStation.erp > 0 ? matchingStation.erp : '?',
|
||||
city: matchingCity.name,
|
||||
itu: matchingCity.itu,
|
||||
distance: maxDistance.toFixed(0),
|
||||
azimuth: txAzimuth.toFixed(0),
|
||||
id: matchingStation.id,
|
||||
foundStation: true
|
||||
pi: matchingStation.pi,
|
||||
foundStation: true,
|
||||
reg: detectedByPireg // Indicates if it was detected by pireg
|
||||
};
|
||||
} else {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user