Enhanced Dashboard
This commit is contained in:
+74
-35
@@ -3,61 +3,100 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<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">
|
||||||
<title>DMR Web Receiver</title>
|
<title>DMR Web Receiver Pro</title>
|
||||||
<style>
|
<style>
|
||||||
body { font-family: Arial, sans-serif; text-align: center; background-color: #2c3e50; color: white; margin-top: 40px; }
|
:root {
|
||||||
.container { max-width: 420px; margin: 0 auto; background: #34495e; padding: 25px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.5); }
|
--bg-main: #0a0a0c;
|
||||||
.display { background: #1abc9c; padding: 20px; border-radius: 5px; font-size: 24px; font-family: monospace; margin-bottom: 20px; color: #fff; font-weight: bold; transition: background 0.3s; }
|
--panel-bg: #15161a;
|
||||||
|
--accent: #ff8c00;
|
||||||
|
--accent-hover: #ff6a00;
|
||||||
|
--lcd-bg: #05140a;
|
||||||
|
--lcd-text: #00ff41;
|
||||||
|
}
|
||||||
|
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; }
|
||||||
|
|
||||||
.tg-box { display: flex; gap: 10px; margin-bottom: 15px; }
|
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 25px; max-width: 850px; margin: 0 auto; }
|
||||||
input[type="number"] { flex: 1; padding: 12px; font-size: 16px; border-radius: 5px; border: none; outline: none; text-align: center; font-weight: bold; }
|
.panel { background: var(--panel-bg); border: 1px solid #2a2b30; border-radius: 6px; padding: 25px; box-shadow: inset 0 1px 0 rgba(255,255,255,0.05), 0 8px 20px rgba(0,0,0,0.6); display: flex; flex-direction: column; }
|
||||||
.set-btn { background-color: #e67e22; color: white; border: none; padding: 12px 18px; border-radius: 5px; font-size: 15px; cursor: pointer; font-weight: bold; }
|
|
||||||
.set-btn:hover { background-color: #d35400; }
|
|
||||||
|
|
||||||
.quick-tg { display: flex; gap: 8px; justify-content: center; margin-bottom: 20px; }
|
.panel-title { font-size: 11px; text-transform: uppercase; color: #7f8c8d; margin-bottom: 20px; border-bottom: 1px solid #2a2b30; padding-bottom: 8px; letter-spacing: 1px; }
|
||||||
.quick-btn { background: #7f8c8d; color: white; border: none; padding: 6px 12px; border-radius: 4px; font-size: 13px; cursor: pointer; }
|
|
||||||
.quick-btn:hover { background: #95a5a6; }
|
|
||||||
|
|
||||||
/* --- STILE PER IL CONTROLLO VOLUME --- */
|
/* Schermo LCD */
|
||||||
.volume-box { margin-bottom: 20px; text-align: left; background: #2c3e50; padding: 10px 15px; border-radius: 5px; }
|
.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); }
|
||||||
.volume-box label { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 8px; color: #bdc3c7; font-weight: bold; }
|
.vu-meter-bg { background: #000; height: 6px; border-radius: 2px; margin-top: 8px; overflow: hidden; border: 1px solid #111; }
|
||||||
input[type="range"] { width: 100%; cursor: pointer; accent-color: #3498db; }
|
.vu-meter-bar { height: 100%; width: 0%; background: #2ecc71; transition: width 0.05s; }
|
||||||
|
|
||||||
.connect-btn { background-color: #3498db; color: white; padding: 15px 24px; border: none; border-radius: 5px; font-size: 18px; cursor: pointer; margin-bottom: 15px; width: 100%; font-weight: bold; }
|
.controls { display: flex; gap: 10px; margin-top: 20px; }
|
||||||
.connect-btn:hover { background-color: #2980b9; }
|
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; }
|
||||||
.status { font-size: 14px; color: #bdc3c7; }
|
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; }
|
||||||
|
.btn-accent { background: var(--accent); border-color: var(--accent-hover); color: #111; }
|
||||||
|
.btn-accent:hover { background: var(--accent-hover); }
|
||||||
|
.btn:hover:not(.btn-accent) { background: #34495e; }
|
||||||
|
|
||||||
|
.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; }
|
||||||
|
.connect-btn:active { transform: translateY(4px); box-shadow: none; margin-bottom: -4px; }
|
||||||
|
.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; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
|
||||||
<h2>ARI FVG Web-Receiver</h2>
|
<h2>ARI FVG Web-Receiver</h2>
|
||||||
|
|
||||||
<!-- Display Caller ID -->
|
<div class="dashboard-grid">
|
||||||
<div class="display" id="displayScreen">IN ASCOLTO</div>
|
<!-- Colonna Sinistra: Strumenti e Avvio -->
|
||||||
|
<div class="panel">
|
||||||
|
<div class="panel-title">Selettore Talkgroup</div>
|
||||||
|
|
||||||
<!-- Campo di inserimento TG Libero -->
|
<div class="display" id="displayScreen">STANDBY</div>
|
||||||
<div class="tg-box">
|
<div class="vu-meter-bg"><div class="vu-meter-bar" id="vuMeterBar"></div></div>
|
||||||
<input type="number" id="tgInput" placeholder="Inserisci TG" value="222" min="1" max="9999999">
|
|
||||||
<button class="set-btn" id="setTgBtn">Sintonizza</button>
|
<div class="controls">
|
||||||
|
<input type="number" id="tgInput" placeholder="TG" value="222" min="1">
|
||||||
|
<button class="btn btn-accent" id="setTgBtn">Sintonizza</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Scorciatoie Rapide -->
|
<div class="quick-grid">
|
||||||
<div class="quick-tg">
|
<button class="btn" onclick="setQuickTg(112)">112 PC</button>
|
||||||
<button class="quick-btn" onclick="setQuickTg(112)">TG 112 ARI FVG PC</button>
|
<button class="btn" onclick="setQuickTg(22231)">22231 BM</button>
|
||||||
<button class="quick-btn" onclick="setQuickTg(22231)">TG 22231 BM</button>
|
<button class="btn" onclick="setQuickTg(22200)">22200 FD</button>
|
||||||
<button class="quick-btn" onclick="setQuickTg(22200)">TG 22200 FreeDMR</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- CONTROLLO VOLUME -->
|
|
||||||
<div class="volume-box">
|
<div class="volume-box">
|
||||||
<label for="volumeSlider"><span>Volume</span> <span id="volumeValue">100%</span></label>
|
<label for="volumeSlider"><span>Master Gain</span> <span id="volumeValue">100%</span></label>
|
||||||
<input type="range" id="volumeSlider" min="0" max="2" step="0.05" value="1">
|
<input type="range" id="volumeSlider" min="0" max="2" step="0.05" value="1">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Bottone Avvio -->
|
<button class="connect-btn" id="connectBtn">Avvia Ricevitore</button>
|
||||||
<button class="connect-btn" id="connectBtn">📡 Avvia Ascolto DMR</button>
|
<div class="status" id="statusText">Sistema in attesa...</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="status" id="statusText">Clicca il pulsante per attivare l'audio.</div>
|
<!-- Colonna Destra: Monitor Traffico -->
|
||||||
|
<div class="panel">
|
||||||
|
<div class="panel-title">Monitor Rete Globale</div>
|
||||||
|
<div class="traffic-list" id="liveTrafficList">
|
||||||
|
<div style="color: #555; font-style: italic; text-align: center; padding: 20px 0;">Nessun traffico rilevato...</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/static/app.js"></script>
|
<script src="/static/app.js"></script>
|
||||||
|
|||||||
@@ -120,6 +120,9 @@ class OpenBridgeRxClient(asyncio.DatagramProtocol):
|
|||||||
src_id = int.from_bytes(data[5:8], 'big')
|
src_id = int.from_bytes(data[5:8], 'big')
|
||||||
tg_arrivo = str(int.from_bytes(data[8:11], 'big'))
|
tg_arrivo = str(int.from_bytes(data[8:11], 'big'))
|
||||||
|
|
||||||
|
# Traccia il traffico a prescindere da chi lo ascolta
|
||||||
|
self.server_app.aggiorna_traffico_globale(src_id, tg_arrivo)
|
||||||
|
|
||||||
# Ricava l'elenco dei TG attualmente richiesti da almeno un utente Web
|
# Ricava l'elenco dei TG attualmente richiesti da almeno un utente Web
|
||||||
tg_attivi = {client_data["tg"] for client_data in self.server_app.clients.values()}
|
tg_attivi = {client_data["tg"] for client_data in self.server_app.clients.values()}
|
||||||
|
|
||||||
@@ -157,6 +160,27 @@ class WebDmrServer:
|
|||||||
# Dizionario stati indipendenti per TG: "222" -> {"rx_in_corso": False, ...}
|
# Dizionario stati indipendenti per TG: "222" -> {"rx_in_corso": False, ...}
|
||||||
self.tg_states = {}
|
self.tg_states = {}
|
||||||
|
|
||||||
|
# Dizionario globale traffico
|
||||||
|
self.traffico_globale = {}
|
||||||
|
|
||||||
|
def aggiorna_traffico_globale(self, src_id, tg):
|
||||||
|
"""Aggiorna il monitor globale e avvisa i client se c'è un nuovo TX"""
|
||||||
|
ora = time.time()
|
||||||
|
nuovo = tg not in self.traffico_globale or self.traffico_globale[tg]["src_id"] != src_id
|
||||||
|
self.traffico_globale[tg] = {"src_id": src_id, "time": ora}
|
||||||
|
|
||||||
|
if nuovo:
|
||||||
|
print(f"[Traffico Globale] Rilevato TX su TG {tg} da ID {src_id}") # <--- AGGIUNGI QUESTA RIGA
|
||||||
|
asyncio.create_task(self.invia_stato_traffico())
|
||||||
|
|
||||||
|
async def invia_stato_traffico(self):
|
||||||
|
"""Invia la lista dei TG attivi a tutti i WebSocket connessi"""
|
||||||
|
attivi = [{"tg": k, "src": cerca_nominativo(v["src_id"])} for k, v in self.traffico_globale.items()]
|
||||||
|
msg_str = json.dumps({"action": "global_traffic", "data": attivi})
|
||||||
|
for ws in list(self.clients.keys()):
|
||||||
|
try: await ws.send_str(msg_str)
|
||||||
|
except Exception: pass
|
||||||
|
|
||||||
def ricevi_frame_dmr(self, ambe_frames, src_id, tg):
|
def ricevi_frame_dmr(self, ambe_frames, src_id, tg):
|
||||||
if tg not in self.tg_states:
|
if tg not in self.tg_states:
|
||||||
self.tg_states[tg] = {"rx_in_corso": False, "ultimo_src_id": None, "ultimo_frame_time": 0}
|
self.tg_states[tg] = {"rx_in_corso": False, "ultimo_src_id": None, "ultimo_frame_time": 0}
|
||||||
@@ -181,10 +205,12 @@ class WebDmrServer:
|
|||||||
asyncio.create_task(self.processa_audio_dmr(ambe_frames, tg))
|
asyncio.create_task(self.processa_audio_dmr(ambe_frames, tg))
|
||||||
|
|
||||||
async def watchdog_rx(self):
|
async def watchdog_rx(self):
|
||||||
"""Monitora il silenzio e ripristina lo stato per i singoli TG"""
|
"""Monitora il silenzio e ripristina lo stato per i singoli TG e per il traffico globale"""
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(0.4)
|
await asyncio.sleep(0.4)
|
||||||
ora = time.time()
|
ora = time.time()
|
||||||
|
|
||||||
|
# Watchdog TG sintonizzati
|
||||||
for tg, stato_tg in list(self.tg_states.items()):
|
for tg, stato_tg in list(self.tg_states.items()):
|
||||||
if stato_tg["rx_in_corso"] and (ora - stato_tg["ultimo_frame_time"] > 1.2):
|
if stato_tg["rx_in_corso"] and (ora - stato_tg["ultimo_frame_time"] > 1.2):
|
||||||
stato_tg["rx_in_corso"] = False
|
stato_tg["rx_in_corso"] = False
|
||||||
@@ -196,6 +222,15 @@ class WebDmrServer:
|
|||||||
"active": False
|
"active": False
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Watchdog traffico globale
|
||||||
|
cambiamento = False
|
||||||
|
for tg in list(self.traffico_globale.keys()):
|
||||||
|
if ora - self.traffico_globale[tg]["time"] > 1.5:
|
||||||
|
del self.traffico_globale[tg]
|
||||||
|
cambiamento = True
|
||||||
|
if cambiamento:
|
||||||
|
await self.invia_stato_traffico()
|
||||||
|
|
||||||
async def processa_audio_dmr(self, ambe_27_bytes, tg):
|
async def processa_audio_dmr(self, ambe_27_bytes, tg):
|
||||||
try:
|
try:
|
||||||
for i in range(0, len(ambe_27_bytes), 9):
|
for i in range(0, len(ambe_27_bytes), 9):
|
||||||
@@ -264,6 +299,9 @@ async def websocket_handler(request):
|
|||||||
print(f"[WebSocket] Nuovo client connesso (Totali: {len(server_app.clients)}/{MAX_UTENTI_WEB})")
|
print(f"[WebSocket] Nuovo client connesso (Totali: {len(server_app.clients)}/{MAX_UTENTI_WEB})")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Invia subito lo stato del traffico globale al nuovo connesso
|
||||||
|
await server_app.invia_stato_traffico()
|
||||||
|
|
||||||
async for msg in ws:
|
async for msg in ws:
|
||||||
if msg.type == web.WSMsgType.TEXT:
|
if msg.type == web.WSMsgType.TEXT:
|
||||||
dati = json.loads(msg.data)
|
dati = json.loads(msg.data)
|
||||||
|
|||||||
+99
-70
@@ -1,6 +1,10 @@
|
|||||||
|
console.log("App.js caricato - VU Meter & Click-to-Tune attivi!");
|
||||||
|
|
||||||
let ws = null;
|
let ws = null;
|
||||||
let audioCtx = null;
|
let audioCtx = null;
|
||||||
let gainNode = null; // Il controller del volume
|
let gainNode = null;
|
||||||
|
let analyser = null;
|
||||||
|
let dataArray = null;
|
||||||
let nextStartTime = 0;
|
let nextStartTime = 0;
|
||||||
|
|
||||||
const connectBtn = document.getElementById('connectBtn');
|
const connectBtn = document.getElementById('connectBtn');
|
||||||
@@ -8,25 +12,60 @@ const tgInput = document.getElementById('tgInput');
|
|||||||
const setTgBtn = document.getElementById('setTgBtn');
|
const setTgBtn = document.getElementById('setTgBtn');
|
||||||
const displayScreen = document.getElementById('displayScreen');
|
const displayScreen = document.getElementById('displayScreen');
|
||||||
const statusText = document.getElementById('statusText');
|
const statusText = document.getElementById('statusText');
|
||||||
|
|
||||||
// --- CONTROLLI VOLUME ---
|
|
||||||
const volumeSlider = document.getElementById('volumeSlider');
|
const volumeSlider = document.getElementById('volumeSlider');
|
||||||
const volumeValue = document.getElementById('volumeValue');
|
const volumeValue = document.getElementById('volumeValue');
|
||||||
|
const liveTrafficList = document.getElementById('liveTrafficList');
|
||||||
|
const vuMeterBar = document.getElementById('vuMeterBar');
|
||||||
|
|
||||||
volumeSlider.addEventListener('input', (e) => {
|
if(statusText) statusText.innerText = "✅ Sistema pronto. Clicca Avvia Ascolto.";
|
||||||
|
|
||||||
|
if(volumeSlider) {
|
||||||
|
volumeSlider.addEventListener('input', (e) => {
|
||||||
const val = parseFloat(e.target.value);
|
const val = parseFloat(e.target.value);
|
||||||
volumeValue.innerText = Math.round(val * 100) + '%';
|
if(volumeValue) volumeValue.innerText = Math.round(val * 100) + '%';
|
||||||
|
if (gainNode) gainNode.gain.value = val;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Modifica il volume in tempo reale
|
window.setQuickTg = function(valore) {
|
||||||
if (gainNode) {
|
if (tgInput) tgInput.value = valore;
|
||||||
gainNode.gain.value = val;
|
inviaCambioTG(valore);
|
||||||
|
};
|
||||||
|
|
||||||
|
function inviaCambioTG(nuovoTG) {
|
||||||
|
if (!nuovoTG || nuovoTG <= 0) return;
|
||||||
|
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||||
|
ws.send(JSON.stringify({ action: "cambia_tg", tg: nuovoTG }));
|
||||||
|
if(displayScreen) displayScreen.innerText = "SINTONIA...";
|
||||||
|
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;
|
||||||
|
|
||||||
|
analyser.getByteTimeDomainData(dataArray);
|
||||||
|
let sum = 0;
|
||||||
|
for(let i = 0; i < dataArray.length; i++) {
|
||||||
|
let v = (dataArray[i] - 128) / 128.0;
|
||||||
|
sum += v * v;
|
||||||
|
}
|
||||||
|
let rms = Math.sqrt(sum / dataArray.length);
|
||||||
|
let percent = Math.min(100, rms * 500); // Moltiplicatore di sensibilità grafica
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
// --- RIPRODUZIONE AUDIO PCM ---
|
|
||||||
function playPCM320(arrayBuffer) {
|
function playPCM320(arrayBuffer) {
|
||||||
if (!audioCtx || !gainNode) return;
|
if (!audioCtx || !analyser) return;
|
||||||
|
try {
|
||||||
const int16Array = new Int16Array(arrayBuffer);
|
const int16Array = new Int16Array(arrayBuffer);
|
||||||
const float32Array = new Float32Array(int16Array.length);
|
const float32Array = new Float32Array(int16Array.length);
|
||||||
for (let i = 0; i < int16Array.length; i++) {
|
for (let i = 0; i < int16Array.length; i++) {
|
||||||
@@ -39,38 +78,47 @@ function playPCM320(arrayBuffer) {
|
|||||||
const source = audioCtx.createBufferSource();
|
const source = audioCtx.createBufferSource();
|
||||||
source.buffer = buffer;
|
source.buffer = buffer;
|
||||||
|
|
||||||
// Colleghiamo l'audio al controller del volume invece che direttamente all'uscita
|
// Collega al VU meter, che a sua volta è collegato al volume
|
||||||
source.connect(gainNode);
|
source.connect(analyser);
|
||||||
|
|
||||||
const currentTime = audioCtx.currentTime;
|
const currentTime = audioCtx.currentTime;
|
||||||
if (nextStartTime < currentTime) {
|
if (nextStartTime < currentTime) nextStartTime = currentTime + 0.02;
|
||||||
nextStartTime = currentTime + 0.02;
|
|
||||||
}
|
|
||||||
source.start(nextStartTime);
|
source.start(nextStartTime);
|
||||||
nextStartTime += buffer.duration;
|
nextStartTime += buffer.duration;
|
||||||
|
} catch(err) {
|
||||||
|
console.error("Errore audio:", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- CONNESSIONE WEBSOCKET ---
|
|
||||||
function startAudio() {
|
function startAudio() {
|
||||||
|
try {
|
||||||
if (!audioCtx) {
|
if (!audioCtx) {
|
||||||
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||||
|
|
||||||
// Creazione del nodo Volume
|
analyser = audioCtx.createAnalyser();
|
||||||
|
analyser.fftSize = 256;
|
||||||
|
dataArray = new Uint8Array(analyser.frequencyBinCount);
|
||||||
|
|
||||||
gainNode = audioCtx.createGain();
|
gainNode = audioCtx.createGain();
|
||||||
|
|
||||||
|
// Catena: Source -> Analyser(VU) -> Gain(Volume) -> Casse
|
||||||
|
analyser.connect(gainNode);
|
||||||
gainNode.connect(audioCtx.destination);
|
gainNode.connect(audioCtx.destination);
|
||||||
gainNode.gain.value = parseFloat(volumeSlider.value);
|
|
||||||
}
|
if(volumeSlider) gainNode.gain.value = parseFloat(volumeSlider.value);
|
||||||
if (audioCtx.state === 'suspended') {
|
|
||||||
audioCtx.resume();
|
renderVUMeter(); // Avvia l'animazione grafica
|
||||||
}
|
}
|
||||||
|
if (audioCtx.state === 'suspended') audioCtx.resume();
|
||||||
|
if(statusText) statusText.innerText = "🔄 Connessione in corso...";
|
||||||
|
|
||||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
ws = new WebSocket(`${protocol}//${window.location.host}/ws`);
|
ws = new WebSocket(`${protocol}//${window.location.host}/ws`);
|
||||||
ws.binaryType = 'arraybuffer';
|
ws.binaryType = 'arraybuffer';
|
||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
connectBtn.style.display = 'none';
|
if(connectBtn) connectBtn.style.display = 'none';
|
||||||
inviaCambioTG(tgInput.value);
|
if(tgInput) inviaCambioTG(tgInput.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onmessage = (event) => {
|
ws.onmessage = (event) => {
|
||||||
@@ -79,64 +127,45 @@ function startAudio() {
|
|||||||
} else if (typeof event.data === 'string') {
|
} else if (typeof event.data === 'string') {
|
||||||
const data = JSON.parse(event.data);
|
const data = JSON.parse(event.data);
|
||||||
|
|
||||||
// --- GESTIONE ERRORE SERVER PIENO ---
|
if (data.action === "error") return;
|
||||||
if (data.action === "error") {
|
|
||||||
displayScreen.innerText = "SERVER PIENO";
|
|
||||||
displayScreen.style.background = "#e74c3c"; // Rosso[cite: 5]
|
|
||||||
statusText.innerText = "❌ " + data.text;
|
|
||||||
statusText.style.color = "#e74c3c";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.action === "display") {
|
if (data.action === "display") {
|
||||||
|
if(displayScreen) {
|
||||||
displayScreen.innerText = data.text;
|
displayScreen.innerText = data.text;
|
||||||
statusText.style.color = "#bdc3c7"; // Ripristina il colore di default del testo[cite: 5]
|
displayScreen.style.background = data.active ? "#e67e22" : "#1abc9c";
|
||||||
if (data.active) {
|
}
|
||||||
displayScreen.style.background = "#e67e22"; // Arancione durante RX[cite: 5]
|
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...";
|
||||||
} else {
|
} else {
|
||||||
displayScreen.style.background = "#1abc9c"; // Verde in Standby[cite: 5]
|
liveTrafficList.innerHTML = data.data.map(item =>
|
||||||
|
`<div class="traffic-item traffic-clickable" onclick="setQuickTg(${item.tg})" title="Clicca per sintonizzare TG ${item.tg}">
|
||||||
|
<b>TG ${item.tg}</b>: ${item.src}
|
||||||
|
</div>`
|
||||||
|
).join("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = () => {
|
ws.onclose = () => {
|
||||||
// Se il display non è in stato di errore "SERVER PIENO", mostra la riconnessione standard[cite: 5]
|
if(statusText) statusText.innerText = "❌ Connessione persa.";
|
||||||
if (displayScreen.innerText !== "SERVER PIENO") {
|
if(connectBtn) connectBtn.style.display = 'block';
|
||||||
statusText.innerText = "Connessione persa. Riconnessione...";
|
|
||||||
statusText.style.color = "#bdc3c7";
|
|
||||||
connectBtn.style.display = 'block';
|
|
||||||
connectBtn.innerText = "Riconnetti Ricevitore";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
// --- FUNZIONE PER CAMBIARE TG ---
|
} catch (err) {
|
||||||
function inviaCambioTG(nuovoTG) {
|
console.error("Errore in avvio:", err);
|
||||||
if (!nuovoTG || nuovoTG <= 0) return;
|
|
||||||
|
|
||||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
||||||
ws.send(JSON.stringify({ action: "cambia_tg", tg: nuovoTG }));
|
|
||||||
displayScreen.innerText = "SINTONIA...";
|
|
||||||
statusText.innerText = "Sintonizzato su TG " + nuovoTG;
|
|
||||||
} else {
|
|
||||||
statusText.innerText = "Pronto a sintonizzare TG " + nuovoTG;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scelta Rapida dai tasti prefissati
|
if(connectBtn) connectBtn.addEventListener('click', startAudio);
|
||||||
function setQuickTg(valore) {
|
if(setTgBtn) setTgBtn.addEventListener('click', () => { if(tgInput) inviaCambioTG(tgInput.value); });
|
||||||
tgInput.value = valore;
|
if(tgInput) {
|
||||||
inviaCambioTG(valore);
|
tgInput.addEventListener('keypress', (e) => {
|
||||||
|
if (e.key === 'Enter') inviaCambioTG(tgInput.value);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- EVENTI ---
|
|
||||||
connectBtn.addEventListener('click', startAudio);
|
|
||||||
setTgBtn.addEventListener('click', () => inviaCambioTG(tgInput.value));
|
|
||||||
|
|
||||||
// Invio anche premendo "Invio" sulla tastiera dentro la casella di testo
|
|
||||||
tgInput.addEventListener('keypress', (e) => {
|
|
||||||
if (e.key === 'Enter') {
|
|
||||||
inviaCambioTG(tgInput.value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user