refactor: add typed decoder plugin runtime

This commit is contained in:
sjg
2026-08-01 13:02:54 +02:00
parent 6a83e2e90a
commit 508cf2ba87
23 changed files with 438 additions and 324 deletions
@@ -228,15 +228,15 @@
}
aisWindow.updateAisBar = updateAisBar;
aisWindow.clearAisBar = function() {
aisWindow.resetAisHistoryView?.();
resetAisHistoryView();
};
aisWindow.resetAisHistoryView = function() {
function resetAisHistoryView() {
if (aisMessagesEl) aisMessagesEl.innerHTML = "";
aisMessageHistory = [];
updateAisBar();
renderAisHistory();
aisWindow.clearMapMarkersByType?.("ais");
};
}
function renderAisHistory() {
pruneAisMessageHistory();
if (!aisMessagesEl) {
@@ -272,7 +272,7 @@
rig_id: msg.rig_id || null
};
}
aisWindow.onServerAisBatch = function(messages) {
function onServerAisBatch(messages) {
if (!Array.isArray(messages) || messages.length === 0) return;
if (aisStatus) aisStatus.textContent = "Receiving";
const normalized = [];
@@ -295,21 +295,18 @@
pruneAisMessageHistory();
scheduleAisBarUpdate();
scheduleAisHistoryRender();
};
aisWindow.restoreAisHistory = function(messages) {
aisWindow.onServerAisBatch?.(messages);
};
aisWindow.pruneAisHistoryView = function() {
}
function pruneAisHistoryView() {
pruneAisMessageHistory();
updateAisBar();
renderAisHistory();
};
}
document.getElementById("settings-clear-ais-history")?.addEventListener("click", () => {
void (async () => {
if (!await aisWindow.trxUi.confirm({ title: "Clear AIS history?", message: "All stored AIS messages will be permanently removed.", confirmLabel: "Clear history" })) return;
try {
await aisWindow.postPath?.("/clear_ais_decode");
aisWindow.resetAisHistoryView?.();
resetAisHistoryView();
} catch (e) {
console.error("AIS history clear failed", e);
}
@@ -321,10 +318,17 @@
renderAisHistory();
});
}
aisWindow.onServerAis = function(msg) {
function onServerAis(msg) {
if (aisStatus) aisStatus.textContent = "Receiving";
addAisMessage(normalizeServerAisMessage(msg));
};
}
updateAisSummary();
aisWindow._trxDrainPendingDecode?.("ais");
window.trxPluginRuntime.registerDecoder({
id: "ais",
onMessage: onServerAis,
onBatch: onServerAisBatch,
restore: onServerAisBatch,
reset: resetAisHistoryView,
prune: pruneAisHistoryView
});
})();