@norskvideo/ctl-sdk 0.1.8 → 0.1.10

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.
@@ -0,0 +1,32 @@
1
+ import type { DerivedShot, ResolvedShot, TakeCommand, Transition } from "@norskvideo/ctl-foundation/browser";
2
+ import { type ReactNode } from "react";
3
+ export interface ShotBarProps {
4
+ /** Shots already derived from the manifest + live room by the consumer. */
5
+ shots: DerivedShot[];
6
+ /** The shot currently on air, if known — highlights its card. */
7
+ pgmShotId?: string | null;
8
+ /** The shot currently in preview, if the product runs a preview bus. */
9
+ pvwShotId?: string | null;
10
+ /**
11
+ * Engine-reachable base for resolving relative graphic pages (`/overlays/…`)
12
+ * to the absolute URL `change-url` needs — the origin of the overlay
13
+ * `input.browser`'s configured URL, NOT the operator's `location.origin`
14
+ * (the media container's chromium fetches the page, not the browser). Omit
15
+ * only when the deployment has no overlay graphics; a graphic shot whose page
16
+ * can't be resolved without it is shown but can't be taken.
17
+ */
18
+ graphicBaseUrl?: string;
19
+ /** Default transition applied to takes. */
20
+ transition?: Transition;
21
+ /** Show the editable graphic-URL field on graphic-bearing cards (default true). */
22
+ editableGraphics?: boolean;
23
+ /** Send the assembled commands to air. The consumer owns the WebSocket. */
24
+ onTake: (commands: TakeCommand[], shot: ResolvedShot) => void;
25
+ /** Optional preview bus — omit to hide the Preview control. */
26
+ onPreview?: (commands: TakeCommand[], shot: ResolvedShot) => void;
27
+ /** Drop-in program monitor (e.g. a WHEP player). */
28
+ renderProgramMonitor?: () => ReactNode;
29
+ /** Drop-in preview monitor. */
30
+ renderPreviewMonitor?: () => ReactNode;
31
+ }
32
+ export declare function ShotBar({ shots, pgmShotId, pvwShotId, graphicBaseUrl, transition, editableGraphics, onTake, onPreview, renderProgramMonitor, renderPreviewMonitor, }: ShotBarProps): import("react").JSX.Element;
@@ -0,0 +1,63 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo, useState } from "react";
3
+ import { graphicResolvable, hideReasonLabel, prepareTake } from "./shot-bar-view-model.js";
4
+ import { useUIPrimitives } from "./ui-primitives.js";
5
+ const FAMILY_BADGE = { geometry: "Geometry", graphic: "Graphic" };
6
+ export function ShotBar({ shots, pgmShotId, pvwShotId, graphicBaseUrl, transition, editableGraphics = true, onTake, onPreview, renderProgramMonitor, renderPreviewMonitor, }) {
7
+ const { Button, Input } = useUIPrimitives();
8
+ const firstReady = shots.find((s) => s.status === "ready")?.id ?? null;
9
+ const [selectedId, setSelectedId] = useState(firstReady);
10
+ const [editedUrls, setEditedUrls] = useState({});
11
+ const selected = shots.find((s) => s.id === selectedId && s.status === "ready");
12
+ const commands = useMemo(() => (selected ? prepareTake(selected, { graphicBaseUrl, editedUrl: editedUrls[selected.id], transition }) : []), [selected, graphicBaseUrl, editedUrls, transition]);
13
+ // A graphic shot whose page is relative and has no engine-reachable base
14
+ // can't safely change-url — surface it instead of firing an unfetchable page.
15
+ const takeableGraphic = selected
16
+ ? graphicResolvable(editedUrls[selected.id] ?? selected.graphicUrl, graphicBaseUrl)
17
+ : true;
18
+ return (_jsxs("div", { className: "flex flex-col gap-4 text-zinc-100", children: [_jsxs("div", { className: "grid grid-cols-2 gap-3", children: [_jsx(Monitor, { label: "Preview", tone: "pvw", shot: findLabel(shots, pvwShotId), render: renderPreviewMonitor }), _jsx(Monitor, { label: "On Air", tone: "pgm", shot: findLabel(shots, pgmShotId), render: renderProgramMonitor })] }), _jsx("div", { className: "flex gap-3 overflow-x-auto pb-1", children: shots.map((shot) => (_jsx(ShotCard, { shot: shot, selected: shot.id === selectedId, onAir: shot.id === pgmShotId, config: shot.status === "ready" ? shot.config : undefined, onSelect: () => shot.status === "ready" && setSelectedId(shot.id) }, shot.id))) }), selected ? (_jsxs("div", { className: "flex flex-col gap-3 rounded-lg border border-zinc-800 bg-zinc-900/60 p-3", children: [_jsxs("div", { className: "flex items-center justify-between gap-3", children: [_jsx("div", { className: "text-sm font-medium", children: selected.label }), _jsxs("div", { className: "flex gap-2", children: [onPreview ? (_jsx(Button, { variant: "ghost", size: "sm", disabled: !takeableGraphic, onClick: () => onPreview(commands, selected), children: "Preview" })) : null, _jsx(Button, { variant: "primary", size: "sm", disabled: !takeableGraphic, onClick: () => onTake(commands, selected), children: "Take" })] })] }), !takeableGraphic ? (_jsx("p", { className: "text-xs text-amber-500/90", children: "This shot's graphic page is a relative path but no engine-reachable graphic base is configured, so it can't be loaded into the overlay. Set an absolute page URL, or configure the overlay base." })) : null, editableGraphics && selected.graphicUrl !== undefined ? (_jsxs("div", { className: "flex flex-col gap-1 text-xs text-zinc-400", children: [_jsx("label", { htmlFor: "shotbar-graphic-url", children: "Graphic page" }), _jsx(Input, { id: "shotbar-graphic-url", type: "text", value: editedUrls[selected.id] ?? selected.graphicUrl, placeholder: selected.graphicUrl, onChange: (e) => setEditedUrls((prev) => ({ ...prev, [selected.id]: e.target.value })) })] })) : null, _jsx("pre", { className: "max-h-40 overflow-auto rounded bg-zinc-950 p-2 font-mono text-[11px] leading-relaxed text-zinc-400", children: JSON.stringify(commands, null, 2) })] })) : (_jsx("div", { className: "rounded-lg border border-dashed border-zinc-800 p-4 text-center text-sm text-zinc-500", children: "No shot selected \u2014 pick an available shot above." }))] }));
19
+ }
20
+ function findLabel(shots, id) {
21
+ if (!id)
22
+ return null;
23
+ return shots.find((s) => s.id === id)?.label ?? null;
24
+ }
25
+ function Monitor({ label, tone, shot, render, }) {
26
+ const ring = tone === "pgm" ? "border-red-600/70" : "border-emerald-600/70";
27
+ const chip = tone === "pgm" ? "bg-red-600 text-white" : "bg-emerald-600 text-white";
28
+ return (_jsxs("div", { className: `relative overflow-hidden rounded-lg border-2 ${ring} bg-black`, children: [_jsx("span", { className: `absolute left-2 top-2 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold ${chip}`, children: label }), _jsx("div", { className: "flex aspect-video items-center justify-center", children: render ? render() : _jsx("span", { className: "text-xs text-zinc-500", children: shot ?? "—" }) })] }));
29
+ }
30
+ function ShotCard({ shot, selected, onAir, config, onSelect, }) {
31
+ const hidden = shot.status === "hidden";
32
+ const border = onAir ? "border-red-600" : selected ? "border-sky-500" : "border-zinc-800 hover:border-zinc-600";
33
+ return (_jsxs("button", { type: "button", onClick: onSelect, disabled: hidden, title: hidden ? hideReasonLabel(shot.reason) : shot.label, className: `flex w-40 shrink-0 flex-col gap-2 rounded-lg border ${border} bg-zinc-900 p-2 text-left transition-colors disabled:cursor-not-allowed disabled:opacity-40`, children: [_jsx(ShotThumbnail, { preset: shot.status === "ready" ? shot.preset : "fullscreen", config: config }), _jsxs("div", { className: "flex items-center justify-between gap-1", children: [_jsx("span", { className: "truncate text-xs font-medium text-zinc-100", children: shot.label }), shot.status === "ready" ? (_jsx("span", { className: "shrink-0 rounded bg-zinc-800 px-1 text-[9px] uppercase tracking-wide text-zinc-400", children: FAMILY_BADGE[shot.family] })) : null] }), hidden ? (_jsx("span", { className: "text-[10px] leading-tight text-amber-500/80", children: hideReasonLabel(shot.reason) })) : null] }));
34
+ }
35
+ // A truthful 16:9 schematic of what the preset does — programme fill plus the
36
+ // preset's overlay/box geometry, read from config where it's positional.
37
+ function ShotThumbnail({ preset, config }) {
38
+ const c = (config ?? {});
39
+ const pct = (v, of) => `${Math.max(0, Math.min(100, (v / of) * 100))}%`;
40
+ const prog = _jsx("div", { className: "absolute inset-0 bg-sky-700/50" });
41
+ let overlay = null;
42
+ if (preset === "pip") {
43
+ overlay = (_jsx("div", { className: "absolute rounded-sm bg-amber-400/80", style: { right: "8%", bottom: "10%", width: pct(c.width ?? 384, 1920), height: pct(c.height ?? 270, 1080) } }));
44
+ }
45
+ else if (preset === "lbar") {
46
+ overlay = (_jsx("div", { className: "absolute rounded-sm bg-sky-700/70 ring-1 ring-sky-300/40", style: {
47
+ left: pct(c.videoX ?? 480, 1920),
48
+ top: pct(c.videoY ?? 0, 1080),
49
+ width: pct(c.videoWidth ?? 1440, 1920),
50
+ height: pct(c.videoHeight ?? 810, 1080),
51
+ } }));
52
+ }
53
+ else if (preset === "side-by-side") {
54
+ return (_jsxs("div", { className: "relative aspect-video w-full overflow-hidden rounded bg-zinc-950", children: [_jsx("div", { className: "absolute inset-y-0 left-0 w-1/2 bg-sky-700/50" }), _jsx("div", { className: "absolute inset-y-0 right-0 w-1/2 bg-emerald-700/50" })] }));
55
+ }
56
+ else if (preset === "quarters") {
57
+ return (_jsxs("div", { className: "relative grid aspect-video w-full grid-cols-2 grid-rows-2 gap-px overflow-hidden rounded bg-zinc-700", children: [_jsx("div", { className: "bg-sky-700/50" }), _jsx("div", { className: "bg-emerald-700/50" }), _jsx("div", { className: "bg-violet-700/50" }), _jsx("div", { className: "bg-amber-700/50" })] }));
58
+ }
59
+ else if (preset === "overlay" || preset === "lower-third") {
60
+ overlay = _jsx("div", { className: "absolute inset-x-[6%] bottom-[8%] h-[22%] rounded-sm bg-amber-400/80" });
61
+ }
62
+ return (_jsxs("div", { className: "relative aspect-video w-full overflow-hidden rounded bg-zinc-950", children: [prog, overlay] }));
63
+ }
@@ -1,3 +1,5 @@
1
1
  export { ProductIframe, type ProductIframeHandle, type SubmitResult } from "./ProductIframe.js";
2
2
  export { ProductTemplateBuildForm, type ProductTemplateBuildOutcome, type ProductTemplateBuildRequest, } from "./ProductTemplateBuildForm.js";
3
+ export { ShotBar, type ShotBarProps } from "./ShotBar.js";
4
+ export { graphicResolvable, hideReasonLabel, type PrepareTakeOptions, prepareTake, resolveGraphicUrl, } from "./shot-bar-view-model.js";
3
5
  export { type ButtonProps, type ButtonSize, type ButtonVariant, type InputProps, type LabelProps, type UIPrimitives, UIPrimitivesProvider, useUIPrimitives, } from "./ui-primitives.js";
@@ -1,3 +1,5 @@
1
1
  export { ProductIframe } from "./ProductIframe.js";
2
2
  export { ProductTemplateBuildForm, } from "./ProductTemplateBuildForm.js";
3
+ export { ShotBar } from "./ShotBar.js";
4
+ export { graphicResolvable, hideReasonLabel, prepareTake, resolveGraphicUrl, } from "./shot-bar-view-model.js";
3
5
  export { UIPrimitivesProvider, useUIPrimitives, } from "./ui-primitives.js";
@@ -0,0 +1,44 @@
1
+ import { type HideReason, type ResolvedShot, type TakeCommand, type Transition } from "@norskvideo/ctl-foundation/browser";
2
+ /** Operator-facing text for why a shot can't be taken right now. */
3
+ export declare function hideReasonLabel(reason: HideReason): string;
4
+ /**
5
+ * Resolve a shot's graphic page to an absolute URL for `change-url`, or `null`
6
+ * if it can't be resolved safely.
7
+ *
8
+ * Manifests ship relative paths (`/overlays/lbar.html`) so they're
9
+ * host-independent, but `change-url` is fetched by the media container's
10
+ * chromium (`input.browser`), NOT the operator's browser — so the base MUST be
11
+ * an engine-reachable origin the product supplies (the overlay layer's own
12
+ * configured URL origin). Resolving a relative path against the operator origin
13
+ * (`location.origin`) yields a plausible-but-unreachable URL that 404s in the
14
+ * container; refuse it (`null`) rather than emit that. Absolute inputs pass
15
+ * through untouched, so an operator-typed full URL is honoured as-is.
16
+ */
17
+ export declare function resolveGraphicUrl(url: string, base: string | undefined): string | null;
18
+ /**
19
+ * Whether a shot's graphic page can be taken to air: an absolute page always
20
+ * can, a relative one only with an engine-reachable base, and a shot naming no
21
+ * page is trivially fine. The ShotBar uses this to disable Take (and say why)
22
+ * rather than fire a `change-url` the media container can't fetch.
23
+ */
24
+ export declare function graphicResolvable(graphicUrl: string | undefined, base: string | undefined): boolean;
25
+ export interface PrepareTakeOptions {
26
+ /**
27
+ * Engine-reachable base to resolve a relative graphic path against — the
28
+ * origin of the overlay `input.browser`'s configured URL, NOT the operator's
29
+ * `location.origin`. Omit only for deployments with no overlay graphics.
30
+ */
31
+ graphicBaseUrl?: string;
32
+ /** Operator-edited graphic URL from the card, if they changed it. */
33
+ editedUrl?: string;
34
+ transition?: Transition;
35
+ configOverride?: Record<string, unknown>;
36
+ }
37
+ /**
38
+ * Assemble the exact `TakeCommand[]` for a shot: pick the graphic URL (edited
39
+ * over manifest), resolve it against the engine-reachable base, and hand
40
+ * `buildTake` the right opts. A relative page with no usable base resolves to
41
+ * `null` and its `change-url` is dropped — better to squeeze the layout with a
42
+ * stale overlay than to fire a page the media container can't reach.
43
+ */
44
+ export declare function prepareTake(shot: ResolvedShot, opts: PrepareTakeOptions): TakeCommand[];
@@ -0,0 +1,87 @@
1
+ // Pure view-model for the Shot Bar — the testable logic behind `ShotBar.tsx`,
2
+ // kept React-free so it can be unit-tested without a DOM (the SDK ships no
3
+ // render harness). The component stays a thin presentational shell over these.
4
+ import { buildTake, } from "@norskvideo/ctl-foundation/browser";
5
+ /** Operator-facing text for why a shot can't be taken right now. */
6
+ export function hideReasonLabel(reason) {
7
+ switch (reason) {
8
+ case "no-compose":
9
+ return "No compositor in this channel";
10
+ case "no-programme":
11
+ return "Waiting for programme";
12
+ case "no-overlay-layer":
13
+ return "No graphics overlay layer";
14
+ case "no-commentator-on-camera":
15
+ return "No commentator on camera";
16
+ case "commentator-count-mismatch":
17
+ return "Doesn't fit the commentators on camera";
18
+ case "no-contributor":
19
+ return "No contributor connected";
20
+ case "graphic-shot-missing-url":
21
+ return "No graphic page configured";
22
+ default:
23
+ // Unknown reason from an untyped boundary — show something honest rather
24
+ // than crash the whole bar.
25
+ return "Unavailable";
26
+ }
27
+ }
28
+ /**
29
+ * Resolve a shot's graphic page to an absolute URL for `change-url`, or `null`
30
+ * if it can't be resolved safely.
31
+ *
32
+ * Manifests ship relative paths (`/overlays/lbar.html`) so they're
33
+ * host-independent, but `change-url` is fetched by the media container's
34
+ * chromium (`input.browser`), NOT the operator's browser — so the base MUST be
35
+ * an engine-reachable origin the product supplies (the overlay layer's own
36
+ * configured URL origin). Resolving a relative path against the operator origin
37
+ * (`location.origin`) yields a plausible-but-unreachable URL that 404s in the
38
+ * container; refuse it (`null`) rather than emit that. Absolute inputs pass
39
+ * through untouched, so an operator-typed full URL is honoured as-is.
40
+ */
41
+ export function resolveGraphicUrl(url, base) {
42
+ if (/^https?:\/\//i.test(url))
43
+ return url;
44
+ if (!base)
45
+ return null;
46
+ try {
47
+ const resolved = new URL(url, base);
48
+ // A relative path against a bare/relative base can still land on a
49
+ // non-http(s) or otherwise unreachable origin — only absolute web URLs are
50
+ // safe to hand the engine.
51
+ return /^https?:$/i.test(resolved.protocol) ? resolved.toString() : null;
52
+ }
53
+ catch {
54
+ return null;
55
+ }
56
+ }
57
+ /**
58
+ * Whether a shot's graphic page can be taken to air: an absolute page always
59
+ * can, a relative one only with an engine-reachable base, and a shot naming no
60
+ * page is trivially fine. The ShotBar uses this to disable Take (and say why)
61
+ * rather than fire a `change-url` the media container can't fetch.
62
+ */
63
+ export function graphicResolvable(graphicUrl, base) {
64
+ if (!graphicUrl)
65
+ return true;
66
+ return resolveGraphicUrl(graphicUrl, base) !== null;
67
+ }
68
+ /**
69
+ * Assemble the exact `TakeCommand[]` for a shot: pick the graphic URL (edited
70
+ * over manifest), resolve it against the engine-reachable base, and hand
71
+ * `buildTake` the right opts. A relative page with no usable base resolves to
72
+ * `null` and its `change-url` is dropped — better to squeeze the layout with a
73
+ * stale overlay than to fire a page the media container can't reach.
74
+ */
75
+ export function prepareTake(shot, opts) {
76
+ const rawUrl = opts.editedUrl ?? shot.graphicUrl;
77
+ const graphicUrl = rawUrl ? resolveGraphicUrl(rawUrl, opts.graphicBaseUrl) : null;
78
+ // An unresolvable page must be dropped, not passed through: buildTake falls
79
+ // back to `shot.graphicUrl` (the raw, relative, unreachable manifest path)
80
+ // when no resolved url is supplied, so strip it from the shot as well.
81
+ const effectiveShot = rawUrl && graphicUrl === null ? { ...shot, graphicUrl: undefined } : shot;
82
+ return buildTake(effectiveShot, {
83
+ ...(graphicUrl ? { graphicUrl } : {}),
84
+ ...(opts.transition ? { transition: opts.transition } : {}),
85
+ ...(opts.configOverride ? { configOverride: opts.configOverride } : {}),
86
+ });
87
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@norskvideo/ctl-sdk",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -37,7 +37,7 @@
37
37
  "types": "./index.d.ts",
38
38
  "dependencies": {
39
39
  "@norskvideo/ctl-foundation": "^0.1.0",
40
- "@norskvideo/ctl-product-template-schema": "^0.1.0",
40
+ "@norskvideo/ctl-product-template-schema": "^0.1.5",
41
41
  "express": "5",
42
42
  "lucide-react": "^0.483.0",
43
43
  "react": "^19.0.0",