Standbild HiRes

This commit is contained in:
chk
2026-06-07 10:53:27 +02:00
parent 8055c375fc
commit 8d56a8fe35
3 changed files with 18 additions and 13 deletions

View File

@@ -38,24 +38,27 @@ function stopStream(cam) {
log(cam.id, 'Live aus');
}
// ── Snapshot-Modus (stream:false): alle 5 s ein Einzelbild ──────────────────
// Kein Video der Server öffnet das Gerät pro Snapshot kurz (one-shot). Fehler
// (z. B. Gerät gerade durch HD-Grab belegt) werden still übersprungen, das letzte
// gute Bild bleibt stehen.
const SNAPSHOT_INTERVAL_MS = 5000;
// ── Snapshot-Modus (stream:false): alle 15 s ein HD-Einzelbild ──────────────
// Kein Video pro Snapshot holt der Viewer ein Bild in HD-Auflösung (/hires,
// pro Kamera in cameras.json konfiguriert). Da nur 1 Bild / 15 s übertragen wird,
// ist HD hier bandbreiten-unkritisch und liefert das beste Standbild. Der Server
// öffnet das Gerät pro Grab kurz und schliesst es wieder. Fehler (z. B. Gerät
// gerade belegt) werden still übersprungen, das letzte gute Bild bleibt stehen.
const SNAPSHOT_INTERVAL_MS = 15000;
async function fetchSnapshot(cam) {
if (!cam.snapshotActive) return;
try {
const r = await fetch(`/api/snapshot/${encodeURIComponent(cam.id)}?t=${Date.now()}`,
{ signal: AbortSignal.timeout(8000) });
const r = await fetch(`/api/snapshot/${encodeURIComponent(cam.id)}/hires?t=${Date.now()}`,
{ signal: AbortSignal.timeout(20000) });
if (!r.ok) { setInfo(cam, `Snapshot-Fehler (HTTP ${r.status})`, 'warn'); return; }
const blob = await r.blob();
const w = r.headers.get('X-Frame-Width') || '?';
const url = URL.createObjectURL(blob);
cam.img.src = url;
if (cam.lastBlobUrl) URL.revokeObjectURL(cam.lastBlobUrl);
cam.lastBlobUrl = url;
setInfo(cam, `Einzelbild · ${new Date().toLocaleTimeString()}`, 'ok');
setInfo(cam, `Einzelbild ${w}px · ${new Date().toLocaleTimeString()}`, 'ok');
} catch (_e) {
setInfo(cam, 'Snapshot-Timeout', 'warn');
}