cameras: RTSP preview via ffmpeg, stop opening VLC, drop masscan to 200pps
All checks were successful
build-and-deploy / build (push) Successful in 2m23s

Masscan finds are rtsp:// with no snapshot_url, so the popup skipped the
<img> and the leftover source link handed the OS an rtsp:// URL (VLC).

- Popup always hits /api/cameras/{id}/snapshot (HTTP stills, then one
  ffmpeg frame grab). No credentials. 10s hard timeout.
- rtsp:// is rendered as text, never as an href.
- ffmpeg added to the app image for the RTSP still/MJPEG path.
- Default MASSCAN_RATE 200 (1k/10k saturated the home uplink).
This commit is contained in:
Sirius DevOps 2026-08-24 23:36:34 -04:00
commit 12262d1562
6 changed files with 268 additions and 27 deletions

View file

@ -1025,16 +1025,33 @@ function esc(s) {
return String(s == null ? '' : s).replace(/[&<>"']/g,
c => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
}
function camSourceLink(c) {
const url = c.source_url || '';
if (!url) return '';
// Never emit an rtsp:// href — the OS opens VLC (or another player).
if (url.toLowerCase().startsWith('rtsp://')) {
const host = url.replace(/^rtsp:\/\//i, '').replace(/\/.*$/, '');
return `<span style="color:var(--muted)">RTSP ${esc(host)}:554</span>`;
}
return `<a href="${esc(url)}" target="_blank" rel="noopener">source page ↗</a>`;
}
function camThumb(c) {
// 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>';
// Preview is always served by the dashboard (never a raw rtsp:// href —
// browsers hand those to VLC). HTTP cams stream live MJPEG; RTSP/masscan
// finds grab a still via /snapshot (ffmpeg / HTTP probe). Fallback:
// live stream → still snapshot → placeholder.
if (!c.id) return '<div class="thumb placeholder">no preview available</div>';
const isRtsp = (c.device_type === 'rtsp')
|| String(c.source_url || '').toLowerCase().startsWith('rtsp://')
|| String(c.snapshot_url || '').toLowerCase().startsWith('rtsp://');
const first = isRtsp
? `/api/cameras/${esc(c.id)}/snapshot`
: `/api/cameras/${esc(c.id)}/stream`;
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}">`;
return `<img class="thumb" src="${first}" alt="camera preview" loading="lazy" onerror="${onerr}">`;
}
async function loadCams() {
if (!map) return;
@ -1059,7 +1076,7 @@ async function loadCams() {
`<tr><td class="k">Last seen</td><td>${esc((c.last_seen||'').slice(0,16).replace('T',' '))}</td></tr>` +
`<tr><td class="k">Coords</td><td>${(c.lat!=null&&c.lon!=null) ? c.lat.toFixed(3)+', '+c.lon.toFixed(3) : 'unknown'}</td></tr>` +
`</table>` +
(c.source_url ? `<a href="${esc(c.source_url)}" target="_blank" rel="noopener">source page ↗</a>` : '') +
camSourceLink(c) +
`</div>`);
}));
camsGroup.addTo(map);