@norskvideo/moq-watch 0.2.0 → 0.2.2

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.
@@ -1,25 +1,34 @@
1
1
  import { Time } from "@norskvideo/moq-net";
2
2
  import { type Getter, type Inputs, type Readonlys, Signal } from "@norskvideo/moq-signals";
3
3
  import type { Decoder } from "./decoder";
4
+ import { type VisibilitySource } from "./tab-visible";
4
5
  /**
5
6
  * Controls when video is downloaded relative to the canvas position.
6
7
  *
7
8
  * - `"never"`: never download video.
8
9
  * - `"always"`: always download video, regardless of the canvas position or tab visibility.
10
+ * - `"tab"`: download wherever the canvas is, while the tab is visible (an off-screen tile keeps
11
+ * playing; a background tab stops).
9
12
  * - a CSS length (`"0px"`, `"200px"`, `"100%"`, ...): download while the canvas is within
10
13
  * that distance of the viewport (used as the {@link IntersectionObserver} `rootMargin`) and
11
14
  * the tab is visible. `"0px"` means strictly on screen; larger values pre-warm the video
12
15
  * before it scrolls in.
16
+ *
17
+ * Whatever the policy, other than `"always"`, a hidden tab only stops video once it has been
18
+ * hidden for `hiddenGrace`, so a quick flip to another tab and back does not interrupt it.
13
19
  */
14
- export type Visible = "never" | "always" | (string & {});
20
+ export type Visible = "never" | "always" | "tab" | (string & {});
15
21
  export type RendererInput = {
16
22
  canvas: Getter<HTMLCanvasElement | undefined>;
17
23
  visible: Getter<Visible>;
24
+ hiddenGrace: Getter<number>;
18
25
  };
19
26
  /** Constructor properties for {@link Renderer}. */
20
27
  export type RendererProps = Inputs<RendererInput> & {
21
28
  /** Decoder supplying video frames. */
22
29
  decoder: Decoder;
30
+ /** The document whose visibility counts. Defaults to the global `document`. */
31
+ document?: VisibilitySource;
23
32
  };
24
33
  type RendererOutput = {
25
34
  frame: Signal<VideoFrame | undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/video/renderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,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cAAc,CAAC;AAC3G,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAKlE;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAEjE,MAAM,MAAM,aAAa,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAAC;IAG9C,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAGzB,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;CAC5B,CAAC;AAEF,mDAAmD;AACnD,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG;IACnD,sCAAsC;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC5B,CAAC;AAEF,KAAK,cAAc,GAAG;IAErB,KAAK,EAAE,MAAM,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAGtC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IAI1C,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;CACzB,CAAC;AAGF,qBAAa,QAAQ;;IACpB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,QAAQ,CAAC,EAAE,EAAE,SAAS,CAAC,aAAa,CAAC,CAAC;IAOtC,QAAQ,CAAC,GAAG,4BAAwB;IAMpC,YAAY,KAAK,EAAE,aAAa,EAiB/B;IA0ID,KAAK,SAQJ;CACD"}
@@ -0,0 +1,28 @@
1
+ import { type Getter, Signal } from "@norskvideo/moq-signals";
2
+ /** What TabVisible watches: `document`, or a stand-in with the same event and flag. */
3
+ export type VisibilitySource = EventTarget & {
4
+ readonly hidden: boolean;
5
+ };
6
+ /** Constructor properties for {@link TabVisible}. */
7
+ export type TabVisibleProps = {
8
+ /** The document to watch. Defaults to the global `document`. */
9
+ doc?: VisibilitySource;
10
+ /** How long, in milliseconds, the tab must stay hidden before it counts as invisible. Defaults to 5000. */
11
+ grace?: Getter<number> | number;
12
+ };
13
+ /**
14
+ * Whether the tab counts as visible: true while it is shown, and false only once it has been
15
+ * hidden for the grace period.
16
+ *
17
+ * A background tab is throttled, so video that keeps downloading cannot be rendered in time,
18
+ * and on return the player fast-forwards through the backlog. Turning video off once the tab
19
+ * has been away for a while means it comes back at the live edge, while the grace keeps a
20
+ * quick flip to another tab and back from interrupting it.
21
+ */
22
+ export declare class TabVisible {
23
+ #private;
24
+ readonly visible: Signal<boolean>;
25
+ constructor(props?: TabVisibleProps);
26
+ close(): void;
27
+ }
28
+ //# sourceMappingURL=tab-visible.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tab-visible.d.ts","sourceRoot":"","sources":["../../src/video/tab-visible.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,MAAM,EAAU,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnE,uFAAuF;AACvF,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;AAE1E,qDAAqD;AACrD,MAAM,MAAM,eAAe,GAAG;IAC7B,gEAAgE;IAChE,GAAG,CAAC,EAAE,gBAAgB,CAAC;IACvB,2GAA2G;IAC3G,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CAChC,CAAC;AAEF;;;;;;;;GAQG;AACH,qBAAa,UAAU;;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAMlC,YAAY,KAAK,GAAE,eAAoB,EAmBtC;IAED,KAAK,IAAI,IAAI,CAEZ;CACD"}