logging improvements, connection changes, ui changes

This commit is contained in:
NoobishSVK
2024-02-07 20:18:38 +01:00
parent 0b11e9cd96
commit 8ad8015ae7
7 changed files with 108 additions and 87 deletions
+14 -1
View File
@@ -1,4 +1,5 @@
const verboseMode = process.argv.includes('--debug');
const verboseModeFfmpeg = process.argv.includes('--ffmpegdebug');
const getCurrentTime = () => {
const currentTime = new Date();
@@ -10,6 +11,7 @@ const getCurrentTime = () => {
const MESSAGE_PREFIX = {
DEBUG: "\x1b[36m[DEBUG]\x1b[0m",
ERROR: "\x1b[31m[ERROR]\x1b[0m",
FFMPEG: "\x1b[36m[FFMPEG]\x1b[0m",
INFO: "\x1b[32m[INFO]\x1b[0m",
WARN: "\x1b[33m[WARN]\x1b[0m",
};
@@ -38,6 +40,17 @@ const logError = (...messages) => {
console.log(logMessage);
};
const logFfmpeg = (...messages) => {
if (verboseModeFfmpeg) {
const logMessage = `${getCurrentTime()} ${MESSAGE_PREFIX.FFMPEG} ${messages.join(' ')}`;
logs.push(logMessage);
if (logs.length > maxLogLines) {
logs.shift(); // Remove the oldest log if the array exceeds the maximum number of lines
}
console.log(logMessage);
}
};
const logInfo = (...messages) => {
const logMessage = `${getCurrentTime()} ${MESSAGE_PREFIX.INFO} ${messages.join(' ')}`;
logs.push(logMessage);
@@ -57,5 +70,5 @@ const logWarn = (...messages) => {
};
module.exports = {
logError, logDebug, logInfo, logWarn, logs
logError, logDebug, logFfmpeg, logInfo, logWarn, logs
};
+1 -1
View File
@@ -341,7 +341,7 @@ function handleData(ws, receivedData) {
}
// Get the received TX info
const currentTx = fetchTx(dataToSend.freq, dataToSend.pi, dataToSend.ps);
const currentTx = fetchTx(parseFloat(dataToSend.freq).toFixed(1), dataToSend.pi, dataToSend.ps);
if(currentTx && currentTx.station !== undefined) {
dataToSend.txInfo = {
station: currentTx.station,
+19 -8
View File
@@ -100,11 +100,10 @@ function authenticateWithXdrd(client, salt, password) {
client.write('x\n');
}
if(serverConfig.identification.tunerName.includes('zvartoshu')) {
process.exit(1);
}
connectToXdrd();
// xdrd connection
function connectToXdrd() {
if (serverConfig.xdrd.xdrdPassword.length > 1) {
client.connect(serverConfig.xdrd.xdrdPort, serverConfig.xdrd.xdrdIp, () => {
logInfo('Connection to xdrd established successfully.');
@@ -179,27 +178,39 @@ if (serverConfig.xdrd.xdrdPassword.length > 1) {
client.on('data', authDataHandler);
});
}
}
client.on('close', () => {
logWarn('Disconnected from xdrd.');
logWarn('Disconnected from xdrd. Attempting to reconnect.');
setTimeout(function () {
connectToXdrd();
}, 2000)
});
client.on('error', (err) => {
setTimeout(function () {
connectToXdrd();
}, 2000)
switch (true) {
case err.message.includes("ECONNRESET"):
logError("Connection to xdrd lost. Exiting...");
process.exit(1);
logError("Connection to xdrd lost. Reconnecting...");
break;
case err.message.includes("ETIMEDOUT"):
logError("Connection to xdrd @ " + serverConfig.xdrd.xdrdIp + ":" + serverConfig.xrd.xdrdPort + " timed out.");
process.exit(1);
logError("Connection to xdrd @ " + serverConfig.xdrd.xdrdIp + ":" + serverConfig.xdrd.xdrdPort + " timed out.");
break;
case err.message.includes("ECONNREFUSED"):
logError("Connection to xdrd @ " + serverConfig.xdrd.xdrdIp + ":" + serverConfig.xdrd.xdrdPort + " failed. Is xdrd running?");
break;
case err.message.includes("EINVAL"):
logError("Attempts to reconnect are failing repeatedly. Consider checking your settings or restarting xdrd.");
break;
default:
logError("Unhandled error: ", err.message);
break;
}
});
+4 -4
View File
@@ -43,21 +43,21 @@ function enableAudioStream() {
// Handle the output of the child process (optional)
childProcess.stdout.on('data', (data) => {
consoleCmd.logDebug(`stdout: ${data}`);
consoleCmd.logFfmpeg(`stdout: ${data}`);
});
childProcess.stderr.on('data', (data) => {
consoleCmd.logDebug(`stderr: ${data}`);
consoleCmd.logFfmpeg(`stderr: ${data}`);
});
// Handle the child process exit event
childProcess.on('close', (code) => {
consoleCmd.logDebug(`Child process exited with code ${code}`);
consoleCmd.logFfmpeg(`Child process exited with code ${code}`);
});
// You can also listen for the 'error' event in case the process fails to start
childProcess.on('error', (err) => {
consoleCmd.logError(`Error starting child process: ${err}`);
consoleCmd.logFfmpeg(`Error starting child process: ${err}`);
});
}
}
+5 -1
View File
@@ -249,7 +249,7 @@ label {
}
}
@media only screen and (min-width: 960px) and (max-height: 860px) {
@media only screen and (min-width: 769px) and (max-height: 860px) {
#rt-container {
height: 90px !important;
}
@@ -268,4 +268,8 @@ label {
float: right;
text-align: right;
}
h2 {
margin-bottom: 10px;
font-size: 18px;
}
}
-7
View File
@@ -84,13 +84,6 @@ input[type="range"] {
background: transparent;
}
input[type="range"]::after {
width: 100px;
height: 100px;
background: blue;
}
/* Track: Mozilla Firefox */
input[type="range"]::-moz-range-track {
height: 48px;
+2 -2
View File
@@ -133,7 +133,7 @@
<div class="panel-33 flex-container flex-phone" id="tune-buttons">
<button id="freq-down" aria-label="Tune down by 100 KHz"><i class="fa-solid fa-chevron-left"></i></button>
<input type="text" id="commandinput" inputmode="numeric" placeholder="Frequency">
<input type="text" id="commandinput" inputmode="numeric" placeholder="Frequency" aria-label="Current frequency: ">
<button id="freq-up" aria-label="Tune up by 100 KHz"><i class="fa-solid fa-chevron-right"></i></button>
</div>
@@ -253,7 +253,7 @@
<div class="flex-container flex-left text-left bottom-20 hover-brighten p-10 br-5" onclick="window.open('https://buymeacoffee.com/noobish')">
<i class="fa-solid fa-hand-holding-medical"></i>&nbsp;<span><strong>Support</strong> the developer!</span>
</div>
<p class="text-small">FM-DX WebServer <span style="color: var(--color-3);">v1.0.2 [6/2/2024]</span> by <a href="https://noobish.eu" target="_blank">Noobish</a> & the OpenRadio community.</p>
<p class="text-small">FM-DX WebServer <span style="color: var(--color-3);">v1.0.3 [7/2/2024]</span> by <a href="https://noobish.eu" target="_blank">Noobish</a> & the OpenRadio community.</p>
<p class="text-small bottom-50">This app works thanks to these amazing projects: <br>
<span class="text-smaller">- librdsparser & maps.fmdx.pl by <a href="https://fmdx.pl" target="_blank">Konrad Kosmatka</a></span><br>
<span class="text-smaller">- 3LAS by <a href="https://github.com/JoJoBond/3LAS" target="_blank">JoJoBond</a></span><br>