Compare commits
2 Commits
feat/repor
...
feature/mo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ecdd8027b | ||
| add5f1f4f3 |
72
src/main.js
72
src/main.js
@@ -140,50 +140,6 @@ const GATEWAY_CANDIDATES = [
|
|||||||
"http://10.0.0.1",
|
"http://10.0.0.1",
|
||||||
];
|
];
|
||||||
|
|
||||||
// --- Geolocation via API -----------------------------------------------------
|
|
||||||
|
|
||||||
async function fetchGeoInfo() {
|
|
||||||
try {
|
|
||||||
const res = await fetch("https://freeipapi.com/api/json/");
|
|
||||||
if (!res.ok) return null;
|
|
||||||
return await res.json();
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Telemetry Report --------------------------------------------------------
|
|
||||||
|
|
||||||
function getClientId() {
|
|
||||||
const key = "netwatch_client_id";
|
|
||||||
let id = localStorage.getItem(key);
|
|
||||||
if (!id) {
|
|
||||||
id = crypto.randomUUID();
|
|
||||||
localStorage.setItem(key, id);
|
|
||||||
}
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
const clientId = getClientId();
|
|
||||||
|
|
||||||
function buildReport(state) {
|
|
||||||
return {
|
|
||||||
clientId,
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
geo: state.geoInfo,
|
|
||||||
hosts: state.wan.map((h) => ({
|
|
||||||
name: h.name,
|
|
||||||
url: h.url,
|
|
||||||
status: h.status,
|
|
||||||
history: h.history.map((s) => ({
|
|
||||||
t: s.timestamp,
|
|
||||||
latency: s.latency,
|
|
||||||
error: s.error || null,
|
|
||||||
})),
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Formatting Helpers ------------------------------------------------------
|
// --- Formatting Helpers ------------------------------------------------------
|
||||||
|
|
||||||
function formatUTCTimestamp(date) {
|
function formatUTCTimestamp(date) {
|
||||||
@@ -313,7 +269,6 @@ class AppState {
|
|||||||
this.local = localHosts.map((h) => new HostState(h));
|
this.local = localHosts.map((h) => new HostState(h));
|
||||||
this.paused = false;
|
this.paused = false;
|
||||||
this.tickCount = 0;
|
this.tickCount = 0;
|
||||||
this.geoInfo = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get allHosts() {
|
get allHosts() {
|
||||||
@@ -1176,6 +1131,25 @@ function handleResize(state) {
|
|||||||
async function init() {
|
async function init() {
|
||||||
log.info("NetWatch starting");
|
log.info("NetWatch starting");
|
||||||
|
|
||||||
|
// Mobile detection — show a friendly message and bail out early
|
||||||
|
if (window.innerWidth < 768) {
|
||||||
|
const app = document.getElementById("app");
|
||||||
|
app.innerHTML = `
|
||||||
|
<div class="mx-auto px-[5%] py-8">
|
||||||
|
<header class="mb-8">
|
||||||
|
<h1 class="text-3xl font-bold text-white"><a href="https://git.eeqj.de/sneak/netwatch" target="_blank" rel="noopener" class="underline decoration-dashed decoration-gray-500 underline-offset-4">NetWatch</a> by <a href="https://sneak.berlin" target="_blank" rel="noopener" class="text-blue-400 underline hover:text-blue-300">@sneak</a></h1>
|
||||||
|
<p class="text-gray-400 mt-2">Real-time network connectivity monitor</p>
|
||||||
|
</header>
|
||||||
|
<div style="display:flex;align-items:center;justify-content:center;min-height:50vh;">
|
||||||
|
<div style="background:#1f2937;border:1px solid #374151;border-radius:12px;padding:2rem 1.5rem;text-align:center;max-width:90vw;">
|
||||||
|
<p style="font-size:1.25rem;color:#e5e7eb;margin:0;">Not yet available on mobile.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
log.info("Mobile viewport detected — skipping monitor startup");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Probe common gateway IPs to find the local router
|
// Probe common gateway IPs to find the local router
|
||||||
const gateway = await detectGateway();
|
const gateway = await detectGateway();
|
||||||
const localHosts = [LOCAL_CPE];
|
const localHosts = [LOCAL_CPE];
|
||||||
@@ -1185,9 +1159,6 @@ async function init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const state = new AppState(localHosts);
|
const state = new AppState(localHosts);
|
||||||
fetchGeoInfo().then((geo) => {
|
|
||||||
state.geoInfo = geo;
|
|
||||||
});
|
|
||||||
buildUI(state);
|
buildUI(state);
|
||||||
log.info("UI built, starting tick loop");
|
log.info("UI built, starting tick loop");
|
||||||
|
|
||||||
@@ -1242,11 +1213,6 @@ async function init() {
|
|||||||
doTick();
|
doTick();
|
||||||
let tickIntervalId = setInterval(doTick, CONFIG.updateInterval);
|
let tickIntervalId = setInterval(doTick, CONFIG.updateInterval);
|
||||||
|
|
||||||
setInterval(() => {
|
|
||||||
if (state.tickCount > 1)
|
|
||||||
console.log("NetWatch report:", buildReport(state));
|
|
||||||
}, 60000);
|
|
||||||
|
|
||||||
document
|
document
|
||||||
.getElementById("interval-select")
|
.getElementById("interval-select")
|
||||||
.addEventListener("change", (e) => {
|
.addEventListener("change", (e) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user