mirror of
https://github.com/smittix/intercept.git
synced 2026-04-24 06:40:00 -07:00
Tear down satellite dashboard cleanly
This commit is contained in:
@@ -789,6 +789,9 @@
|
|||||||
let _dashboardRetryAttempts = 0;
|
let _dashboardRetryAttempts = 0;
|
||||||
let _satelliteSelectionRequestToken = 0;
|
let _satelliteSelectionRequestToken = 0;
|
||||||
let _lastSatelliteCatalogRefresh = 0;
|
let _lastSatelliteCatalogRefresh = 0;
|
||||||
|
let _pageTearingDown = false;
|
||||||
|
let _clockTimer = null;
|
||||||
|
let _countdownTimer = null;
|
||||||
const passCache = new Map();
|
const passCache = new Map();
|
||||||
const telemetryCache = new Map();
|
const telemetryCache = new Map();
|
||||||
const transmitterCache = new Map();
|
const transmitterCache = new Map();
|
||||||
@@ -1247,6 +1250,7 @@
|
|||||||
let satelliteSSE = null;
|
let satelliteSSE = null;
|
||||||
|
|
||||||
function startSSETracking() {
|
function startSSETracking() {
|
||||||
|
if (_pageTearingDown) return;
|
||||||
if (satelliteSSE) return;
|
if (satelliteSSE) return;
|
||||||
satelliteSSE = new EventSource('/satellite/stream_satellite');
|
satelliteSSE = new EventSource('/satellite/stream_satellite');
|
||||||
satelliteSSE.onmessage = (e) => {
|
satelliteSSE.onmessage = (e) => {
|
||||||
@@ -1256,9 +1260,12 @@
|
|||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
};
|
};
|
||||||
satelliteSSE.onerror = () => {
|
satelliteSSE.onerror = () => {
|
||||||
|
if (_pageTearingDown) return;
|
||||||
// Reconnect automatically after 5s
|
// Reconnect automatically after 5s
|
||||||
if (satelliteSSE) { satelliteSSE.close(); satelliteSSE = null; }
|
if (satelliteSSE) { satelliteSSE.close(); satelliteSSE = null; }
|
||||||
setTimeout(startSSETracking, 5000);
|
setTimeout(() => {
|
||||||
|
if (!_pageTearingDown) startSSETracking();
|
||||||
|
}, 5000);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1635,7 +1642,25 @@
|
|||||||
// Refresh the catalog on focus only occasionally, and do not clobber
|
// Refresh the catalog on focus only occasionally, and do not clobber
|
||||||
// working pass/telemetry panes when we already have cached state.
|
// working pass/telemetry panes when we already have cached state.
|
||||||
window.addEventListener('focus', refreshSatelliteCatalogOnFocus);
|
window.addEventListener('focus', refreshSatelliteCatalogOnFocus);
|
||||||
window.addEventListener('pagehide', () => {
|
function teardownSatelliteDashboard() {
|
||||||
|
_pageTearingDown = true;
|
||||||
|
stopSSETracking();
|
||||||
|
if (_telemetryPollTimer) {
|
||||||
|
clearInterval(_telemetryPollTimer);
|
||||||
|
_telemetryPollTimer = null;
|
||||||
|
}
|
||||||
|
if (_clockTimer) {
|
||||||
|
clearInterval(_clockTimer);
|
||||||
|
_clockTimer = null;
|
||||||
|
}
|
||||||
|
if (_countdownTimer) {
|
||||||
|
clearInterval(_countdownTimer);
|
||||||
|
_countdownTimer = null;
|
||||||
|
}
|
||||||
|
if (_dashboardRetryTimer) {
|
||||||
|
clearTimeout(_dashboardRetryTimer);
|
||||||
|
_dashboardRetryTimer = null;
|
||||||
|
}
|
||||||
if (_telemetryAbortController) {
|
if (_telemetryAbortController) {
|
||||||
_telemetryAbortController.abort();
|
_telemetryAbortController.abort();
|
||||||
_telemetryAbortController = null;
|
_telemetryAbortController = null;
|
||||||
@@ -1649,7 +1674,17 @@
|
|||||||
_passTimeoutId = null;
|
_passTimeoutId = null;
|
||||||
}
|
}
|
||||||
closePacketModal();
|
closePacketModal();
|
||||||
});
|
if (_gsEventSource) {
|
||||||
|
_gsEventSource.close();
|
||||||
|
_gsEventSource = null;
|
||||||
|
}
|
||||||
|
if (window.GroundStationWaterfall) {
|
||||||
|
GroundStationWaterfall.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('pagehide', teardownSatelliteDashboard);
|
||||||
|
window.addEventListener('beforeunload', teardownSatelliteDashboard);
|
||||||
window.addEventListener('keydown', (event) => {
|
window.addEventListener('keydown', (event) => {
|
||||||
if (event.key === 'Escape') {
|
if (event.key === 'Escape') {
|
||||||
closePacketModal();
|
closePacketModal();
|
||||||
@@ -1658,6 +1693,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
_pageTearingDown = false;
|
||||||
_satelliteSelectionRequestToken += 1;
|
_satelliteSelectionRequestToken += 1;
|
||||||
renderPacketPanels();
|
renderPacketPanels();
|
||||||
loadTrackedSatelliteCatalog();
|
loadTrackedSatelliteCatalog();
|
||||||
@@ -1667,8 +1703,8 @@
|
|||||||
const usedShared = applySharedObserverLocation();
|
const usedShared = applySharedObserverLocation();
|
||||||
initGroundMap();
|
initGroundMap();
|
||||||
updateClock();
|
updateClock();
|
||||||
setInterval(updateClock, 1000);
|
_clockTimer = setInterval(updateClock, 1000);
|
||||||
setInterval(updateCountdown, 1000);
|
_countdownTimer = setInterval(updateCountdown, 1000);
|
||||||
// In standalone mode, start SSE tracking immediately.
|
// In standalone mode, start SSE tracking immediately.
|
||||||
// In embedded mode, wait for parent to signal visibility.
|
// In embedded mode, wait for parent to signal visibility.
|
||||||
if (!isEmbedded) {
|
if (!isEmbedded) {
|
||||||
|
|||||||
Reference in New Issue
Block a user