@sentinel-nvr/web 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +13 -0
- package/README.md +1 -0
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +3 -1
- package/dist/{chunk-MS6D4OUE.js → chunk-LN4VXI2V.js} +7 -3
- package/dist/chunk-LN4VXI2V.js.map +1 -0
- package/dist/{chunk-Z22KWFHI.js → chunk-MAUN6MNY.js} +172 -24
- package/dist/chunk-MAUN6MNY.js.map +1 -0
- package/dist/{client-BEc4796_.d.ts → client-yrngvMAK.d.ts} +8 -2
- package/dist/{controller-DUCnMIrR.d.ts → controller-B0mPOQml.d.ts} +17 -1
- package/dist/player/index.d.ts +2 -2
- package/dist/player/index.js +2 -1
- package/dist/ui/index.d.ts +6 -4
- package/dist/ui/index.js +77 -43
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/locales/de.json +2 -0
- package/dist/ui/locales/en.json +2 -0
- package/dist/ui/locales/es.json +2 -0
- package/dist/ui/locales/fr.json +2 -0
- package/dist/ui/locales/it.json +2 -0
- package/dist/ui/locales/pt.json +2 -0
- package/dist/ui/locales/sv.json +2 -0
- package/package.json +14 -3
- package/dist/chunk-MS6D4OUE.js.map +0 -1
- package/dist/chunk-Z22KWFHI.js.map +0 -1
package/NOTICE.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
The `/ui` part of `@sentinel-nvr/web` (themes, design tokens, base classes in
|
|
4
|
+
`ui/ui.css` and `src/ui/themes-data.ts`) derives its token values and conventions
|
|
5
|
+
from **HAPulse** (https://github.com/jlnbln/HAPulse), MIT-licensed:
|
|
6
|
+
|
|
7
|
+
MIT License — Copyright (c) 2026 Julian
|
|
8
|
+
|
|
9
|
+
That notice is retained here and in the source files where those values are reused.
|
|
10
|
+
The `/api` and `/player` parts contain no HAPulse-authored code.
|
|
11
|
+
|
|
12
|
+
"Scrypted" is used descriptively to identify the platform the Sentinel NVR plugin
|
|
13
|
+
runs on. This project is not affiliated with or endorsed by Scrypted.
|
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ on older servers, but only get their full behaviour with the matching plugin:
|
|
|
30
30
|
| 0.8.x | 2026-09-24 | jumps with a still picture: `relay-seek&mark=1&avoid=W` answers `{w}`; the still is lifted on the first frame of that width (older servers: timer) |
|
|
31
31
|
| 0.9.x | 2026-09-25 | speed buttons in place: `api/relay-speed` (older servers: a seek to the displayed position); stills fade out two frames after the video runs |
|
|
32
32
|
| 0.10.x | any | calendar days instead of ±24 h (DST days are 23/25 h: no duplicate clips/events on 25.10., "next day" works, time picker and axis on the wall clock), `SentinelSetup.prefix` / `sentinelPublicBase(origin, prefix)` / `exchangeSentinelToken(…, prefix)` for a reverse-proxy path prefix. No server change needed. |
|
|
33
|
+
| 0.11.x | any (storage warning: 2026-09-26) | robustness: the chosen speed survives a new relay session (pause/play, tab switch, recovery), control/seek/poll requests time out, answers of a finished session are ignored, a camera switch stops the old stream at once, forced TURN relay only for 10 min, live watchdog (frozen WebRTC → restart → fallback, WebRTC retried out of a fallback with back-off), MJPEG retry, telemetry rate limit, keyboard shortcuts leave modifiers/buttons alone, fallback transport shown, second deep link to the same camera works, storage-unavailable warning in the hero (`stats.storageOk`). `sideEffects` keeps the CSS, NOTICE.md shipped, react/lucide-react optional peers. |
|
|
33
34
|
|
|
34
35
|
Lab note: headless Chromium reports an 800×600 screen unless `screenWidth/screenHeight` are emulated; the Scrypted
|
|
35
36
|
sink then transcodes every stream to 800 px / 15 fps, which distorts latency and resolution measurements.
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { S as SENTINEL_DAY_MS, a as SENTINEL_ENDPOINT_PATH, b as SENTINEL_EVENT_CLASSES, c as SentinelBox, d as SentinelCamera, e as SentinelClient, f as SentinelClip, g as SentinelClipsResponse, h as SentinelEvent, i as SentinelEventBox, j as SentinelEventClass, k as SentinelHttpError, l as SentinelRecentEvent, m as SentinelRun, n as SentinelSetup, o as SentinelStats, p as SentinelStorageForecast, q as SentinelStorageStatus, r as exchangeSentinelToken, s as parseSentinelSetup, t as sentinelAddDays, u as sentinelAtTime, v as sentinelClassOf, w as sentinelClassesOf, x as sentinelClipIndexFor, y as sentinelClipRuns, z as sentinelDayEnd, A as sentinelDayOf, B as sentinelEntryUrl, C as sentinelEventPlayTs, D as sentinelHumanBytes, E as sentinelLoginBase, F as sentinelMergeDays, G as sentinelPublicBase, H as sentinelStorageForecast, I as sentinelTimelineLink, J as sentinelUrl, K as sentinelWallMarks, L as sentinelWallSeconds } from '../client-
|
|
1
|
+
export { S as SENTINEL_DAY_MS, a as SENTINEL_ENDPOINT_PATH, b as SENTINEL_EVENT_CLASSES, c as SentinelBox, d as SentinelCamera, e as SentinelClient, f as SentinelClip, g as SentinelClipsResponse, h as SentinelEvent, i as SentinelEventBox, j as SentinelEventClass, k as SentinelHttpError, l as SentinelRecentEvent, m as SentinelRun, n as SentinelSetup, o as SentinelStats, p as SentinelStorageForecast, q as SentinelStorageStatus, r as exchangeSentinelToken, s as parseSentinelSetup, t as sentinelAddDays, u as sentinelAtTime, v as sentinelClassOf, w as sentinelClassesOf, x as sentinelClipIndexFor, y as sentinelClipRuns, z as sentinelDayEnd, A as sentinelDayOf, B as sentinelEntryUrl, C as sentinelEventPlayTs, D as sentinelHumanBytes, E as sentinelLoginBase, F as sentinelMergeDays, G as sentinelPublicBase, H as sentinelStorageForecast, I as sentinelTimelineLink, J as sentinelUrl, K as sentinelWallMarks, L as sentinelWallSeconds, M as timeoutSignal } from '../client-yrngvMAK.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Locale-aware, translation-free formatting (Intl only). Word-dependent helpers
|
package/dist/api/index.js
CHANGED
|
@@ -30,8 +30,9 @@ import {
|
|
|
30
30
|
sentinelUrl,
|
|
31
31
|
sentinelWallMarks,
|
|
32
32
|
sentinelWallSeconds,
|
|
33
|
+
timeoutSignal,
|
|
33
34
|
weekdayShorts
|
|
34
|
-
} from "../chunk-
|
|
35
|
+
} from "../chunk-LN4VXI2V.js";
|
|
35
36
|
export {
|
|
36
37
|
SENTINEL_DAY_MS,
|
|
37
38
|
SENTINEL_ENDPOINT_PATH,
|
|
@@ -64,6 +65,7 @@ export {
|
|
|
64
65
|
sentinelUrl,
|
|
65
66
|
sentinelWallMarks,
|
|
66
67
|
sentinelWallSeconds,
|
|
68
|
+
timeoutSignal,
|
|
67
69
|
weekdayShorts
|
|
68
70
|
};
|
|
69
71
|
//# sourceMappingURL=index.js.map
|
|
@@ -223,9 +223,9 @@ var SentinelClient = class {
|
|
|
223
223
|
* fetch (network error) resolves false so the player can recover instead of
|
|
224
224
|
* believing a seek/rate change landed. (The plugin sends CORS on every reply.)
|
|
225
225
|
*/
|
|
226
|
-
async control(path) {
|
|
226
|
+
async control(path, timeoutMs = 8e3) {
|
|
227
227
|
try {
|
|
228
|
-
const r = await fetch(this.url(path), { cache: "no-store" });
|
|
228
|
+
const r = await fetch(this.url(path), { cache: "no-store", signal: timeoutSignal(timeoutMs) });
|
|
229
229
|
return r.ok;
|
|
230
230
|
} catch {
|
|
231
231
|
return false;
|
|
@@ -290,6 +290,9 @@ async function exchangeSentinelToken(origin, username, password, timeoutMs = 1e4
|
|
|
290
290
|
if (typeof j.token !== "string" || !j.token) throw new SentinelHttpError(502, path);
|
|
291
291
|
return j.token;
|
|
292
292
|
}
|
|
293
|
+
function timeoutSignal(ms) {
|
|
294
|
+
return typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function" ? AbortSignal.timeout(ms) : void 0;
|
|
295
|
+
}
|
|
293
296
|
|
|
294
297
|
// src/api/format.ts
|
|
295
298
|
var pad = (n) => String(n).padStart(2, "0");
|
|
@@ -341,6 +344,7 @@ export {
|
|
|
341
344
|
SentinelClient,
|
|
342
345
|
SentinelHttpError,
|
|
343
346
|
exchangeSentinelToken,
|
|
347
|
+
timeoutSignal,
|
|
344
348
|
fmtTime,
|
|
345
349
|
fmtTimeSec,
|
|
346
350
|
fmtDay,
|
|
@@ -348,4 +352,4 @@ export {
|
|
|
348
352
|
weekdayShorts,
|
|
349
353
|
hhmmInput
|
|
350
354
|
};
|
|
351
|
-
//# sourceMappingURL=chunk-
|
|
355
|
+
//# sourceMappingURL=chunk-LN4VXI2V.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/api/model.ts","../src/api/client.ts","../src/api/format.ts"],"sourcesContent":["/**\n * Sentinel NVR — DOM-free data model + pure helpers.\n *\n * Mirrors the Sentinel NVR plugin's `docs/API.md` (the binding contract): types,\n * URL/setup parsing, event classification, the playback-start heuristic, the\n * storage forecast the status page computes, and the timeline clip-run merge.\n * No fetch/DOM here — the browser client lives in `client.ts`.\n */\n\n// ---------------------------------------------------------------------------\n// Types (docs/API.md §3)\n// ---------------------------------------------------------------------------\n\n/** UI classes of an event; anything unknown collapses to `motion`. */\nexport type SentinelEventClass = 'person' | 'car' | 'bike' | 'animal' | 'package' | 'motion';\n\nexport const SENTINEL_EVENT_CLASSES: readonly SentinelEventClass[] = [\n 'person', 'car', 'bike', 'animal', 'package', 'motion',\n];\n\nexport type SentinelBox = [number, number, number, number];\n\n/** `api/cameras` entry. */\nexport interface SentinelCamera {\n id: string;\n name: string;\n recording: boolean;\n online: boolean;\n lastSegmentAt?: number;\n eventsToday: number;\n lastEventTs?: number;\n latestThumbId?: string;\n latestTs?: number;\n /** RFC-6381 codec string of the recordings (MSE). */\n codecs?: string;\n}\n\n/** `api/stats`. */\nexport interface SentinelStats {\n cameras: number;\n recording: number;\n eventsToday: number;\n segments: number;\n bytes: number;\n earliest?: number;\n retentionDays: number;\n diskFree: number;\n diskTotal: number;\n minFreeBytes: number;\n /** plugin ≥ 2026-09-26: storage root usable (storage guard); false = not recording, nothing deleted. */\n storageOk?: boolean;\n /** why not: 'marker' (share not mounted), 'missing', 'error', 'timeout' */\n storageProblem?: string;\n}\n\n/** `api/recent-events` entry (short form). */\nexport interface SentinelRecentEvent {\n camera: string;\n cameraName: string;\n ts: number;\n startTs?: number;\n classes: string[];\n score: number;\n}\n\nexport interface SentinelEventBox {\n class: string;\n rawClass?: string;\n score: number;\n box: SentinelBox;\n nbox?: SentinelBox;\n}\n\n/** Full event (`api/clips.events`). */\nexport interface SentinelEvent {\n id: string;\n timestamp: number;\n startTs?: number;\n classes: string[];\n score: number;\n source: 'object' | 'motion';\n boxes?: SentinelEventBox[];\n}\n\n/** Recording segment (`api/clips.clips`). */\nexport interface SentinelClip {\n id: string;\n videoId?: string;\n thumbnailId?: string;\n startTime: number;\n duration?: number;\n event?: string;\n detectionClasses?: string[];\n}\n\nexport interface SentinelClipsResponse {\n clips: SentinelClip[];\n events: SentinelEvent[];\n motion: [number, number][];\n codecs?: string;\n}\n\nexport const SENTINEL_DAY_MS = 24 * 60 * 60 * 1000;\n\n// ---------------------------------------------------------------------------\n// Setup / URLs (docs/API.md §1)\n// ---------------------------------------------------------------------------\n\n/** Where the plugin lives below a Scrypted origin. */\nexport const SENTINEL_ENDPOINT_PATH = '/endpoint/@local/sentinel-nvr';\n\nexport interface SentinelSetup {\n /** Scrypted origin, e.g. `https://192.168.2.120:10443` (no trailing slash). */\n origin: string;\n /** Access token found in the pasted URL (`?token=`), if any. */\n token: string | null;\n /**\n * Reverse-proxy path prefix in front of Scrypted's `/endpoint/…` (e.g. `/scrypted` for\n * `https://proxy/scrypted/endpoint/@local/sentinel-nvr/public/`), `''` without one.\n * Only derived when the pasted URL contains `/endpoint/`. Since 0.10.0.\n */\n prefix: string;\n}\n\n/**\n * Turn whatever the user pastes into a clean Scrypted origin (+ token, when the\n * pasted string was Sentinel's embed URL). Accepts a bare host (`https://` is\n * assumed), the Scrypted root, the plugin's login/public path, or the embed\n * URL with `?token=…&embed=1`. Returns null for unusable input.\n */\nexport function parseSentinelSetup(input: string | null | undefined): SentinelSetup | null {\n const raw = (input ?? '').trim();\n if (!raw) return null;\n const withScheme = /^https?:\\/\\//i.test(raw) ? raw : `https://${raw}`;\n let u: URL;\n try {\n u = new URL(withScheme);\n } catch {\n return null;\n }\n if (!u.hostname) return null;\n const token = u.searchParams.get('token');\n const at = u.pathname.indexOf('/endpoint/');\n const prefix = at > 0 ? u.pathname.slice(0, at).replace(/\\/+$/, '') : '';\n return { origin: u.origin, token: token && token.trim() ? token.trim() : null, prefix };\n}\n\n/** Token-guarded machine base (`…/public/`), always with a trailing slash; `prefix` = reverse-proxy path prefix. */\nexport function sentinelPublicBase(origin: string, prefix = ''): string {\n return `${origin.replace(/\\/+$/, '')}${prefix.replace(/\\/+$/, '')}${SENTINEL_ENDPOINT_PATH}/public/`;\n}\n\n/**\n * Human base behind the Scrypted login (`…/sentinel-nvr/`). NOT a link target:\n * without a session Scrypted answers \"Not Authorized\" here. Humans enter via\n * `sentinelEntryUrl` (the public base without a token shows Sentinel's sign-in\n * page, or redirects straight here when a session exists).\n */\nexport function sentinelLoginBase(origin: string): string {\n return `${origin.replace(/\\/+$/, '')}${SENTINEL_ENDPOINT_PATH}/`;\n}\n\n/** Where a human opens Sentinel's own UI: the public base WITHOUT a token (sign-in page / 302 into the session). */\nexport function sentinelEntryUrl(origin: string): string {\n return sentinelPublicBase(origin);\n}\n\n/**\n * Absolute URL for an API/media path below the public base, with the token as\n * a query parameter (a `GET` with a query token is a CORS \"simple request\" —\n * the `x-sentinel-token` header would force a preflight the plugin does not\n * answer; `<img>`/`<video>` sources need the query form anyway).\n */\nexport function sentinelUrl(base: string, token: string, path: string): string {\n const u = base + path;\n if (!token) return u;\n return `${u}${u.includes('?') ? '&' : '?'}token=${encodeURIComponent(token)}`;\n}\n\n/**\n * Deep link into Sentinel's own web UI for a camera timeline — via the entry\n * URL (sign-in or 302 into the session; browsers carry the `#` fragment across\n * the redirect).\n */\nexport function sentinelTimelineLink(origin: string, cameraId: string, atMs?: number): string {\n const q = atMs ? `?at=${Math.round(atMs)}` : '';\n return `${sentinelEntryUrl(origin)}#/timeline/${encodeURIComponent(cameraId)}${q}`;\n}\n\n// ---------------------------------------------------------------------------\n// Events\n// ---------------------------------------------------------------------------\n\nfunction isKnownClass(k: string): k is SentinelEventClass {\n return (SENTINEL_EVENT_CLASSES as readonly string[]).includes(k);\n}\n\n/** Primary class of an event (first known class, else `motion`). */\nexport function sentinelClassOf(ev: { classes?: string[] | undefined }): SentinelEventClass {\n const k = ev.classes?.[0];\n return k !== undefined && isKnownClass(k) ? k : 'motion';\n}\n\n/** Distinct known classes of an event, in order — never empty. */\nexport function sentinelClassesOf(ev: { classes?: string[] | undefined }): SentinelEventClass[] {\n const out: SentinelEventClass[] = [];\n for (const k of ev.classes ?? []) {\n const c: SentinelEventClass = isKnownClass(k) ? k : 'motion';\n if (!out.includes(c)) out.push(c);\n }\n return out.length ? out : [sentinelClassOf(ev)];\n}\n\n/**\n * Where playback starts for an event: 2 s before the first sighting when the\n * detector recorded one, else 3 s before the trigger (docs/API.md §3.3).\n */\nexport function sentinelEventPlayTs(ev: { timestamp?: number; ts?: number; startTs?: number }): number {\n const ts = ev.startTs || ev.ts || ev.timestamp || 0;\n return ev.startTs ? ts - 2000 : ts - 3000;\n}\n\n// ---------------------------------------------------------------------------\n// Storage forecast (docs/API.md §3.2 — the same maths the Sentinel status page uses)\n// ---------------------------------------------------------------------------\n\nexport type SentinelStorageStatus = 'unknown' | 'unreachable' | 'reachable' | 'filling';\n\nexport interface SentinelStorageForecast {\n /** Days spanned by the archive (earliest segment → now). */\n spanDays: number;\n /** Bytes recorded per day (0 until at least an hour of footage exists). */\n ratePerDay: number;\n /** Free-space guard reserve, clamped to the disk size. */\n reserve: number;\n /** Free bytes above the reserve. */\n usableFree: number;\n /** Bytes available for recordings = archive + usable free. */\n capacity: number;\n /** Days the archive can grow to at the current rate (0 = unknown). */\n fitsDays: number;\n /** Days until the reserve is reached (0 = unknown). */\n fillsInDays: number;\n /** The disk is effectively full (free ≤ 2 % above the reserve) → steady-state eviction. */\n steady: boolean;\n /** Bytes used by something other than recordings. */\n other: number;\n /** Which forecast message applies. */\n status: SentinelStorageStatus;\n}\n\nexport function sentinelStorageForecast(st: SentinelStats, nowMs: number = Date.now()): SentinelStorageForecast {\n const spanDays = st.earliest ? Math.max(0, (nowMs - st.earliest) / SENTINEL_DAY_MS) : 0;\n const ratePerDay = spanDays >= 1 / 24 ? st.bytes / Math.max(spanDays, 1 / 24) : 0;\n const reserve = Math.min(st.minFreeBytes || 0, st.diskTotal);\n const usableFree = Math.max(0, st.diskFree - reserve);\n const capacity = st.bytes + usableFree;\n const fitsDays = ratePerDay ? capacity / ratePerDay : 0;\n const fillsInDays = ratePerDay ? usableFree / ratePerDay : 0;\n const steady = usableFree < 0.02 * st.diskTotal;\n const other = Math.max(0, st.diskTotal - st.diskFree - st.bytes);\n let status: SentinelStorageStatus = 'unknown';\n if (ratePerDay) {\n if (fitsDays < st.retentionDays * 0.95) status = 'unreachable';\n else if (steady || spanDays >= st.retentionDays) status = 'reachable';\n else status = 'filling';\n }\n return { spanDays, ratePerDay, reserve, usableFree, capacity, fitsDays, fillsInDays, steady, other, status };\n}\n\n// ---------------------------------------------------------------------------\n// Timeline helpers\n// ---------------------------------------------------------------------------\n\nexport interface SentinelRun { s: number; e: number }\n\n/**\n * Contiguous recording runs: segments whose gap is ≤ `gapMs` (2 s) are drawn as\n * ONE band (otherwise every 60-s segment boundary shows a notch).\n */\nexport function sentinelClipRuns(clips: SentinelClip[], gapMs = 2000): SentinelRun[] {\n const out: SentinelRun[] = [];\n let cur: SentinelRun | null = null;\n for (const c of clips) {\n const e = c.startTime + (c.duration || 0);\n if (cur && c.startTime - cur.e <= gapMs) cur.e = Math.max(cur.e, e);\n else { cur = { s: c.startTime, e }; out.push(cur); }\n }\n return out;\n}\n\n/** Index of the clip covering `ts` (60 s assumed when a duration is missing), −1 if none. */\nexport function sentinelClipIndexFor(clips: SentinelClip[], ts: number): number {\n for (let i = 0; i < clips.length; i++) {\n const c = clips[i]!;\n if (ts >= c.startTime && ts < c.startTime + (c.duration || 60000)) return i;\n }\n return -1;\n}\n\n/** Local-midnight start of the day containing `ts`. */\nexport function sentinelDayOf(ts: number): number {\n return new Date(ts).setHours(0, 0, 0, 0);\n}\n\n// Calendar-day arithmetic. A local day is 23 or 25 hours long on DST change days, so\n// \"day ± 24 h\" lands an hour off midnight there (a second key for the same day, requests\n// shifted by an hour, \"next day\" staying on the same date). Always step calendar days:\n\n/** Local midnight `n` calendar days from the day of `ts`. */\nexport function sentinelAddDays(ts: number, n: number): number {\n const d = new Date(ts);\n d.setHours(0, 0, 0, 0);\n d.setDate(d.getDate() + n);\n return d.getTime();\n}\n\n/** End of the local day of `ts` (= next local midnight). */\nexport function sentinelDayEnd(ts: number): number {\n return sentinelAddDays(ts, 1);\n}\n\n/** Wall-clock time h:m on the local day of `ts` (not `midnight + h·3600 s`, which is an hour off on DST days). */\nexport function sentinelAtTime(ts: number, h: number, m: number, s = 0): number {\n const d = new Date(ts);\n d.setHours(h, m, s, 0);\n return d.getTime();\n}\n\n/**\n * Timestamps of local wall-clock marks every `step` ms (a divisor of a day: 15 s … 6 h) within [from, to],\n * ascending: a 3-h step marks 00:00/03:00/06:00 local time in every time zone (UTC-aligned steps showed\n * 02:00/05:00/08:00 in CEST). On DST days a mark that does not exist is skipped, a repeated hour marked once.\n */\nexport function sentinelWallMarks(from: number, to: number, step: number, max = 8000): number[] {\n const stepSec = Math.max(1, Math.round(step / 1000));\n const out: number[] = [];\n for (let day = sentinelDayOf(from); day <= to && out.length < max; day = sentinelAddDays(day, 1)) {\n const end = sentinelDayEnd(day);\n const regular = end - day === SENTINEL_DAY_MS;\n // only the marks near the window (+1 h slack on DST days)\n const k0 = Math.max(0, Math.floor((from - day - 3600_000) / (stepSec * 1000)));\n const k1 = Math.min(Math.floor(86400 / stepSec), Math.ceil((to - day + 3600_000) / (stepSec * 1000)));\n for (let k = k0; k <= k1 && out.length < max; k++) {\n const sec = k * stepSec;\n if (sec >= 86400) break;\n let t: number;\n if (regular) t = day + sec * 1000;\n else {\n const d = new Date(day);\n d.setHours(Math.floor(sec / 3600), Math.floor((sec % 3600) / 60), sec % 60, 0);\n // a wall time that does not exist (spring gap) normalises to another hour: skip it\n if (d.getHours() * 3600 + d.getMinutes() * 60 + d.getSeconds() !== sec) continue;\n t = d.getTime();\n }\n if (t >= from && t <= to && (!out.length || t > out[out.length - 1]!)) out.push(t);\n }\n }\n return out;\n}\n\n/** Local wall-clock seconds since midnight (for \"is this mark on a label step?\"). */\nexport function sentinelWallSeconds(ts: number): number {\n const d = new Date(ts);\n return d.getHours() * 3600 + d.getMinutes() * 60 + d.getSeconds();\n}\n\n/**\n * Merge per-day clip responses into one sorted, continuous data set. A clip or motion span that\n * crosses midnight comes with both days — kept once (by id / by interval).\n */\nexport function sentinelMergeDays(days: Record<number, SentinelClipsResponse>): {\n clips: SentinelClip[]; events: SentinelEvent[]; motion: [number, number][]; codecs: string | null; oldestDay: number | null;\n} {\n const keys = Object.keys(days).map(Number).sort((a, b) => a - b);\n const clips = new Map<string, SentinelClip>(), events = new Map<string, SentinelEvent>();\n const motionRaw: [number, number][] = [];\n let codecs: string | null = null;\n for (const k of keys) {\n const d = days[k]!;\n for (const c of d.clips) clips.set(c.id, c);\n for (const e of d.events) events.set(e.id || `${e.timestamp}`, e);\n motionRaw.push(...d.motion);\n if (d.codecs) codecs = d.codecs;\n }\n motionRaw.sort((a, b) => a[0] - b[0]);\n const motion: [number, number][] = [];\n for (const m of motionRaw) {\n const last = motion[motion.length - 1];\n if (last && m[0] <= last[1]) last[1] = Math.max(last[1], m[1]);\n else motion.push([m[0], m[1]]);\n }\n return {\n clips: [...clips.values()].sort((a, b) => a.startTime - b.startTime),\n events: [...events.values()].sort((a, b) => a.timestamp - b.timestamp),\n motion,\n codecs,\n oldestDay: keys.length ? keys[0]! : null,\n };\n}\n\n/** Human-readable byte size split into value + unit (binary steps). */\nexport function sentinelHumanBytes(b: number): { value: string; unit: string } {\n if (!b || b <= 0) return { value: '0', unit: 'B' };\n const u = ['B', 'KB', 'MB', 'GB', 'TB'];\n const i = Math.min(u.length - 1, Math.floor(Math.log(b) / Math.log(1024)));\n return { value: (b / Math.pow(1024, i)).toFixed(i ? 1 : 0), unit: u[i]! };\n}\n","/**\n * Browser client for the Sentinel NVR plugin's token-guarded `/public/` endpoint.\n *\n * The plugin sends permissive CORS on every answer (JSON, the 204 control replies,\n * api/segment incl. 206, api/livemse, images, errors) and answers OPTIONS, so a\n * cross-origin static SPA can talk to it directly with `?token=`. Media elements\n * may use crossOrigin=\"anonymous\". Older builds (JSON-only CORS) degrade: control()\n * treats an unreadable reply as delivered; media fetches fall into the next fallback.\n */\n\nimport { sentinelPublicBase, sentinelEntryUrl, sentinelUrl } from './model';\n\nexport class SentinelClient {\n readonly origin: string;\n readonly token: string;\n readonly base: string;\n /** \"Open Sentinel\" target: public base without token → sign-in / 302 into the session. */\n readonly entryUrl: string;\n /** fetch() can read media bodies (segments, live fMP4): the plugin sends CORS on media. */\n readonly corsMedia = true;\n\n /**\n * @param origin Scrypted origin, e.g. https://host:10443\n * @param token access token (empty behind a Scrypted login session)\n * @param opts.base override the request base: needed when the plugin is served\n * under a reverse-proxy prefix, or behind the Scrypted login path\n * (`…/endpoint/@local/sentinel-nvr/`, cookie session, no token). Defaults to\n * the token-guarded public base below `origin`.\n */\n constructor(origin: string, token: string, opts: { base?: string } = {}) {\n this.origin = origin;\n this.token = token;\n this.base = opts.base ? opts.base.replace(/\\/*$/, '/') : sentinelPublicBase(origin);\n this.entryUrl = sentinelEntryUrl(origin);\n }\n\n /** Cache key — a new client is built whenever origin/token change. */\n get key(): string {\n return `${this.origin} ${this.token}`;\n }\n\n url(path: string): string {\n return sentinelUrl(this.base, this.token, path);\n }\n\n /** JSON GET with a timeout (an unreachable host otherwise waits for the browser's TCP timeout). */\n async getJson<T>(path: string, signal?: AbortSignal, timeoutMs = 10_000): Promise<T> {\n const signals: AbortSignal[] = [AbortSignal.timeout(timeoutMs)];\n if (signal) signals.push(signal);\n // AbortSignal.any is Chrome 116 / Safari 17.4+; older engines get the timeout signal alone.\n const combined = typeof AbortSignal.any === 'function' ? AbortSignal.any(signals) : signals[0]!;\n const r = await fetch(this.url(path), { cache: 'no-store', signal: combined });\n if (!r.ok) throw new SentinelHttpError(r.status, path);\n return (await r.json()) as T;\n }\n\n /**\n * Fire a control GET (204 = ok, 404 = session gone). Resolves `r.ok`; a rejected\n * fetch (network error) resolves false so the player can recover instead of\n * believing a seek/rate change landed. (The plugin sends CORS on every reply.)\n */\n async control(path: string, timeoutMs = 8000): Promise<boolean> {\n try {\n // bounded: a hanging control request kept the player's \"one in flight\" gate closed for good\n const r = await fetch(this.url(path), { cache: 'no-store', signal: timeoutSignal(timeoutMs) });\n return r.ok;\n } catch {\n return false;\n }\n }\n\n /** Text POST (client telemetry). Best effort, never throws. */\n postText(path: string, body: string): void {\n try {\n void fetch(this.url(path), { method: 'POST', body, keepalive: true }).catch(() => { /* telemetry only */ });\n } catch { /* ignore */ }\n }\n\n /** WebSocket signaling URL (the plugin's Engine.IO handler). */\n signalingUrl(cameraId: string, params: Record<string, string> = {}): string {\n const u = new URL(this.url(''));\n u.protocol = u.protocol === 'https:' ? 'wss:' : 'ws:';\n u.hash = '';\n u.searchParams.set('camera', cameraId);\n u.searchParams.set('signaling', '1');\n for (const [k, v] of Object.entries(params)) u.searchParams.set(k, v);\n return u.href;\n }\n\n // ---- media URL helpers (all <img>/<video>-loadable) ----\n snapshotUrl(cameraId: string, bust?: number): string {\n return this.url(`api/snapshot?camera=${encodeURIComponent(cameraId)}`) + (bust != null ? `&_=${bust}` : '');\n }\n eventThumbUrl(cameraId: string, ts: number): string {\n return this.url(`api/evthumb?camera=${encodeURIComponent(cameraId)}&ts=${Math.round(ts)}`);\n }\n eventFrameUrl(cameraId: string, ts: number): string {\n return this.url(`api/evframe?camera=${encodeURIComponent(cameraId)}&ts=${Math.round(ts)}`);\n }\n segmentThumbUrl(thumbId: string): string {\n return this.url(`api/thumb?id=${encodeURIComponent(thumbId)}`);\n }\n}\n\nexport class SentinelHttpError extends Error {\n readonly status: number;\n constructor(status: number, path: string) {\n super(`${status} ${path}`);\n this.name = 'SentinelHttpError';\n this.status = status;\n }\n}\n\n/**\n * Trade Scrypted credentials for the plugin's access token (`POST …/public/api/token-exchange`,\n * plugin ≥ 2026-09-22). Rejects with `SentinelHttpError`: 401 wrong credentials, 403 token access\n * switched off in the plugin or (plugin ≥ 2026-09-26) not a Scrypted admin, 404 plugin too old,\n * 429 too many attempts, 503 Scrypted login unavailable; 0 = unreachable. `prefix` = reverse-proxy\n * path prefix (SentinelSetup.prefix, since 0.10.0).\n */\nexport async function exchangeSentinelToken(origin: string, username: string, password: string, timeoutMs = 10_000, prefix = ''): Promise<string> {\n const path = 'api/token-exchange';\n let r: Response;\n try {\n r = await fetch(sentinelPublicBase(origin, prefix) + path, {\n method: 'POST', cache: 'no-store', signal: AbortSignal.timeout(timeoutMs),\n headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }),\n });\n } catch {\n throw new SentinelHttpError(0, path);\n }\n if (!r.ok) throw new SentinelHttpError(r.status, path);\n const j = (await r.json()) as { token?: unknown };\n if (typeof j.token !== 'string' || !j.token) throw new SentinelHttpError(502, path);\n return j.token;\n}\n\n/** AbortSignal that fires after `ms` (undefined on engines without AbortSignal.timeout — Safari < 16). */\nexport function timeoutSignal(ms: number): AbortSignal | undefined {\n return typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function' ? AbortSignal.timeout(ms) : undefined;\n}\n","/**\n * Locale-aware, translation-free formatting (Intl only). Word-dependent helpers\n * (relative time, \"N days\") live in @sentinel-nvr/ui, which owns the i18n dictionary.\n */\n\nconst pad = (n: number) => String(n).padStart(2, '0');\n\n/** HH:MM in the viewer's locale (24 h where the locale uses it). */\nexport function fmtTime(ts: number, locale: string): string {\n return new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit' }).format(ts);\n}\n\n/** HH:MM:SS. */\nexport function fmtTimeSec(ts: number, locale: string): string {\n return new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', second: '2-digit' }).format(ts);\n}\n\n/** \"Mon 8 Sep\" style day label. */\nexport function fmtDay(ts: number, locale: string): string {\n return new Intl.DateTimeFormat(locale, { weekday: 'short', day: 'numeric', month: 'short' }).format(ts);\n}\n\n/** Month + year for a date-picker header. */\nexport function fmtMonthYear(ts: number, locale: string): string {\n return new Intl.DateTimeFormat(locale, { month: 'long', year: 'numeric' }).format(ts);\n}\n\n/** Weekday short names (Monday first) for a date-picker grid. */\nexport function weekdayShorts(locale: string): string[] {\n const f = new Intl.DateTimeFormat(locale, { weekday: 'short' });\n // 2024-01-01 is a Monday.\n return Array.from({ length: 7 }, (_, i) => f.format(new Date(2024, 0, 1 + i)));\n}\n\n/** HH:MM string for a <input type=\"time\">. */\nexport function hhmmInput(ts: number): string {\n const d = new Date(ts);\n return `${pad(d.getHours())}:${pad(d.getMinutes())}`;\n}\n"],"mappings":";AAgBO,IAAM,yBAAwD;AAAA,EACnE;AAAA,EAAU;AAAA,EAAO;AAAA,EAAQ;AAAA,EAAU;AAAA,EAAW;AAChD;AAoFO,IAAM,kBAAkB,KAAK,KAAK,KAAK;AAOvC,IAAM,yBAAyB;AAqB/B,SAAS,mBAAmB,OAAwD;AACzF,QAAM,OAAO,SAAS,IAAI,KAAK;AAC/B,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,aAAa,gBAAgB,KAAK,GAAG,IAAI,MAAM,WAAW,GAAG;AACnE,MAAI;AACJ,MAAI;AACF,QAAI,IAAI,IAAI,UAAU;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACA,MAAI,CAAC,EAAE,SAAU,QAAO;AACxB,QAAM,QAAQ,EAAE,aAAa,IAAI,OAAO;AACxC,QAAM,KAAK,EAAE,SAAS,QAAQ,YAAY;AAC1C,QAAM,SAAS,KAAK,IAAI,EAAE,SAAS,MAAM,GAAG,EAAE,EAAE,QAAQ,QAAQ,EAA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AY,QAAwB;AAC/D,SAAO,IAAI,KAAK,eAAe,QAAQ,EAAE,OAAO,QAAQ,MAAM,UAAU,CAAC,EAAE,OAAO,EAAE;AACtF;AAGO,SAAS,cAAc,QAA0B;AACtD,QAAM,IAAI,IAAI,KAAK,eAAe,QAAQ,EAAE,SAAS,QAAQ,CAAC;AAE9D,SAAO,MAAM,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE,OAAO,IAAI,KAAK,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;AAC/E;AAGO,SAAS,UAAU,IAAoB;AAC5C,QAAM,IAAI,IAAI,KAAK,EAAE;AACrB,SAAO,GAAG,IAAI,EAAE,SAAS,CAAC,CAAC,IAAI,IAAI,EAAE,WAAW,CAAC,CAAC;AACpD;","names":[]}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
timeoutSignal
|
|
3
|
+
} from "./chunk-LN4VXI2V.js";
|
|
4
|
+
|
|
1
5
|
// src/player/rlog.ts
|
|
2
6
|
var brand = "web";
|
|
3
7
|
var client = null;
|
|
@@ -5,8 +9,25 @@ function setRlogClient(c, b) {
|
|
|
5
9
|
client = c;
|
|
6
10
|
if (b) brand = b;
|
|
7
11
|
}
|
|
12
|
+
var PER_MIN = 20;
|
|
13
|
+
var SAME_TAG_MS = 5e3;
|
|
14
|
+
var sent = [];
|
|
15
|
+
var lastByTag = /* @__PURE__ */ new Map();
|
|
16
|
+
var dropped = 0;
|
|
8
17
|
function rlog(tag, data) {
|
|
9
18
|
if (!client) return;
|
|
19
|
+
const now = Date.now();
|
|
20
|
+
sent = sent.filter((t) => now - t < 6e4);
|
|
21
|
+
if (sent.length >= PER_MIN || now - (lastByTag.get(tag) ?? -Infinity) < SAME_TAG_MS) {
|
|
22
|
+
dropped++;
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
sent.push(now);
|
|
26
|
+
lastByTag.set(tag, now);
|
|
27
|
+
if (dropped) {
|
|
28
|
+
data = { ...data ?? {}, dropped };
|
|
29
|
+
dropped = 0;
|
|
30
|
+
}
|
|
10
31
|
let line;
|
|
11
32
|
try {
|
|
12
33
|
line = JSON.stringify({ tag, b: brand, d: data ?? null, ua: navigator.userAgent.slice(0, 80) });
|
|
@@ -17,7 +38,9 @@ function rlog(tag, data) {
|
|
|
17
38
|
}
|
|
18
39
|
|
|
19
40
|
// src/player/webrtc.ts
|
|
20
|
-
var
|
|
41
|
+
var forceRelayUntil = 0;
|
|
42
|
+
var FORCE_RELAY_MS = 10 * 6e4;
|
|
43
|
+
var relayForced = () => Date.now() < forceRelayUntil;
|
|
21
44
|
function mobileClient() {
|
|
22
45
|
return /iPhone|iPod|Android|Mobile/i.test(navigator.userAgent) || navigator.maxTouchPoints > 1 && Math.min(screen.width || 9999, screen.height || 9999) < 920;
|
|
23
46
|
}
|
|
@@ -67,8 +90,8 @@ var WebRtcSession = class {
|
|
|
67
90
|
this.connectT = window.setTimeout(() => {
|
|
68
91
|
if (this.active && this.ws === ws && !this.connected) {
|
|
69
92
|
rlog("connect-timeout", { kind: this.opts.mode, ice: this.pc?.iceConnectionState });
|
|
70
|
-
if (!
|
|
71
|
-
|
|
93
|
+
if (!relayForced()) {
|
|
94
|
+
forceRelayUntil = Date.now() + FORCE_RELAY_MS;
|
|
72
95
|
rlog("retry-relay-only", { kind: this.opts.mode });
|
|
73
96
|
this.stop();
|
|
74
97
|
this.start();
|
|
@@ -145,7 +168,7 @@ var WebRtcSession = class {
|
|
|
145
168
|
ensurePc(setup) {
|
|
146
169
|
if (this.pc) return this.pc;
|
|
147
170
|
let cfg = setup && setup.configuration || { iceServers: [{ urls: "stun:stun.l.google.com:19302" }] };
|
|
148
|
-
if (
|
|
171
|
+
if (relayForced()) cfg = { ...cfg, iceTransportPolicy: "relay" };
|
|
149
172
|
const pc = new RTCPeerConnection(cfg);
|
|
150
173
|
this.pc = pc;
|
|
151
174
|
if (setup?.datachannel) {
|
|
@@ -200,16 +223,16 @@ var WebRtcSession = class {
|
|
|
200
223
|
if (r.type === "inbound-rtp" && (r.kind || r.mediaType) === "audio") aBytes = r.bytesReceived || 0;
|
|
201
224
|
});
|
|
202
225
|
if (dec <= 0) {
|
|
203
|
-
rlog("dec-check-fail", { kind: this.opts.mode, dec, recv, vBytes, aBytes, relayForced:
|
|
204
|
-
if (!
|
|
205
|
-
|
|
226
|
+
rlog("dec-check-fail", { kind: this.opts.mode, dec, recv, vBytes, aBytes, relayForced: relayForced() });
|
|
227
|
+
if (!relayForced() && vBytes <= 0 && aBytes <= 0) {
|
|
228
|
+
forceRelayUntil = Date.now() + FORCE_RELAY_MS;
|
|
206
229
|
rlog("retry-relay-only", { kind: this.opts.mode });
|
|
207
230
|
this.stop();
|
|
208
231
|
this.start();
|
|
209
232
|
return;
|
|
210
233
|
}
|
|
211
234
|
this.fail("no-decode");
|
|
212
|
-
} else rlog("dec-ok", { kind: this.opts.mode, dec, relayForced:
|
|
235
|
+
} else rlog("dec-ok", { kind: this.opts.mode, dec, relayForced: relayForced() });
|
|
213
236
|
}).catch(() => {
|
|
214
237
|
});
|
|
215
238
|
}, this.opts.mode === "live" ? 5e3 : 9e3);
|
|
@@ -359,6 +382,13 @@ var PlayerController = class {
|
|
|
359
382
|
stallTimer = 0;
|
|
360
383
|
destroyed = false;
|
|
361
384
|
liveRestartT = 0;
|
|
385
|
+
// live watchdog (presented frames), MJPEG retry, periodic WebRTC retry out of a fallback, relay-pos in flight
|
|
386
|
+
liveWd = { last: -1, at: 0, since: 0 };
|
|
387
|
+
mjpegRetries = 0;
|
|
388
|
+
mjpegRetryT = 0;
|
|
389
|
+
liveUpgradeAt = 0;
|
|
390
|
+
liveUpgradeN = 0;
|
|
391
|
+
rwPosBusy = false;
|
|
362
392
|
unlisten = [];
|
|
363
393
|
arPrefix;
|
|
364
394
|
constructor(api, opts) {
|
|
@@ -466,6 +496,7 @@ var PlayerController = class {
|
|
|
466
496
|
this.unlisten.push(() => document.removeEventListener("visibilitychange", vis));
|
|
467
497
|
const edge = window.setInterval(() => {
|
|
468
498
|
if (this.live && this.L.active) this.liveEdge();
|
|
499
|
+
if (this.live) this.liveWatch();
|
|
469
500
|
}, 1e3);
|
|
470
501
|
this.unlisten.push(() => clearInterval(edge));
|
|
471
502
|
}
|
|
@@ -477,17 +508,32 @@ var PlayerController = class {
|
|
|
477
508
|
clearTimeout(this.liveRestartT);
|
|
478
509
|
this.liveRestartT = 0;
|
|
479
510
|
}
|
|
511
|
+
if (this.mjpegRetryT) {
|
|
512
|
+
clearTimeout(this.mjpegRetryT);
|
|
513
|
+
this.mjpegRetryT = 0;
|
|
514
|
+
}
|
|
480
515
|
this.recWebrtcTeardown();
|
|
481
516
|
this.webrtcTeardown();
|
|
482
517
|
this.mseTeardown();
|
|
483
518
|
this.liveTeardown();
|
|
484
519
|
this.chaseAbort();
|
|
485
520
|
if (this.pendingT) clearInterval(this.pendingT);
|
|
521
|
+
if (this.freezeT) {
|
|
522
|
+
clearTimeout(this.freezeT);
|
|
523
|
+
this.freezeT = 0;
|
|
524
|
+
}
|
|
486
525
|
for (const u of this.unlisten) u();
|
|
487
526
|
try {
|
|
488
527
|
this.v.pause();
|
|
489
528
|
this.v.srcObject = null;
|
|
490
529
|
this.v.removeAttribute("src");
|
|
530
|
+
this.v.onloadedmetadata = null;
|
|
531
|
+
} catch {
|
|
532
|
+
}
|
|
533
|
+
try {
|
|
534
|
+
this.img.onload = null;
|
|
535
|
+
this.img.onerror = null;
|
|
536
|
+
this.img.removeAttribute("src");
|
|
491
537
|
} catch {
|
|
492
538
|
}
|
|
493
539
|
}
|
|
@@ -495,6 +541,7 @@ var PlayerController = class {
|
|
|
495
541
|
if (camId !== this.camId) {
|
|
496
542
|
this.recWebrtcDisabled = false;
|
|
497
543
|
this.recoveries = 0;
|
|
544
|
+
if (this.camId) this.stopStreams();
|
|
498
545
|
}
|
|
499
546
|
this.camId = camId;
|
|
500
547
|
this.camName = name;
|
|
@@ -506,6 +553,39 @@ var PlayerController = class {
|
|
|
506
553
|
if (ar) this.stage.style.setProperty("--stage-ar", ar);
|
|
507
554
|
else this.stage.style.removeProperty("--stage-ar");
|
|
508
555
|
}
|
|
556
|
+
/** Stop every stream and clear the stage (camera switch): no picture of the old camera stays. */
|
|
557
|
+
stopStreams() {
|
|
558
|
+
this.chaseAbort();
|
|
559
|
+
if (this.liveRestartT) {
|
|
560
|
+
clearTimeout(this.liveRestartT);
|
|
561
|
+
this.liveRestartT = 0;
|
|
562
|
+
}
|
|
563
|
+
if (this.mjpegRetryT) {
|
|
564
|
+
clearTimeout(this.mjpegRetryT);
|
|
565
|
+
this.mjpegRetryT = 0;
|
|
566
|
+
}
|
|
567
|
+
this.recWebrtcTeardown();
|
|
568
|
+
this.webrtcTeardown();
|
|
569
|
+
this.mseTeardown();
|
|
570
|
+
this.liveTeardown();
|
|
571
|
+
this.live = false;
|
|
572
|
+
this.recPaused = false;
|
|
573
|
+
this.recPausedTs = null;
|
|
574
|
+
this.hiddenTs = null;
|
|
575
|
+
this.playIndex = -1;
|
|
576
|
+
this.curClipId = null;
|
|
577
|
+
try {
|
|
578
|
+
this.v.pause();
|
|
579
|
+
this.v.srcObject = null;
|
|
580
|
+
this.v.removeAttribute("src");
|
|
581
|
+
this.v.onloadedmetadata = null;
|
|
582
|
+
} catch {
|
|
583
|
+
}
|
|
584
|
+
this.setMjpeg(false);
|
|
585
|
+
this.freezeHide();
|
|
586
|
+
this.transport = "none";
|
|
587
|
+
this.setLabel("loading");
|
|
588
|
+
}
|
|
509
589
|
/** picture aspect → stage box (mobile layout uses it); posters and video both report it */
|
|
510
590
|
setAspect(w, h) {
|
|
511
591
|
if (!w || !h) return;
|
|
@@ -870,7 +950,10 @@ var PlayerController = class {
|
|
|
870
950
|
setMjpeg(on) {
|
|
871
951
|
this.img.classList.toggle("hidden", !on);
|
|
872
952
|
this.v.classList.toggle("hidden", on);
|
|
873
|
-
if (!on)
|
|
953
|
+
if (!on) {
|
|
954
|
+
this.img.onerror = null;
|
|
955
|
+
this.img.removeAttribute("src");
|
|
956
|
+
}
|
|
874
957
|
}
|
|
875
958
|
webrtcTeardown() {
|
|
876
959
|
this.w?.stop();
|
|
@@ -910,6 +993,7 @@ var PlayerController = class {
|
|
|
910
993
|
this.safePlay();
|
|
911
994
|
this.transport = "webrtc";
|
|
912
995
|
this.setLabel("liveWebrtc");
|
|
996
|
+
this.liveWd = { last: this.presentedFrames(), at: Date.now() + 8e3, since: Date.now() };
|
|
913
997
|
},
|
|
914
998
|
onFail: () => {
|
|
915
999
|
if (this.w === s) this.liveFallbackMse();
|
|
@@ -919,6 +1003,50 @@ var PlayerController = class {
|
|
|
919
1003
|
this.transport = "webrtc";
|
|
920
1004
|
s.start();
|
|
921
1005
|
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Live health, once a second while live and visible:
|
|
1008
|
+
* - WebRTC: no presented frame for 8 s (a 'disconnected' ICE that never turns 'failed' froze the picture under the
|
|
1009
|
+
* "Live" label) → restart, after 3 restarts in a row the MSE/MJPEG fallback;
|
|
1010
|
+
* - 30 s of flowing frames reset the restart counter (it only ever grew → MJPEG for good after 5 hiccups);
|
|
1011
|
+
* - in a fallback (MSE/MJPEG) WebRTC is tried again every 2 minutes.
|
|
1012
|
+
*/
|
|
1013
|
+
liveWatch() {
|
|
1014
|
+
if (document.visibilityState === "hidden" || this.destroyed) return;
|
|
1015
|
+
const now = Date.now();
|
|
1016
|
+
if (this.transport === "webrtc" && this.w?.active && this.v.srcObject) {
|
|
1017
|
+
const q = this.presentedFrames();
|
|
1018
|
+
const W = this.liveWd;
|
|
1019
|
+
if (q !== W.last) {
|
|
1020
|
+
W.last = q;
|
|
1021
|
+
if (now > W.at) W.at = now;
|
|
1022
|
+
if (now - W.since > 3e4) {
|
|
1023
|
+
this.L.restarts = 0;
|
|
1024
|
+
this.liveUpgradeN = 0;
|
|
1025
|
+
W.since = now;
|
|
1026
|
+
}
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
if (now - W.at > 8e3) {
|
|
1030
|
+
this.L.restarts++;
|
|
1031
|
+
rlog("live-stall", { n: this.L.restarts, pf: q, ice: this.w.pc?.iceConnectionState });
|
|
1032
|
+
if (this.L.restarts > 3) this.liveFallbackMse();
|
|
1033
|
+
else this.liveStartWebrtc();
|
|
1034
|
+
}
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
if ((this.transport === "mse" || this.transport === "mjpeg") && window.RTCPeerConnection && window.WebSocket && !this.w) {
|
|
1038
|
+
if (!this.liveUpgradeAt) this.liveUpgradeAt = now + [12e4, 3e5, 9e5][Math.min(this.liveUpgradeN, 2)];
|
|
1039
|
+
else if (now > this.liveUpgradeAt) {
|
|
1040
|
+
this.liveUpgradeAt = 0;
|
|
1041
|
+
this.liveUpgradeN++;
|
|
1042
|
+
this.L.restarts = 0;
|
|
1043
|
+
rlog("live-upgrade", { from: this.transport, n: this.liveUpgradeN });
|
|
1044
|
+
if (this.transport === "mjpeg") this.freezeFromImage(this.img, true, false, "mjpeg");
|
|
1045
|
+
else this.freezeShow(true);
|
|
1046
|
+
this.liveStartWebrtc();
|
|
1047
|
+
}
|
|
1048
|
+
} else this.liveUpgradeAt = 0;
|
|
1049
|
+
}
|
|
922
1050
|
liveFallbackMse() {
|
|
923
1051
|
this.webrtcTeardown();
|
|
924
1052
|
if (!this.live) return;
|
|
@@ -1084,14 +1212,26 @@ var PlayerController = class {
|
|
|
1084
1212
|
this.v.pause();
|
|
1085
1213
|
} catch {
|
|
1086
1214
|
}
|
|
1215
|
+
const cam = this.camId;
|
|
1087
1216
|
this.img.onload = () => {
|
|
1088
1217
|
this.img.onload = null;
|
|
1218
|
+
this.mjpegRetries = 0;
|
|
1089
1219
|
if (this.live) this.freezeLift(0);
|
|
1090
1220
|
};
|
|
1221
|
+
this.img.onerror = () => {
|
|
1222
|
+
if (!this.live || this.camId !== cam || this.transport !== "mjpeg" || this.destroyed || this.mjpegRetries >= 3) return;
|
|
1223
|
+
const wait = 2e3 * 2 ** this.mjpegRetries++;
|
|
1224
|
+
rlog("mjpeg-retry", { n: this.mjpegRetries });
|
|
1225
|
+
if (this.mjpegRetryT) clearTimeout(this.mjpegRetryT);
|
|
1226
|
+
this.mjpegRetryT = window.setTimeout(() => {
|
|
1227
|
+
this.mjpegRetryT = 0;
|
|
1228
|
+
if (this.live && this.camId === cam && this.transport === "mjpeg") this.img.src = this.api.url(`api/live?camera=${encodeURIComponent(cam)}`) + `&_=${Date.now()}`;
|
|
1229
|
+
}, wait);
|
|
1230
|
+
};
|
|
1091
1231
|
this.transport = "mjpeg";
|
|
1092
1232
|
this.setLabel("liveMjpeg");
|
|
1093
1233
|
this.setMjpeg(true);
|
|
1094
|
-
this.img.src = this.api.url(`api/live?camera=${encodeURIComponent(
|
|
1234
|
+
this.img.src = this.api.url(`api/live?camera=${encodeURIComponent(cam)}`) + `&_=${Date.now()}`;
|
|
1095
1235
|
}
|
|
1096
1236
|
// ---- RECORDED via relay -----------------------------------------------------------------
|
|
1097
1237
|
recWebrtcOk() {
|
|
@@ -1150,9 +1290,10 @@ var PlayerController = class {
|
|
|
1150
1290
|
this.setLabel("loading");
|
|
1151
1291
|
this.rwStartMs = ts;
|
|
1152
1292
|
this.rwBase = null;
|
|
1153
|
-
this.rwRate =
|
|
1293
|
+
this.rwRate = 1;
|
|
1154
1294
|
this.rwSrate = 1;
|
|
1155
1295
|
this.seekTarget = ts;
|
|
1296
|
+
this.cmdSeq++;
|
|
1156
1297
|
const compat = mobileClient();
|
|
1157
1298
|
if (compat) rlog("rec-compat-start", { ts: Math.round(ts) });
|
|
1158
1299
|
const s = new WebRtcSession(this.api, { camId: this.camId, mode: "recorded", startMs: ts, compat }, {
|
|
@@ -1190,14 +1331,13 @@ var PlayerController = class {
|
|
|
1190
1331
|
if (this.rw === s) this.recFallbackMse(ts);
|
|
1191
1332
|
},
|
|
1192
1333
|
onSessionId: () => {
|
|
1193
|
-
if (this.rw
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
}
|
|
1334
|
+
if (this.rw !== s) return;
|
|
1335
|
+
const p = this.rwPending;
|
|
1336
|
+
this.rwPending = null;
|
|
1337
|
+
if (p && Math.abs(p.ts - this.rwStartMs) > 1500) {
|
|
1338
|
+
if (p.mark) this.freezeCurrent();
|
|
1339
|
+
this.recRelaySeek(p.ts, p.rate, p.srate, p.mark);
|
|
1340
|
+
} else if (this.rate !== 1) this.recRelaySpeed(this.rate);
|
|
1201
1341
|
}
|
|
1202
1342
|
});
|
|
1203
1343
|
this.sessFrames0 = this.presentedFrames();
|
|
@@ -1276,6 +1416,7 @@ var PlayerController = class {
|
|
|
1276
1416
|
}
|
|
1277
1417
|
const seq = this.cmdSeq;
|
|
1278
1418
|
const done = (ok, w) => {
|
|
1419
|
+
if (this.rw !== s) return;
|
|
1279
1420
|
this.rwSeekBusy = false;
|
|
1280
1421
|
if (!ok) {
|
|
1281
1422
|
this.relayRecover();
|
|
@@ -1292,7 +1433,7 @@ var PlayerController = class {
|
|
|
1292
1433
|
if (p && this.rw?.id) this.recRelaySeek(p.ts, p.rate, p.srate, p.mark);
|
|
1293
1434
|
};
|
|
1294
1435
|
const q = `api/relay-seek?session=${encodeURIComponent(s.id)}&start=${Math.round(ts)}&rate=${rate}&srate=${srate}` + (mark ? `&mark=1&avoid=${this.shownW || this.v.videoWidth || 0}` : "");
|
|
1295
|
-
fetch(this.api.url(q), { cache: "no-store" }).then((r) => {
|
|
1436
|
+
fetch(this.api.url(q), { cache: "no-store", signal: timeoutSignal(1e4) }).then((r) => {
|
|
1296
1437
|
if (!r.ok) return done(false, 0);
|
|
1297
1438
|
if (r.status === 200) return r.json().then((j) => done(true, Number(j?.w) || 0), () => done(true, 0));
|
|
1298
1439
|
return done(true, 0);
|
|
@@ -1343,8 +1484,10 @@ var PlayerController = class {
|
|
|
1343
1484
|
this.cad.lastNew = Date.now();
|
|
1344
1485
|
this.rwTargetBusy = true;
|
|
1345
1486
|
this.api.control(`api/relay-target?session=${encodeURIComponent(s.id)}&ts=${Math.round(ts)}`).then((ok) => {
|
|
1487
|
+
if (this.rw !== s) return;
|
|
1346
1488
|
if (!ok) this.relayRecover();
|
|
1347
1489
|
}).then(() => {
|
|
1490
|
+
if (this.rw !== s) return;
|
|
1348
1491
|
this.rwTargetBusy = false;
|
|
1349
1492
|
const p = this.rwPendingTarget;
|
|
1350
1493
|
this.rwPendingTarget = null;
|
|
@@ -1374,7 +1517,7 @@ var PlayerController = class {
|
|
|
1374
1517
|
this.wdGrace = Date.now() + 5e3;
|
|
1375
1518
|
this.cad.lastNew = Date.now();
|
|
1376
1519
|
this.api.control(`api/relay-scrub?session=${encodeURIComponent(s.id)}&on=${on ? 1 : 0}`).then((ok) => {
|
|
1377
|
-
if (!ok) this.relayRecover();
|
|
1520
|
+
if (this.rw === s && !ok) this.relayRecover();
|
|
1378
1521
|
});
|
|
1379
1522
|
}
|
|
1380
1523
|
relayRecover() {
|
|
@@ -1441,9 +1584,11 @@ var PlayerController = class {
|
|
|
1441
1584
|
this.wdLastCt = q;
|
|
1442
1585
|
this.wdLastAt = Date.now();
|
|
1443
1586
|
}
|
|
1587
|
+
if (this.rwPosBusy) return;
|
|
1444
1588
|
const seq = this.cmdSeq;
|
|
1445
|
-
|
|
1446
|
-
|
|
1589
|
+
this.rwPosBusy = true;
|
|
1590
|
+
fetch(this.api.url(`api/relay-pos?session=${encodeURIComponent(s.id)}`), { cache: "no-store", signal: timeoutSignal(3e3) }).then((r) => r.json()).then((d) => {
|
|
1591
|
+
if (this.rw !== s || seq !== this.cmdSeq) return;
|
|
1447
1592
|
if (d && d.t > 0 && Date.now() - this.seekAt < 2500 && Math.abs(d.t - this.seekTarget) > 5e3) return;
|
|
1448
1593
|
if (d && d.t > 0) {
|
|
1449
1594
|
this.wdDead = 0;
|
|
@@ -1458,6 +1603,8 @@ var PlayerController = class {
|
|
|
1458
1603
|
}
|
|
1459
1604
|
}
|
|
1460
1605
|
}).catch(() => {
|
|
1606
|
+
}).finally(() => {
|
|
1607
|
+
this.rwPosBusy = false;
|
|
1461
1608
|
});
|
|
1462
1609
|
}, 600);
|
|
1463
1610
|
}
|
|
@@ -1467,6 +1614,7 @@ var PlayerController = class {
|
|
|
1467
1614
|
clearInterval(this.relayPoll);
|
|
1468
1615
|
this.relayPoll = void 0;
|
|
1469
1616
|
}
|
|
1617
|
+
this.rwPosBusy = false;
|
|
1470
1618
|
}
|
|
1471
1619
|
cadStart() {
|
|
1472
1620
|
this.cadStop();
|
|
@@ -2133,4 +2281,4 @@ export {
|
|
|
2133
2281
|
WebRtcSession,
|
|
2134
2282
|
PlayerController
|
|
2135
2283
|
};
|
|
2136
|
-
//# sourceMappingURL=chunk-
|
|
2284
|
+
//# sourceMappingURL=chunk-MAUN6MNY.js.map
|