Enable release resource

This commit is contained in:
2026-09-02 10:31:22 +02:00
parent 2ec8251605
commit e7f6ef62c0
2 changed files with 87 additions and 28 deletions
+25 -8
View File
@@ -2,7 +2,7 @@
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>DMR Web Receiver Pro</title>
<style>
:root {
@@ -13,6 +13,9 @@
--lcd-bg: #05140a;
--lcd-text: #00ff41;
}
* { box-sizing: border-box; }
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(--bg-main); color: #e0e0e0; margin: 0; padding: 30px 15px; }
h2 { text-align: center; color: #fff; text-transform: uppercase; letter-spacing: 2px; margin-bottom: 30px; font-size: 22px; }
@@ -21,13 +24,12 @@
.panel-title { font-size: 11px; text-transform: uppercase; color: #7f8c8d; margin-bottom: 20px; border-bottom: 1px solid #2a2b30; padding-bottom: 8px; letter-spacing: 1px; }
/* Schermo LCD */
.display { background: var(--lcd-bg); color: var(--lcd-text); padding: 20px 15px; border-radius: 4px; font-size: 24px; font-family: 'Courier New', Courier, monospace; text-align: center; font-weight: bold; text-shadow: 0 0 8px rgba(0, 255, 65, 0.5); border: 2px solid #000; box-shadow: inset 0 0 15px rgba(0,0,0,0.9); }
.vu-meter-bg { background: #000; height: 6px; border-radius: 2px; margin-top: 8px; overflow: hidden; border: 1px solid #111; }
.vu-meter-bar { height: 100%; width: 0%; background: #2ecc71; transition: width 0.05s; }
.controls { display: flex; gap: 10px; margin-top: 20px; }
input[type="number"] { flex: 1; padding: 12px; font-size: 18px; border-radius: 4px; border: 1px solid #333; background: #0a0a0c; color: #fff; text-align: center; font-family: monospace; }
input[type="number"] { flex: 1; padding: 12px; font-size: 18px; border-radius: 4px; border: 1px solid #333; background: #0a0a0c; color: #fff; text-align: center; font-family: monospace; width: 100%; }
input[type="number"]:focus { outline: none; border-color: var(--accent); }
.btn { background: #2c3e50; color: white; border: 1px solid #1a252f; padding: 12px 15px; border-radius: 4px; font-size: 13px; cursor: pointer; text-transform: uppercase; font-weight: bold; transition: background 0.2s; }
@@ -37,33 +39,46 @@
.quick-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-top: 15px; }
/* Traffico e Scrollbar */
.traffic-list { flex-grow: 1; max-height: 400px; overflow-y: auto; padding-right: 5px; background: #0a0a0c; border: 1px solid #222; border-radius: 4px; padding: 10px; }
.traffic-item { color: #bdc3c7; font-size: 13px; margin: 4px 0; padding: 8px; background: #15161a; border-radius: 4px; }
.traffic-item b { color: var(--accent); font-size: 14px; display: inline-block; width: 75px; }
.traffic-clickable { cursor: pointer; transition: all 0.2s; border-left: 3px solid transparent; }
.traffic-clickable:hover { background: #1a1b20; border-left-color: var(--accent); transform: translateX(3px); }
/* Volume e Pulsanti Inferiori */
.volume-box { margin-top: 25px; }
.volume-box label { display: flex; justify-content: space-between; font-size: 11px; margin-bottom: 12px; color: #7f8c8d; text-transform: uppercase; letter-spacing: 1px;}
input[type="range"] { width: 100%; cursor: pointer; accent-color: var(--accent); }
.connect-btn { background: #27ae60; color: white; padding: 20px; border: none; border-radius: 4px; font-size: 15px; cursor: pointer; width: 100%; font-weight: bold; text-transform: uppercase; margin-top: 25px; letter-spacing: 1px; box-shadow: 0 4px 0 #1e8449; transition: all 0.1s; }
.action-buttons { display: flex; gap: 10px; margin-top: 25px; }
.connect-btn { flex: 1; background: #27ae60; color: white; padding: 20px 10px; border: none; border-radius: 4px; font-size: 15px; cursor: pointer; font-weight: bold; text-transform: uppercase; letter-spacing: 1px; box-shadow: 0 4px 0 #1e8449; transition: all 0.1s; }
.connect-btn:active { transform: translateY(4px); box-shadow: none; margin-bottom: -4px; }
.stop-btn { background: #e74c3c; box-shadow: 0 4px 0 #c0392b; display: none; }
.stop-btn:active { box-shadow: none; }
.status { text-align: center; font-size: 12px; color: #7f8c8d; margin-top: 20px; font-family: monospace; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-main); }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }
@media (max-width: 768px) {
body { padding: 15px 10px; }
h2 { font-size: 18px; margin-bottom: 20px; margin-top: 5px; }
.dashboard-grid { gap: 15px; grid-template-columns: 1fr; }
.panel { padding: 15px; }
.traffic-list { max-height: 280px; }
.quick-grid { gap: 6px; }
.btn { padding: 12px 5px; font-size: 11px; }
.display { font-size: 20px; padding: 15px 10px; }
input[type="number"] { font-size: 16px; padding: 10px; }
}
</style>
</head>
<body>
<h2>ARI FVG Web-Receiver</h2>
<div class="dashboard-grid">
<!-- Colonna Sinistra: Strumenti e Avvio -->
<div class="panel">
<div class="panel-title">Selettore Talkgroup</div>
@@ -86,11 +101,13 @@
<input type="range" id="volumeSlider" min="0" max="2" step="0.05" value="1">
</div>
<div class="action-buttons">
<button class="connect-btn" id="connectBtn">Avvia Ricevitore</button>
<button class="connect-btn stop-btn" id="stopBtn">Ferma</button>
</div>
<div class="status" id="statusText">Sistema in attesa...</div>
</div>
<!-- Colonna Destra: Monitor Traffico -->
<div class="panel">
<div class="panel-title">Monitor Rete Globale</div>
<div class="traffic-list" id="liveTrafficList">
+60 -18
View File
@@ -1,4 +1,4 @@
console.log("App.js caricato - VU Meter & Click-to-Tune attivi!");
console.log("App.js caricato - Soft Stop e Auto-Wakeup attivi!");
let ws = null;
let audioCtx = null;
@@ -8,6 +8,7 @@ let dataArray = null;
let nextStartTime = 0;
const connectBtn = document.getElementById('connectBtn');
const stopBtn = document.getElementById('stopBtn');
const tgInput = document.getElementById('tgInput');
const setTgBtn = document.getElementById('setTgBtn');
const displayScreen = document.getElementById('displayScreen');
@@ -17,7 +18,7 @@ const volumeValue = document.getElementById('volumeValue');
const liveTrafficList = document.getElementById('liveTrafficList');
const vuMeterBar = document.getElementById('vuMeterBar');
if(statusText) statusText.innerText = "✅ Sistema pronto. Clicca Avvia Ascolto.";
if(statusText) statusText.innerText = "✅ Sistema pronto. Clicca Avvia Ricevitore.";
if(volumeSlider) {
volumeSlider.addEventListener('input', (e) => {
@@ -33,17 +34,30 @@ window.setQuickTg = function(valore) {
};
function inviaCambioTG(nuovoTG) {
if (!nuovoTG || nuovoTG <= 0) return;
if (!nuovoTG || nuovoTG < 0) return; // Permette lo zero per lo stop interno
if (ws && ws.readyState === WebSocket.OPEN) {
// Se l'audio era stato fermato, lo riavvia automaticamente (Auto-Wakeup)
if (nuovoTG > 0 && audioCtx && audioCtx.state === 'suspended') {
audioCtx.resume();
if(connectBtn) connectBtn.style.display = 'none';
if(stopBtn) stopBtn.style.display = 'block';
}
ws.send(JSON.stringify({ action: "cambia_tg", tg: nuovoTG }));
if(displayScreen) displayScreen.innerText = "SINTONIA...";
if (nuovoTG > 0) {
if(displayScreen) {
displayScreen.innerText = "SINTONIA...";
displayScreen.style.background = "";
}
if(statusText) statusText.innerText = "Sintonizzato su TG " + nuovoTG;
}
} else {
if(statusText) statusText.innerText = "Pronto a sintonizzare TG " + nuovoTG + " (Avvia prima)";
}
}
// --- VU METER LOOP ---
function renderVUMeter() {
requestAnimationFrame(renderVUMeter);
if (!analyser || !vuMeterBar) return;
@@ -55,12 +69,12 @@ function renderVUMeter() {
sum += v * v;
}
let rms = Math.sqrt(sum / dataArray.length);
let percent = Math.min(100, rms * 500); // Moltiplicatore di sensibilità grafica
let percent = Math.min(100, rms * 500);
vuMeterBar.style.width = percent + '%';
if (percent > 85) vuMeterBar.style.background = '#e74c3c'; // Rosso saturo
else if (percent > 50) vuMeterBar.style.background = '#f1c40f'; // Giallo
else vuMeterBar.style.background = '#2ecc71'; // Verde standard
if (percent > 85) vuMeterBar.style.background = '#e74c3c';
else if (percent > 50) vuMeterBar.style.background = '#f1c40f';
else vuMeterBar.style.background = '#2ecc71';
}
function playPCM320(arrayBuffer) {
@@ -77,8 +91,6 @@ function playPCM320(arrayBuffer) {
const source = audioCtx.createBufferSource();
source.buffer = buffer;
// Collega al VU meter, che a sua volta è collegato al volume
source.connect(analyser);
const currentTime = audioCtx.currentTime;
@@ -90,26 +102,54 @@ function playPCM320(arrayBuffer) {
}
}
function stopAudio() {
// Invia TG 0 per sganciare il flusso audio dal server mantenendo vivo il WebSocket
if (ws && ws.readyState === WebSocket.OPEN) {
inviaCambioTG(0);
}
if (audioCtx && audioCtx.state !== 'suspended') {
audioCtx.suspend();
}
if(connectBtn) connectBtn.style.display = 'block';
if(stopBtn) stopBtn.style.display = 'none';
if(displayScreen) {
displayScreen.innerText = "STANDBY";
displayScreen.style.background = "";
}
if(statusText) {
statusText.innerText = "Audio disattivato. Monitor di rete attivo.";
statusText.style.color = "#bdc3c7";
}
}
function startAudio() {
try {
if (!audioCtx) {
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
analyser = audioCtx.createAnalyser();
analyser.fftSize = 256;
dataArray = new Uint8Array(analyser.frequencyBinCount);
gainNode = audioCtx.createGain();
// Catena: Source -> Analyser(VU) -> Gain(Volume) -> Casse
analyser.connect(gainNode);
gainNode.connect(audioCtx.destination);
if(volumeSlider) gainNode.gain.value = parseFloat(volumeSlider.value);
renderVUMeter(); // Avvia l'animazione grafica
renderVUMeter();
}
if (audioCtx.state === 'suspended') audioCtx.resume();
// Se il WebSocket è già aperto (uscita dallo stato di Stop)
if (ws && ws.readyState === WebSocket.OPEN) {
if(connectBtn) connectBtn.style.display = 'none';
if(stopBtn) stopBtn.style.display = 'block';
if(tgInput) inviaCambioTG(tgInput.value);
return;
}
if(statusText) statusText.innerText = "🔄 Connessione in corso...";
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
@@ -118,6 +158,7 @@ function startAudio() {
ws.onopen = () => {
if(connectBtn) connectBtn.style.display = 'none';
if(stopBtn) stopBtn.style.display = 'block';
if(tgInput) inviaCambioTG(tgInput.value);
};
@@ -132,12 +173,11 @@ function startAudio() {
if (data.action === "display") {
if(displayScreen) {
displayScreen.innerText = data.text;
displayScreen.style.background = data.active ? "#e67e22" : "#1abc9c";
displayScreen.style.background = data.active ? "#e67e22" : "";
}
if(statusText) statusText.style.color = "#bdc3c7";
}
// CLICK-TO-TUNE IMPLEMENTATO QUI
if (data.action === "global_traffic" && liveTrafficList) {
if (!data.data || data.data.length === 0) {
liveTrafficList.innerHTML = "Nessun traffico in corso...";
@@ -155,6 +195,7 @@ function startAudio() {
ws.onclose = () => {
if(statusText) statusText.innerText = "❌ Connessione persa.";
if(connectBtn) connectBtn.style.display = 'block';
if(stopBtn) stopBtn.style.display = 'none';
};
} catch (err) {
@@ -163,6 +204,7 @@ function startAudio() {
}
if(connectBtn) connectBtn.addEventListener('click', startAudio);
if(stopBtn) stopBtn.addEventListener('click', stopAudio);
if(setTgBtn) setTgBtn.addEventListener('click', () => { if(tgInput) inviaCambioTG(tgInput.value); });
if(tgInput) {
tgInput.addEventListener('keypress', (e) => {