From 7c4912a12d7b298c4abfe6d87424ec9d70163543 Mon Sep 17 00:00:00 2001 From: NoobishSVK Date: Tue, 6 Feb 2024 22:22:06 +0100 Subject: [PATCH] ID improvements + console feed + ui changes --- console.js | 47 ++++++++++++++++++++++++++++++++++++----- index.js | 10 +++++---- package.json | 4 ++-- tx_search.js | 2 +- web/css/breadcrumbs.css | 16 ++++++++++++-- web/css/buttons.css | 7 ++++++ web/css/helpers.css | 4 ++++ web/index.ejs | 12 ++++++----- web/js/main.js | 3 ++- web/setup.ejs | 41 +++++++++++++++++++++++++++++++++++ 10 files changed, 126 insertions(+), 20 deletions(-) diff --git a/console.js b/console.js index 461b3a6..6f36bc7 100644 --- a/console.js +++ b/console.js @@ -14,11 +14,48 @@ const MESSAGE_PREFIX = { WARN: "\x1b[33m[WARN]\x1b[0m", }; -const logDebug = (...messages) => verboseMode ? console.log(getCurrentTime(), MESSAGE_PREFIX.DEBUG, ...messages) : ''; -const logError = (...messages) => console.log(getCurrentTime(), MESSAGE_PREFIX.ERROR, ...messages); -const logInfo = (...messages) => console.log(getCurrentTime(), MESSAGE_PREFIX.INFO, ...messages); -const logWarn = (...messages) => console.log(getCurrentTime(), MESSAGE_PREFIX.WARN, ...messages); +// Initialize an array to store logs +const logs = []; +const maxLogLines = 100; + +const logDebug = (...messages) => { + if (verboseMode) { + const logMessage = `${getCurrentTime()} ${MESSAGE_PREFIX.DEBUG} ${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 logError = (...messages) => { + const logMessage = `${getCurrentTime()} ${MESSAGE_PREFIX.ERROR} ${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); + if (logs.length > maxLogLines) { + logs.shift(); // Remove the oldest log if the array exceeds the maximum number of lines + } + console.log(logMessage); +}; + +const logWarn = (...messages) => { + const logMessage = `${getCurrentTime()} ${MESSAGE_PREFIX.WARN} ${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); +}; module.exports = { - logError, logDebug, logInfo, logWarn + logError, logDebug, logInfo, logWarn, logs }; diff --git a/index.js b/index.js index 5707fe2..37efb41 100644 --- a/index.js +++ b/index.js @@ -249,7 +249,8 @@ app.get('/', (req, res) => { isTuneAuthenticated: req.session.isTuneAuthenticated, tunerName: serverConfig.identification.tunerName, tunerDesc: serverConfig.identification.tunerDesc, - tunerLock: serverConfig.lockToAdmin + tunerLock: serverConfig.lockToAdmin, + publicTuner: serverConfig.publicTuner }) } }); @@ -259,7 +260,8 @@ app.get('/setup', (req, res) => { res.render('setup', { isAdminAuthenticated: req.session.isAdminAuthenticated, videoDevices: result.audioDevices, - audioDevices: result.videoDevices }); + audioDevices: result.videoDevices, + consoleOutput: consoleCmd.logs }); }); }); @@ -362,11 +364,11 @@ wss.on('connection', (ws, request) => { }); ws.on('message', (message) => { - logDebug('Command received from \x1b[90m' + request.connection.remoteAddress + '\x1b[0m:', message.toString()); + logDebug('Command received from \x1b[90m' + clientIp + '\x1b[0m:', message.toString()); command = message.toString(); if(command.startsWith('X')) { - logWarn('Remote tuner shutdown attempted by \x1b[90m' + request.connection.remoteAddress + '\x1b[0m. You may consider blocking this user.'); + logWarn('Remote tuner shutdown attempted by \x1b[90m' + clientIp + '\x1b[0m. You may consider blocking this user.'); return; } diff --git a/package.json b/package.json index cbc61c8..08d0ff6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "xdrd-client", - "version": "1.0.0", + "name": "fm-dx-webserver", + "version": "1.0.2", "description": "", "main": "index.js", "scripts": { diff --git a/tx_search.js b/tx_search.js index 017d6c5..c3a644b 100644 --- a/tx_search.js +++ b/tx_search.js @@ -59,7 +59,7 @@ function processData(data, piCode, rdsPs) { const city = data.locations[cityId]; if (city.stations) { for (const station of city.stations) { - if (station.pi === piCode && station.ps && station.ps.includes(rdsPs.replace(/ /g, '_'))) { + if (station.pi === piCode && !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); if (distance.distanceKm < minDistance) { minDistance = distance.distanceKm; diff --git a/web/css/breadcrumbs.css b/web/css/breadcrumbs.css index 396ede7..9566987 100644 --- a/web/css/breadcrumbs.css +++ b/web/css/breadcrumbs.css @@ -64,6 +64,10 @@ label { display: none; } +#data-station-name { + font-size: 20px; +} + .form-group { float: left; margin-bottom: 10px; @@ -71,7 +75,7 @@ label { margin-right: 5px; } -#settings, #back-btn { +#settings, #back-btn, #users-online-container { background: transparent; border: 0; color: white; @@ -88,10 +92,14 @@ label { cursor: pointer; } -#settings:hover, #back-btn:hover { +#settings:hover, #back-btn:hover, #users-online-container:hover { background: var(--color-3); } +#users-online-container { + top: 80px; +} + #back-btn { left: 15px; right: auto; @@ -115,6 +123,10 @@ label { display: none; } +#login-form { + padding: 5px; +} + .checkbox input[type="checkbox"] { padding: 0; height: initial; diff --git a/web/css/buttons.css b/web/css/buttons.css index 4f573a9..f63dacd 100644 --- a/web/css/buttons.css +++ b/web/css/buttons.css @@ -84,6 +84,13 @@ 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; diff --git a/web/css/helpers.css b/web/css/helpers.css index 19b82ae..cf229ba 100644 --- a/web/css/helpers.css +++ b/web/css/helpers.css @@ -157,6 +157,10 @@ background-color: var(--color-2) !important; } +.pointer { + cursor: pointer; +} + @media only screen and (max-width: 960px) { .text-medium-big { font-size: 32px; diff --git a/web/index.ejs b/web/index.ejs index cb3b76a..26f4162 100644 --- a/web/index.ejs +++ b/web/index.ejs @@ -49,7 +49,8 @@
-

