Files
genieacs/ui/components/ping.ts
T
Zaid Humaimidi 75908e624f build: migrate eslint to v10 flat config and upgrade typescript
Replace .eslintrc.json with eslint.config.js using the new flat config
format required by ESLint 10. Swap @typescript-eslint/eslint-plugin and
@typescript-eslint/parser for the unified typescript-eslint package.
Upgrade TypeScript to 5.9 and @types/node to 25. Apply automatic code
fixes: remove unused catch bindings and preserve error cause in auth
header parsing.
2026-03-12 14:58:19 -07:00

69 lines
1.6 KiB
TypeScript

import { ClosureComponent, Component, VnodeDOM } from "mithril";
import { m } from "../components.ts";
import * as store from "../store.ts";
const REFRESH_INTERVAL = 3000;
const component: ClosureComponent = (vn): Component => {
let interval: ReturnType<typeof setInterval>;
let host: string;
const refresh = (): void => {
if (!host) {
const dom = (vn as VnodeDOM).dom;
if (dom) dom.innerHTML = "";
return;
}
let status = "";
store
.ping(host)
.then((res) => {
if (res["avg"] != null) status = `${Math.trunc(res["avg"])} ms`;
else status = "Unreachable";
})
.catch(() => {
status = "Error!";
clearInterval(interval);
})
.finally(() => {
const dom = (vn as VnodeDOM).dom;
if (dom) dom.innerHTML = `Pinging ${host}: ${status}`;
});
};
return {
onremove: () => {
clearInterval(interval);
},
view: (vnode) => {
const device = vnode.attrs["device"];
let param =
device["InternetGatewayDevice.ManagementServer.ConnectionRequestURL"];
if (!param)
param = device["Device.ManagementServer.ConnectionRequestURL"];
let h;
try {
const url = new URL(param.value[0]);
h = url.hostname;
} catch {
// Ignore
}
if (host !== h) {
host = h;
clearInterval(interval);
if (host) {
refresh();
interval = setInterval(refresh, REFRESH_INTERVAL);
}
}
return m("div.text-sm my-4", host ? `Pinging ${host}:` : "");
},
};
};
export default component;