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:
parent
e304fd342d
commit
0b7f2401bd
|
|
@ -3,7 +3,8 @@ import { dom } from "./dom.js";
|
||||||
import { prependEvent } from "./events.js";
|
import { prependEvent } from "./events.js";
|
||||||
import { formatValue } from "./points.js";
|
import { formatValue } from "./points.js";
|
||||||
import { state } from "./state.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";
|
import { showToast } from "./api.js";
|
||||||
|
|
||||||
function escapeHtml(text) {
|
function escapeHtml(text) {
|
||||||
|
|
@ -80,6 +81,7 @@ function setWsStatus(connected) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let _reconnectDelay = 1000;
|
let _reconnectDelay = 1000;
|
||||||
|
let _connectedOnce = false;
|
||||||
|
|
||||||
export function startPointSocket() {
|
export function startPointSocket() {
|
||||||
const protocol = location.protocol === "https:" ? "wss" : "ws";
|
const protocol = location.protocol === "https:" ? "wss" : "ws";
|
||||||
|
|
@ -89,6 +91,11 @@ export function startPointSocket() {
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
setWsStatus(true);
|
setWsStatus(true);
|
||||||
_reconnectDelay = 1000;
|
_reconnectDelay = 1000;
|
||||||
|
if (_connectedOnce) {
|
||||||
|
loadUnits().catch(() => {});
|
||||||
|
loadEquipments().catch(() => {});
|
||||||
|
}
|
||||||
|
_connectedOnce = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onmessage = (event) => {
|
ws.onmessage = (event) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue