@sailingrotevista/rotevista-dash 6.0.5 → 6.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.js +44 -32
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -1166,8 +1166,9 @@ function drawGraph(d, id, min, max, isTws, isHercules) {
|
|
|
1166
1166
|
};
|
|
1167
1167
|
|
|
1168
1168
|
let grids = "";
|
|
1169
|
-
//
|
|
1170
|
-
|
|
1169
|
+
// Tracciamo 3 linee simmetriche al 25%, 50% (centrale) e 75%.
|
|
1170
|
+
// La linea al 50% passerà sempre in modo matematicamente esatto dietro il valore medio stampato.
|
|
1171
|
+
[0.25, 0.5, 0.75].forEach(p => grids += `<line x1="0" y1="${h-(p*h)}" x2="${w}" y2="${h-(p*h)}" stroke="rgba(0,0,0,0.12)" stroke-width="0.5" />`);
|
|
1171
1172
|
|
|
1172
1173
|
const gridInterval = (visibleMinutes <= 15) ? 1 : 5;
|
|
1173
1174
|
for (let m = gridInterval; m < visibleMinutes; m += gridInterval) {
|
|
@@ -1316,13 +1317,26 @@ function connect() {
|
|
|
1316
1317
|
let addr = window.location.host || CONFIG.server.fallbackIp;
|
|
1317
1318
|
try {
|
|
1318
1319
|
socket = new WebSocket(`ws://${addr}/signalk/v1/stream?subscribe=self`);
|
|
1319
|
-
|
|
1320
|
+
|
|
1321
|
+
socket.onopen = async () => {
|
|
1322
|
+
ui.status.className = "online";
|
|
1323
|
+
ui.status.innerText = "ONLINE";
|
|
1324
|
+
reconnectDelay = 1000;
|
|
1325
|
+
|
|
1326
|
+
// SINCRONIZZAZIONE AUTOMATICA: Ogni volta che la connessione si apre o si riapre,
|
|
1327
|
+
// scarichiamo lo storico fresco dal server e ridisegnamo i grafici
|
|
1328
|
+
try {
|
|
1329
|
+
await fetchServerHistory();
|
|
1330
|
+
['stw', 'sog', 'depth', 'tws'].forEach(refreshGraph);
|
|
1331
|
+
} catch (err) {
|
|
1332
|
+
console.warn("⚠️ Sincronizzazione storico fallita alla connessione:", err);
|
|
1333
|
+
}
|
|
1334
|
+
};
|
|
1320
1335
|
|
|
1321
1336
|
socket.onmessage = (e) => {
|
|
1322
1337
|
const d = JSON.parse(e.data);
|
|
1323
1338
|
if (d.updates) {
|
|
1324
1339
|
d.updates.forEach(u => {
|
|
1325
|
-
// ESTRAZIONE AVANZATA DELLA SORGENTE (Gestisce $source e stringhe native)
|
|
1326
1340
|
let sourceLabel = "Unknown";
|
|
1327
1341
|
if (u.$source) {
|
|
1328
1342
|
sourceLabel = u.$source;
|
|
@@ -1341,8 +1355,17 @@ function connect() {
|
|
|
1341
1355
|
}
|
|
1342
1356
|
};
|
|
1343
1357
|
|
|
1344
|
-
socket.onclose = () => {
|
|
1345
|
-
|
|
1358
|
+
socket.onclose = () => {
|
|
1359
|
+
if (!simulationMode) {
|
|
1360
|
+
ui.status.className = "offline";
|
|
1361
|
+
ui.status.innerText = "RECONNECTING...";
|
|
1362
|
+
setTimeout(connect, reconnectDelay);
|
|
1363
|
+
reconnectDelay = Math.min(reconnectDelay * 1.5, 10000);
|
|
1364
|
+
}
|
|
1365
|
+
};
|
|
1366
|
+
} catch (e) {
|
|
1367
|
+
setTimeout(connect, reconnectDelay);
|
|
1368
|
+
}
|
|
1346
1369
|
}
|
|
1347
1370
|
|
|
1348
1371
|
// ==========================================================================
|
|
@@ -1365,46 +1388,35 @@ window.addEventListener('contextmenu', e => e.preventDefault(), true);
|
|
|
1365
1388
|
async function init() {
|
|
1366
1389
|
loadDashboardState();
|
|
1367
1390
|
|
|
1368
|
-
//
|
|
1369
|
-
try {
|
|
1370
|
-
await fetchServerHistory();
|
|
1371
|
-
} catch (err) {
|
|
1372
|
-
console.warn("⚠️ Impossibile caricare lo storico dal server.");
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1391
|
+
// Proviamo un primo caricamento configurazioni
|
|
1375
1392
|
await fetchServerConfig();
|
|
1376
1393
|
startDisplayLoop();
|
|
1377
|
-
connect();
|
|
1394
|
+
connect();
|
|
1378
1395
|
|
|
1379
1396
|
setInterval(watchConfigChanges, 10000);
|
|
1380
1397
|
|
|
1381
1398
|
// ==========================================================================
|
|
1382
|
-
//
|
|
1399
|
+
// RICONNESSIONE RAPIDA AL RISVEGLIO (VISIBILITY WATCHDOG)
|
|
1383
1400
|
// ==========================================================================
|
|
1384
1401
|
|
|
1385
|
-
//
|
|
1402
|
+
// Quando sblocchi l'iPad o riapri il browser, forziamo la chiusura del vecchio
|
|
1403
|
+
// WebSocket orfano. Questo farà scattare immediatamente connect() e la sincronizzazione.
|
|
1386
1404
|
document.addEventListener('visibilitychange', () => {
|
|
1387
1405
|
if (document.visibilityState === 'visible') {
|
|
1388
|
-
|
|
1406
|
+
console.log("⏰ Schermo sbloccato: forzatura riconnessione rapida.");
|
|
1407
|
+
if (socket) {
|
|
1408
|
+
try {
|
|
1409
|
+
socket.close(); // Fa scattare onclose -> connect() -> onopen -> fetchServerHistory()
|
|
1410
|
+
} catch (e) {
|
|
1411
|
+
connect();
|
|
1412
|
+
}
|
|
1413
|
+
} else {
|
|
1414
|
+
connect();
|
|
1415
|
+
}
|
|
1389
1416
|
}
|
|
1390
1417
|
});
|
|
1391
|
-
|
|
1392
|
-
// Rileva se il computer è andato in sospensione misurando il ritardo dei secondi
|
|
1393
|
-
let lastHeartbeat = Date.now();
|
|
1394
|
-
setInterval(() => {
|
|
1395
|
-
const now = Date.now();
|
|
1396
|
-
const diff = now - lastHeartbeat;
|
|
1397
|
-
lastHeartbeat = now;
|
|
1398
|
-
|
|
1399
|
-
// Se passano più di 6 secondi tra un ciclo e l'altro (invece di 1 secondo),
|
|
1400
|
-
// significa che il PC era in sospensione. Avviamo il risveglio.
|
|
1401
|
-
if (diff > 6000) {
|
|
1402
|
-
handleWakeUp();
|
|
1403
|
-
}
|
|
1404
|
-
}, 1000);
|
|
1405
1418
|
}
|
|
1406
1419
|
|
|
1407
1420
|
|
|
1408
|
-
|
|
1409
1421
|
window.addEventListener('load', init);
|
|
1410
1422
|
window.addEventListener('pagehide', saveDashboardState);
|