Ham HF band toggle preset and prevent some multiple-SSE shenanigans when searching and typing letters quickly

This commit is contained in:
Ian Renton
2025-12-30 14:51:49 +00:00
parent f4ae6b610e
commit 5bf45dba46
2 changed files with 21 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
// SSE event source
let evtSource;
let restartSSEOnErrorTimeoutId;
// Table row count, to alternate shading
let rowCount = 0;
@@ -30,6 +31,9 @@ function loadSpots() {
// Start an SSE connection (closing an existing one if it exists). This will then be used to add to the table on the
// fly.
function startSSEConnection() {
if (evtSource != null) {
evtSource.close();
}
evtSource = new EventSource('/api/v1/spots/stream' + buildQueryString());
evtSource.onmessage = function(event) {
@@ -66,8 +70,11 @@ function startSSEConnection() {
};
evtSource.onerror = function(err) {
evtSource.close();
setTimeout(startSSEConnection, 1000);
if (evtSource != null) {
evtSource.close();
}
clearTimeout(restartSSEOnErrorTimeoutId)
restartSSEOnErrorTimeoutId = setTimeout(startSSEConnection, 1000);
};
}