fix(cctv): label a refused viewer's frame fallback instead of the live row

/frame now keeps a pullable HLS camera's shared health, so a viewer
refused for capacity saw its placeholder or Street View frame under the
live row's LIVE · OK badge and "Live HLS connected". When a video camera
is shown on its frame fallback while the row says live, the panel badge
now reads FALLBACK · DEGRADED and the meta line drops the live message;
the shared row stays as it is for the other viewers.
This commit is contained in:
German Khokhlov committed 2026-11-20 12:29:50 +04:00
1 parent 0bebd59b69
commit 58d2c23860
5 files changed
+113 -7

No files matched your search

+3 -2
View File
@@ -1,4 +1,5 @@
- Stop reporting a live HLS camera as degraded when a viewer is refused because
every viewer or session slot is taken: the refusal answers 503 with
`Retry-After`, and the frame shown in its place leaves the camera's health
as it was (asturksever, gekh, #1267).
`Retry-After`, the frame shown in its place leaves the camera's health
as it was, and that viewer's panel labels the frame `FALLBACK · DEGRADED`
rather than live (asturksever, gekh, #1267).
+3 -1
View File
@@ -9658,7 +9658,9 @@ coexist with at most eight independent consumer leases each; no-access lease
expiry is 15 seconds. A viewer refused because every lease or session slot is
taken gets 503 with `Retry-After: 2` and leaves the camera's health unchanged;
so does its frame fallback, since an HLS camera without a snapshot has no frame
of its own. Closing one consumer leaves other consumers running. Lease
of its own. That viewer's panel badge reads FALLBACK · DEGRADED and its meta
line drops the live health message, since the shared live health does not
describe the frame it shows. Closing one consumer leaves other consumers running. Lease
ids use `crypto.randomUUID` where the page is a secure context and an equivalent
v4 id from `crypto.getRandomValues` on plain-HTTP LAN pages. Encrypted/fMP4/byte-range playlists fail
closed. Performance and live agency reliability require recorded validation.
+85
View File
@@ -0,0 +1,85 @@
// Reproduction: a viewer refused for HLS capacity is shown its fallback frame
// under a badge that still reads the shared live health ("LIVE · OK").
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { HLS_LIMITS } from '../../server/providers/cctv/stream.js';
import { mountCctvProvider } from '../testSupport/cctvProviderHarness.mjs';
import { presentCctvSourceBadge } from '../ui/cctvFrames.js';
import { presentCctvPanel } from '../ui/cctvPresentation.js';
const SAME_ORIGIN = { host: 'localhost:4173', 'sec-fetch-site': 'same-origin' };
const PLAYLIST =
'#EXTM3U\n#EXT-X-TARGETDURATION:2\n#EXT-X-MEDIA-SEQUENCE:12\n#EXTINF:2,\na.ts\n#EXTINF:2,\nb.ts\n#EXTINF:2,\nc.ts\n';
const lease = (index) =>
`00000000-0000-4000-8000-${String(index).padStart(12, '0')}`;
const camera = (id) => ({
id,
name: id,
lat: 30.27,
lon: -97.74,
feedType: 'hls',
url: `https://cams.upstream.invalid/${id}/list.m3u8`,
});
test('a capacity-refused viewer is not shown its fallback frame as live and ok', async (t) => {
assert.equal(HLS_LIMITS.sessions, 2);
const { call, health } = mountCctvProvider(t, {
cameras: ['cam-a', 'cam-b', 'cam-c'].map(camera),
fetch: async (url) =>
new Response(String(url).endsWith('.m3u8') ? PLAYLIST : 'abc'),
});
const open = (id, index) =>
call(`/media/${id}?lease=${lease(index)}`, SAME_ORIGIN);
// cam-c played earlier and was released: its row is live/ok.
assert.equal((await open('cam-c', 0)).statusCode, 200);
assert.equal(
(await call(`/media/cam-c?lease=${lease(0)}`, SAME_ORIGIN, 'DELETE'))
.statusCode,
204,
);
// Two other viewers now hold both camera sessions.
assert.equal((await open('cam-a', 1)).statusCode, 200);
assert.equal((await open('cam-b', 2)).statusCode, 200);
// The cam-c viewer is refused and falls back to the frame.
const refused = await open('cam-c', 3);
assert.equal(refused.statusCode, 503);
const frame = await call('/frame/cam-c', SAME_ORIGIN);
assert.equal(frame.statusCode, 200);
assert.equal(frame.headers['X-CCTV-Source'], 'synthetic');
assert.match(frame.body, /UPSTREAM UNAVAILABLE/);
const row = await health('cam-c');
// The badge the panel derives for this viewer, in image (fallback) mode.
const shown = {
feedType: 'hls',
isVideo: false,
sourceKind: row?.sourceKind || 'configured',
sourceStatus: row?.status || 'unknown',
sourceMessage: row?.message || '',
};
const badge = presentCctvSourceBadge(shown, true, {
loading: false,
error: false,
hasFrame: true,
});
assert.notEqual(
badge.label,
'LIVE · OK',
`fallback frame (${frame.headers['X-CCTV-Source']}) labelled ${badge.label}; health message "${row?.message}"`,
);
const { meta } = presentCctvPanel(
{
enabled: true,
activeCameraId: 'cam-c',
activeCamera: {
...shown,
id: 'cam-c',
city: 'Austin',
headingDeg: 0,
fovDeg: 60,
rangeM: 100,
},
},
true,
);
assert.doesNotMatch(meta, /Live HLS connected/);
});
+13
View File
@@ -186,6 +186,14 @@ export function _settleCctvFrame(token, src, ok) {
);
}
/** Shared live health describes the stream even when this viewer shows a frame. */
export function isCctvLiveFrameFallback(activeCamera) {
return (
activeCamera?.isVideo === false &&
String(activeCamera.sourceKind || '').toLowerCase() === 'live'
);
}
/** The source badge's label and frame state for the camera and preview. */
export function presentCctvSourceBadge(activeCamera, enabled, frame) {
if (!enabled || !activeCamera)
@@ -194,6 +202,11 @@ export function presentCctvSourceBadge(activeCamera, enabled, frame) {
return { label: t('FRAME · LOADING'), state: 'loading' };
if (frame.error && !frame.hasFrame)
return { label: t('FRAME · UNAVAILABLE'), state: 'error' };
if (isCctvLiveFrameFallback(activeCamera))
return {
label: `${cctvSourceKindLabel('fallback')} · ${cctvSourceStatusLabel('degraded')}`,
state: 'ready',
};
const kind = cctvSourceKindLabel(
activeCamera.sourceKind || activeCamera.feedType || 'unknown',
);
+9 -4
View File
@@ -1,5 +1,9 @@
import { getLocale, keepCodesWithValues, msg, t, tn } from '../i18n/index.js';
import { cctvSourceLabelText, cctvSourceMessageText } from './cctvFrames.js';
import {
cctvSourceLabelText,
cctvSourceMessageText,
isCctvLiveFrameFallback,
} from './cctvFrames.js';
import { createCctvVideoSurface } from './cctvVideo.js';
import { presentCctvCalibration } from './cctvCalibration.js';
@@ -96,9 +100,10 @@ function metaText(state, enabled, activeCamera, catalogCount) {
const provider = cctvSourceLabelText(
activeCamera.sourceLabel || activeCamera.provider || 'Configured Source',
);
const statusMsg = activeCamera.sourceMessage
? ` · ${cctvSourceMessageText(activeCamera.sourceMessage)}`
: '';
const statusMsg =
activeCamera.sourceMessage && !isCctvLiveFrameFallback(activeCamera)
? ` · ${cctvSourceMessageText(activeCamera.sourceMessage)}`
: '';
// A partner-supplied feed inside a pack names its owner here.
const credit = activeCamera.credit ? ` · ${activeCamera.credit}` : '';
const calBadge = activeCamera.calBadge