mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-02-04 09:14:30 +00:00
Ham HF band toggle preset and prevent some multiple-SSE shenanigans when searching and typing letters quickly
This commit is contained in:
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user