<%= tunerName %> <% if (tunerLock) { %><% } %>

+

<%= tunerName %> <% if (!publicTuner) { %> + <% } else if (tunerLock) { %><% } %>

<%= tunerDesc %>

@@ -192,7 +193,8 @@
- + + -
+
- 0 + 0
<% if (isAdminAuthenticated) { %> @@ -251,7 +253,7 @@
 Support the developer!
-

FM-DX WebServer v1.0.1 [5/2/2024] by Noobish & the OpenRadio community.

+

FM-DX WebServer v1.0.2 [6/2/2024] by Noobish & the OpenRadio community.

This app works thanks to these amazing projects:
- librdsparser & maps.fmdx.pl by Konrad Kosmatka
- 3LAS by JoJoBond
diff --git a/web/js/main.js b/web/js/main.js index 780929e..1275c87 100644 --- a/web/js/main.js +++ b/web/js/main.js @@ -452,6 +452,7 @@ function updateSignalUnits(parsedData) { function updateDataElements(parsedData) { $('#data-frequency').text(parsedData.freq); + $("#commandinput").attr("aria-label", "Current frequency: " + parsedData.freq); $('#data-pi').html(parsedData.pi === '?' ? "?" : parsedData.pi); $('#data-ps').html(parsedData.ps === '?' ? "?" : processString(parsedData.ps, parsedData.ps_errors)); $('.data-tp').html(parsedData.tp === false ? "TP" : "TP"); @@ -528,7 +529,7 @@ function updatePanels(parsedData) { // Update other elements every time updateDataElements(parsedData); updateSignalUnits(parsedData); - $('#users-online').text(parsedData.users); + $('.users-online').text(parsedData.users); } function createListItem(element) { diff --git a/web/setup.ejs b/web/setup.ejs index cc05776..0efd4e3 100644 --- a/web/setup.ejs +++ b/web/setup.ejs @@ -147,9 +147,22 @@

+
+

CONSOLE OUTPUT

+ <% if (consoleOutput && consoleOutput.length > 0) { %> +
+ <% consoleOutput.forEach(function(log) { %> +
<%= log %>
+ <% }); %> +
+ <% } else { %> +

No console output available.

+ <% } %> +

Feel free to contact us on Discord for community support.

+ <% } else { %>
@@ -168,6 +181,34 @@
<% } %> +