Camera popups: live MJPEG preview via /api/cameras/{id}/stream passthrough, snapshot fallback, taller thumb
All checks were successful
build-and-deploy / build (push) Successful in 1m52s
All checks were successful
build-and-deploy / build (push) Successful in 1m52s
This commit is contained in:
parent
1f0b831835
commit
250dbbb5df
2 changed files with 67 additions and 7 deletions
|
|
@ -132,7 +132,7 @@
|
|||
.lp-error { color: var(--red); font-size: 0.68rem; }
|
||||
/* ── Camera popup thumbnail ───────────────────────────────── */
|
||||
.cam-pop { min-width: 210px; max-width: 260px; }
|
||||
.cam-pop .thumb { width: 100%; height: 120px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); margin: 0.3rem 0; box-shadow: 0 0 10px rgba(56,189,248,0.25); background: #0b1220; }
|
||||
.cam-pop .thumb { width: 100%; height: 160px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); margin: 0.3rem 0; box-shadow: 0 0 10px rgba(56,189,248,0.25); background: #0b1220; }
|
||||
.cam-pop .thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.7rem; height: 80px; }
|
||||
.cam-pop table { width: 100%; font-size: 0.72rem; border-collapse: collapse; }
|
||||
.cam-pop td { padding: 0.12rem 0.2rem; vertical-align: top; }
|
||||
|
|
@ -1026,12 +1026,15 @@ function esc(s) {
|
|||
c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
||||
}
|
||||
function camThumb(c) {
|
||||
// Live snapshot proxied through the backend TTL cache. Only render the
|
||||
// <img> when the camera actually has a snapshot URL (else the backend
|
||||
// 404s); onerror swaps to a placeholder so a dead cam never breaks layout.
|
||||
if (!c.snapshot_url) return '<div class="thumb placeholder">no snapshot available</div>';
|
||||
const onerr = "this.classList.add('placeholder'); this.onerror=null; this.alt='snapshot unavailable'; this.removeAttribute('src');";
|
||||
return `<img class="thumb" src="/api/cameras/${esc(c.id)}/snapshot" alt="live snapshot" loading="lazy" onerror="${onerr}">`;
|
||||
// Live preview: stream endpoint proxies the camera's own MJPEG feed, which
|
||||
// browsers render natively in an <img>. Fallback chain on error:
|
||||
// live stream → TTL-cached snapshot → placeholder.
|
||||
if (!c.snapshot_url || !c.id) return '<div class="thumb placeholder">no preview available</div>';
|
||||
const onerr = (
|
||||
"if (!this.dataset.f) { this.dataset.f='1'; this.src='/api/cameras/" + esc(c.id) + "/snapshot'; } " +
|
||||
"else { this.classList.add('placeholder'); this.onerror=null; this.alt='preview unavailable'; this.removeAttribute('src'); }"
|
||||
);
|
||||
return `<img class="thumb" src="/api/cameras/${esc(c.id)}/stream" alt="live camera preview" loading="lazy" onerror="${onerr}">`;
|
||||
}
|
||||
async function loadCams() {
|
||||
if (!map) return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue