signalk-livedepth-plugin 0.3.13 → 0.3.16
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/CHANGELOG.md +28 -0
- package/dist/config.d.ts +3 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +6 -0
- package/dist/config.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/public/js/render-worker.js +8 -2
- package/public/js/render-worker.js.map +2 -2
- package/public/js/renderer.js +58 -6
- package/public/js/renderer.js.map +2 -2
package/public/js/renderer.js
CHANGED
|
@@ -897,7 +897,7 @@ var PLUGIN_ID = "signalk-livedepth-plugin";
|
|
|
897
897
|
var ASSET_BASE = `/plotterext/${PLUGIN_ID}`;
|
|
898
898
|
var BATHY_BASE = `${ASSET_BASE}/bathymetry`;
|
|
899
899
|
var DEBOUNCE_MS = 400;
|
|
900
|
-
var TILE_PAD = 0.
|
|
900
|
+
var TILE_PAD = 0.1;
|
|
901
901
|
var MAX_LAT = 85;
|
|
902
902
|
var fetchedBounds = null;
|
|
903
903
|
function padBounds(bounds, pad) {
|
|
@@ -920,7 +920,7 @@ var LIVE_FLUSH_MS = 300;
|
|
|
920
920
|
var DEFAULT_DEPTH_PATH = "environment.depth.belowTransducer";
|
|
921
921
|
var client = await connectExtension();
|
|
922
922
|
var worker = new Worker(
|
|
923
|
-
new URL(`./render-worker.js?v=${"0.3.
|
|
923
|
+
new URL(`./render-worker.js?v=${"0.3.16"}`, import.meta.url),
|
|
924
924
|
{ type: "module" }
|
|
925
925
|
);
|
|
926
926
|
var settings = { ...DEFAULT_SETTINGS };
|
|
@@ -931,6 +931,7 @@ var showFootprint = false;
|
|
|
931
931
|
var baseSamples = [];
|
|
932
932
|
var lastReq = null;
|
|
933
933
|
var busy = false;
|
|
934
|
+
var busyTimer;
|
|
934
935
|
var dirty = false;
|
|
935
936
|
var rendering = null;
|
|
936
937
|
var renderingLive = false;
|
|
@@ -941,6 +942,8 @@ var perfFrameMs = 0;
|
|
|
941
942
|
var framesSeen = 0;
|
|
942
943
|
var framesSince = Date.now();
|
|
943
944
|
var timer;
|
|
945
|
+
var paused = false;
|
|
946
|
+
var historyPoll;
|
|
944
947
|
var pendingLive = [];
|
|
945
948
|
var liveFlushTimer;
|
|
946
949
|
async function loadSettings() {
|
|
@@ -1042,11 +1045,12 @@ async function fetchTiles(req) {
|
|
|
1042
1045
|
publishBase();
|
|
1043
1046
|
}
|
|
1044
1047
|
function schedule() {
|
|
1048
|
+
if (paused) return;
|
|
1045
1049
|
clearTimeout(timer);
|
|
1046
1050
|
timer = setTimeout(() => void refresh(), DEBOUNCE_MS);
|
|
1047
1051
|
}
|
|
1048
1052
|
async function refresh() {
|
|
1049
|
-
if (!settings.enabled) return;
|
|
1053
|
+
if (paused || !settings.enabled) return;
|
|
1050
1054
|
if (settings.source === "history") {
|
|
1051
1055
|
await fetchHistory();
|
|
1052
1056
|
} else if (lastReq) {
|
|
@@ -1092,6 +1096,33 @@ function stopLive() {
|
|
|
1092
1096
|
void liveUnsub?.();
|
|
1093
1097
|
liveUnsub = void 0;
|
|
1094
1098
|
}
|
|
1099
|
+
function pauseRenderer() {
|
|
1100
|
+
if (paused) return;
|
|
1101
|
+
paused = true;
|
|
1102
|
+
clearTimeout(timer);
|
|
1103
|
+
timer = void 0;
|
|
1104
|
+
clearTimeout(busyTimer);
|
|
1105
|
+
busyTimer = void 0;
|
|
1106
|
+
busy = false;
|
|
1107
|
+
rendering = null;
|
|
1108
|
+
if (liveFlushTimer) {
|
|
1109
|
+
clearInterval(liveFlushTimer);
|
|
1110
|
+
liveFlushTimer = void 0;
|
|
1111
|
+
}
|
|
1112
|
+
if (historyPoll) {
|
|
1113
|
+
clearInterval(historyPoll);
|
|
1114
|
+
historyPoll = void 0;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
function resumeRenderer() {
|
|
1118
|
+
if (!paused) return;
|
|
1119
|
+
paused = false;
|
|
1120
|
+
if (liveUnsub) liveFlushTimer = setInterval(flushLive, LIVE_FLUSH_MS);
|
|
1121
|
+
historyPoll = setInterval(() => {
|
|
1122
|
+
if (settings.enabled && settings.source === "history") schedule();
|
|
1123
|
+
}, POLL_MS);
|
|
1124
|
+
schedule();
|
|
1125
|
+
}
|
|
1095
1126
|
var livePosition = null;
|
|
1096
1127
|
var liveDepth = null;
|
|
1097
1128
|
var liveHeading;
|
|
@@ -1113,7 +1144,7 @@ function sampleLive() {
|
|
|
1113
1144
|
pendingLive.push({ lon, lat, depth: liveDepth });
|
|
1114
1145
|
}
|
|
1115
1146
|
function flushLive() {
|
|
1116
|
-
if (pendingLive.length === 0) return;
|
|
1147
|
+
if (paused || pendingLive.length === 0) return;
|
|
1117
1148
|
const live = pendingLive;
|
|
1118
1149
|
pendingLive = [];
|
|
1119
1150
|
worker.postMessage({ type: "live", samples: live });
|
|
@@ -1121,14 +1152,30 @@ function flushLive() {
|
|
|
1121
1152
|
if (lastReq) draw(true);
|
|
1122
1153
|
}
|
|
1123
1154
|
function draw(live = false) {
|
|
1124
|
-
if (busy || !lastReq || !settings.enabled) return;
|
|
1155
|
+
if (paused || busy || !lastReq || !settings.enabled) return;
|
|
1125
1156
|
if (live && Date.now() - lastLiveAt < liveInterval) return;
|
|
1126
1157
|
busy = true;
|
|
1127
1158
|
rendering = lastReq;
|
|
1128
1159
|
renderingLive = live;
|
|
1129
1160
|
dirty = false;
|
|
1161
|
+
clearTimeout(busyTimer);
|
|
1162
|
+
busyTimer = setTimeout(() => {
|
|
1163
|
+
if (!busy) return;
|
|
1164
|
+
console.warn("[LiveDepth] render worker did not answer; retrying");
|
|
1165
|
+
busy = false;
|
|
1166
|
+
rendering = null;
|
|
1167
|
+
if (lastReq) draw();
|
|
1168
|
+
}, 4e3);
|
|
1130
1169
|
worker.postMessage({ type: "render", req: rendering });
|
|
1131
1170
|
}
|
|
1171
|
+
worker.onerror = (e) => {
|
|
1172
|
+
console.warn("[LiveDepth] render worker error:", e.message);
|
|
1173
|
+
clearTimeout(busyTimer);
|
|
1174
|
+
busy = false;
|
|
1175
|
+
rendering = null;
|
|
1176
|
+
dirty = true;
|
|
1177
|
+
if (lastReq) draw();
|
|
1178
|
+
};
|
|
1132
1179
|
worker.onmessage = (e) => {
|
|
1133
1180
|
const msg = e.data;
|
|
1134
1181
|
if (msg.type === "perf") {
|
|
@@ -1136,6 +1183,7 @@ worker.onmessage = (e) => {
|
|
|
1136
1183
|
perfFrameMs = msg.frameMs;
|
|
1137
1184
|
return;
|
|
1138
1185
|
}
|
|
1186
|
+
clearTimeout(busyTimer);
|
|
1139
1187
|
const req = rendering;
|
|
1140
1188
|
const live = renderingLive;
|
|
1141
1189
|
busy = false;
|
|
@@ -1187,7 +1235,11 @@ await client.subscribe(["state.changed"], () => void loadSettings());
|
|
|
1187
1235
|
await loadMeta();
|
|
1188
1236
|
await loadSettings();
|
|
1189
1237
|
await loadUnits();
|
|
1190
|
-
setInterval(() => {
|
|
1238
|
+
historyPoll = setInterval(() => {
|
|
1191
1239
|
if (settings.enabled && settings.source === "history") schedule();
|
|
1192
1240
|
}, POLL_MS);
|
|
1241
|
+
document.addEventListener("visibilitychange", () => {
|
|
1242
|
+
if (document.visibilityState === "hidden") pauseRenderer();
|
|
1243
|
+
else resumeRenderer();
|
|
1244
|
+
});
|
|
1193
1245
|
//# sourceMappingURL=renderer.js.map
|