feat(ws): refresh units and equipments on WebSocket reconnect

After a disconnect/reconnect, re-fetch units (runtimes) and equipments
(monitor data) so the UI reflects current server state without requiring
a page reload.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
caoqianming 2026-03-26 09:37:00 +08:00
parent e304fd342d
commit 0b7f2401bd
1 changed files with 8 additions and 1 deletions

View File

@ -3,7 +3,8 @@ import { dom } from "./dom.js";
import { prependEvent } from "./events.js";
import { formatValue } from "./points.js";
import { state } from "./state.js";
import { renderUnits } from "./units.js";
import { loadUnits, renderUnits } from "./units.js";
import { loadEquipments } from "./equipment.js";
import { showToast } from "./api.js";
function escapeHtml(text) {
@ -80,6 +81,7 @@ function setWsStatus(connected) {
}
let _reconnectDelay = 1000;
let _connectedOnce = false;
export function startPointSocket() {
const protocol = location.protocol === "https:" ? "wss" : "ws";
@ -89,6 +91,11 @@ export function startPointSocket() {
ws.onopen = () => {
setWsStatus(true);
_reconnectDelay = 1000;
if (_connectedOnce) {
loadUnits().catch(() => {});
loadEquipments().catch(() => {});
}
_connectedOnce = true;
};
ws.onmessage = (event) => {