@moq/watch 0.2.3 → 0.2.5

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/broadcast.d.ts CHANGED
@@ -3,6 +3,7 @@ import type * as Moq from "@moq/lite";
3
3
  import { type Getter, Signal } from "@moq/signals";
4
4
  export interface BroadcastProps {
5
5
  connection?: Moq.Connection.Established | Signal<Moq.Connection.Established | undefined>;
6
+ announced?: Getter<Set<Moq.Path.Valid>>;
6
7
  enabled?: boolean | Signal<boolean>;
7
8
  name?: Moq.Path.Valid | Signal<Moq.Path.Valid>;
8
9
  reload?: boolean | Signal<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"broadcast.d.ts","sourceRoot":"","sources":["../src/broadcast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,KAAK,GAAG,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,WAAW,cAAc;IAC9B,UAAU,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAIzF,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAGpC,IAAI,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAI/C,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;CACnC;AAGD,qBAAa,SAAS;;IACrB,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAE3D,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,IAAI,EAAE,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O,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7B,MAAM,qDAAyD;IAC/D,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAGxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC,CAAgB;IAGlE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAAiB;IAKnE,OAAO,qBAAgB;gBAEX,KAAK,CAAC,EAAE,cAAc;IAoElC,KAAK;CAGL"}
package/element.d.ts CHANGED
@@ -2,12 +2,12 @@ import type { Time } from "@moq/lite";
2
2
  import * as Moq from "@moq/lite";
3
3
  import { MultiBackend } from "./backend";
4
4
  import { Broadcast } from "./broadcast";
5
- import { Sync } from "./sync";
6
- declare const OBSERVED: readonly ["url", "name", "paused", "volume", "muted", "reload", "jitter"];
5
+ import { type Latency, Sync } from "./sync";
6
+ declare const OBSERVED: readonly ["url", "name", "paused", "volume", "muted", "reload", "latency", "jitter"];
7
7
  type Observed = (typeof OBSERVED)[number];
8
8
  export default class MoqWatch extends HTMLElement {
9
9
  #private;
10
- static observedAttributes: readonly ["url", "name", "paused", "volume", "muted", "reload", "jitter"];
10
+ static observedAttributes: readonly ["url", "name", "paused", "volume", "muted", "reload", "latency", "jitter"];
11
11
  connection: Moq.Connection.Reload;
12
12
  broadcast: Broadcast;
13
13
  sync: Sync;
@@ -29,7 +29,11 @@ export default class MoqWatch extends HTMLElement {
29
29
  set muted(value: boolean);
30
30
  get reload(): boolean;
31
31
  set reload(value: boolean);
32
+ get latency(): Latency;
33
+ set latency(value: Latency);
34
+ /** The jitter buffer in milliseconds. */
32
35
  get jitter(): Time.Milli;
36
+ /** @deprecated Use `latency = <number>` instead. */
33
37
  set jitter(value: number);
34
38
  }
35
39
  declare global {
package/element.d.ts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GAAG,IAAI;IAiCzF,IAAI,GAAG,IAAI,GAAG,GAAG,SAAS,CAEzB;IAED,IAAI,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,EAEtC;IAED,IAAI,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAEzB;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,EAEtC;IAED,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,EAExB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,EAEvB;IAED,IAAI,KAAK,IAAI,OAAO,CAEnB;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,OAAO,EAEvB;IAED,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,EAExB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAEzB;IAED,yCAAyC;IACzC,IAAI,MAAM,IAAI,IAAI,CAAC,KAAK,CAEvB;IAED,oDAAoD;IACpD,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,EAEvB;CACD;AAID,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,WAAW,EAAE,QAAQ,CAAC;KACtB;CACD"}
package/element.js CHANGED
@@ -1,52 +1,63 @@
1
- import * as n from "@moq/lite";
2
- import { Signal as o, Effect as r } from "@moq/signals";
3
- import { h as c, B as d, g as u } from "./broadcast-Djx16jPC.js";
4
- const l = ["url", "name", "paused", "volume", "muted", "reload", "jitter"], h = new FinalizationRegistry((a) => a.close());
5
- class b extends HTMLElement {
6
- static observedAttributes = l;
1
+ import * as o from "@moq/lite";
2
+ import { Signal as c, Effect as l } from "@moq/signals";
3
+ import { i as d, B as u, h } from "./broadcast-CZkbruBC.js";
4
+ const b = ["url", "name", "paused", "volume", "muted", "reload", "latency", "jitter"], m = new FinalizationRegistry((r) => r.close());
5
+ class g extends HTMLElement {
6
+ static observedAttributes = b;
7
7
  // The connection to the moq-relay server.
8
8
  connection;
9
9
  // The broadcast being watched.
10
10
  broadcast;
11
11
  // Used to sync audio and video playback at a target latency.
12
- sync = new c();
12
+ sync = new d();
13
13
  // The backend that powers this element.
14
14
  backend;
15
15
  // Set when the element is connected to the DOM.
16
- #t = new o(!1);
16
+ #t = new c(!1);
17
17
  // Expose the Effect class, so users can easily create effects scoped to this element.
18
- signals = new r();
18
+ signals = new l();
19
19
  constructor() {
20
- super(), h.register(this, this.signals), this.connection = new n.Connection.Reload({
20
+ super(), m.register(this, this.signals), this.connection = new o.Connection.Reload({
21
21
  enabled: this.#t
22
- }), this.signals.cleanup(() => this.connection.close()), this.broadcast = new d({
22
+ }), this.signals.cleanup(() => this.connection.close()), this.broadcast = new u({
23
23
  connection: this.connection.established,
24
+ announced: this.connection.announced,
24
25
  enabled: this.#t
25
- }), this.signals.cleanup(() => this.broadcast.close()), this.backend = new u({
26
- broadcast: this.broadcast
26
+ }), this.signals.cleanup(() => this.broadcast.close());
27
+ const t = new c(void 0);
28
+ this.signals.run((e) => {
29
+ const a = e.get(this.connection.established)?.rtt;
30
+ t.set(a ? e.get(a) : void 0);
31
+ }), this.backend = new h({
32
+ broadcast: this.broadcast,
33
+ rtt: t
27
34
  }), this.signals.cleanup(() => this.backend.close());
28
- const t = () => {
29
- const e = this.querySelector("canvas"), s = this.querySelector("video");
30
- if (e && s)
35
+ const n = () => {
36
+ const e = this.querySelector("canvas"), i = this.querySelector("video");
37
+ if (e && i)
31
38
  throw new Error("Cannot have both canvas and video elements");
32
- this.backend.element.set(e ?? s);
33
- }, i = new MutationObserver(t);
34
- i.observe(this, { childList: !0, subtree: !0 }), this.signals.cleanup(() => i.disconnect()), t(), this.signals.run((e) => {
35
- const s = e.get(this.connection.url);
36
- s ? this.setAttribute("url", s.toString()) : this.removeAttribute("url");
39
+ this.backend.element.set(e ?? i);
40
+ }, s = new MutationObserver(n);
41
+ s.observe(this, { childList: !0, subtree: !0 }), this.signals.cleanup(() => s.disconnect()), n(), this.signals.run((e) => {
42
+ const i = e.get(this.connection.url);
43
+ i ? this.setAttribute("url", i.toString()) : this.removeAttribute("url");
37
44
  }), this.signals.run((e) => {
38
- const s = e.get(this.broadcast.name);
39
- this.setAttribute("name", s.toString());
45
+ const i = e.get(this.broadcast.name);
46
+ this.setAttribute("name", i.toString());
40
47
  }), this.signals.run((e) => {
41
48
  e.get(this.backend.audio.muted) ? this.setAttribute("muted", "") : this.removeAttribute("muted");
42
49
  }), this.signals.run((e) => {
43
50
  e.get(this.backend.paused) ? this.setAttribute("paused", "true") : this.removeAttribute("paused");
44
51
  }), this.signals.run((e) => {
45
- const s = e.get(this.backend.audio.volume);
46
- this.setAttribute("volume", s.toString());
52
+ const i = e.get(this.backend.audio.volume);
53
+ this.setAttribute("volume", i.toString());
47
54
  }), this.signals.run((e) => {
48
- const s = Math.floor(e.get(this.backend.jitter));
49
- this.setAttribute("jitter", s.toString());
55
+ if (e.get(this.backend.latency) === "real-time")
56
+ this.setAttribute("latency", "real-time");
57
+ else {
58
+ const a = Math.floor(e.get(this.backend.jitter));
59
+ this.setAttribute("latency", a.toString());
60
+ }
50
61
  });
51
62
  }
52
63
  // Annoyingly, we have to use these callbacks to figure out when the element is connected to the DOM.
@@ -57,26 +68,32 @@ class b extends HTMLElement {
57
68
  disconnectedCallback() {
58
69
  this.#t.set(!1);
59
70
  }
60
- attributeChangedCallback(t, i, e) {
61
- if (i !== e)
71
+ #e(t) {
72
+ const n = t ? Number.parseFloat(t) : Number.NaN;
73
+ this.backend.latency.set(Number.isFinite(n) ? n : 100);
74
+ }
75
+ attributeChangedCallback(t, n, s) {
76
+ if (n !== s)
62
77
  if (t === "url")
63
- this.connection.url.set(e ? new URL(e) : void 0);
78
+ this.connection.url.set(s ? new URL(s) : void 0);
64
79
  else if (t === "name")
65
- this.broadcast.name.set(n.Path.from(e ?? ""));
80
+ this.broadcast.name.set(o.Path.from(s ?? ""));
66
81
  else if (t === "paused")
67
- this.backend.paused.set(e !== null);
82
+ this.backend.paused.set(s !== null);
68
83
  else if (t === "volume") {
69
- const s = e ? Number.parseFloat(e) : 0.5;
70
- this.backend.audio.volume.set(s);
84
+ const e = s ? Number.parseFloat(s) : 0.5;
85
+ this.backend.audio.volume.set(e);
71
86
  } else if (t === "muted")
72
- this.backend.audio.muted.set(e !== null);
87
+ this.backend.audio.muted.set(s !== null);
73
88
  else if (t === "reload")
74
- this.broadcast.reload.set(e !== null);
89
+ this.broadcast.reload.set(s !== null);
90
+ else if (t === "latency")
91
+ !s || s === "real-time" ? this.backend.latency.set("real-time") : this.#e(s);
75
92
  else if (t === "jitter")
76
- this.backend.jitter.set(e ? Number.parseFloat(e) : 100);
93
+ this.#e(s);
77
94
  else {
78
- const s = t;
79
- throw new Error(`Invalid attribute: ${s}`);
95
+ const e = t;
96
+ throw new Error(`Invalid attribute: ${e}`);
80
97
  }
81
98
  }
82
99
  get url() {
@@ -89,7 +106,7 @@ class b extends HTMLElement {
89
106
  return this.broadcast.name.peek();
90
107
  }
91
108
  set name(t) {
92
- this.broadcast.name.set(n.Path.from(t));
109
+ this.broadcast.name.set(o.Path.from(t));
93
110
  }
94
111
  get paused() {
95
112
  return this.backend.paused.peek();
@@ -115,15 +132,23 @@ class b extends HTMLElement {
115
132
  set reload(t) {
116
133
  this.broadcast.reload.set(t);
117
134
  }
135
+ get latency() {
136
+ return this.backend.latency.peek();
137
+ }
138
+ set latency(t) {
139
+ this.backend.latency.set(t);
140
+ }
141
+ /** The jitter buffer in milliseconds. */
118
142
  get jitter() {
119
143
  return this.backend.jitter.peek();
120
144
  }
145
+ /** @deprecated Use `latency = <number>` instead. */
121
146
  set jitter(t) {
122
- this.backend.jitter.set(t);
147
+ this.backend.latency.set(t);
123
148
  }
124
149
  }
125
- customElements.define("moq-watch", b);
150
+ customElements.define("moq-watch", g);
126
151
  export {
127
- b as default
152
+ g as default
128
153
  };
129
154
  //# sourceMappingURL=element.js.map
package/element.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"element.js","sources":["../src/element.ts"],"sourcesContent":["import type { Time } from \"@moq/lite\";\nimport * as Moq from \"@moq/lite\";\nimport { Effect, Signal } from \"@moq/signals\";\nimport { MultiBackend } from \"./backend\";\nimport { Broadcast } from \"./broadcast\";\nimport { Sync } from \"./sync\";\n\nconst OBSERVED = [\"url\", \"name\", \"paused\", \"volume\", \"muted\", \"reload\", \"jitter\"] as const;\ntype Observed = (typeof OBSERVED)[number];\n\n// Close everything when this element is garbage collected.\n// This is primarily to avoid a console.warn that we didn't close() before GC.\n// There's no destructor for web components so this is the best we can do.\nconst cleanup = new FinalizationRegistry<Effect>((signals) => signals.close());\n\n// An optional web component that wraps a <canvas>\nexport default class MoqWatch extends HTMLElement {\n\tstatic observedAttributes = OBSERVED;\n\n\t// The connection to the moq-relay server.\n\tconnection: Moq.Connection.Reload;\n\n\t// The broadcast being watched.\n\tbroadcast: Broadcast;\n\n\t// Used to sync audio and video playback at a target latency.\n\tsync = new Sync();\n\n\t// The backend that powers this element.\n\tbackend: MultiBackend;\n\n\t// Set when the element is connected to the DOM.\n\t#enabled = new Signal(false);\n\n\t// Expose the Effect class, so users can easily create effects scoped to this element.\n\tsignals = new Effect();\n\n\tconstructor() {\n\t\tsuper();\n\n\t\tcleanup.register(this, this.signals);\n\n\t\tthis.connection = new Moq.Connection.Reload({\n\t\t\tenabled: this.#enabled,\n\t\t});\n\t\tthis.signals.cleanup(() => this.connection.close());\n\n\t\tthis.broadcast = new Broadcast({\n\t\t\tconnection: this.connection.established,\n\t\t\tenabled: this.#enabled,\n\t\t});\n\t\tthis.signals.cleanup(() => this.broadcast.close());\n\n\t\tthis.backend = new MultiBackend({\n\t\t\tbroadcast: this.broadcast,\n\t\t});\n\t\tthis.signals.cleanup(() => this.backend.close());\n\n\t\t// Watch to see if the canvas element is added or removed.\n\t\tconst setElement = () => {\n\t\t\tconst canvas = this.querySelector(\"canvas\") as HTMLCanvasElement | undefined;\n\t\t\tconst video = this.querySelector(\"video\") as HTMLVideoElement | undefined;\n\t\t\tif (canvas && video) {\n\t\t\t\tthrow new Error(\"Cannot have both canvas and video elements\");\n\t\t\t}\n\t\t\tthis.backend.element.set(canvas ?? video);\n\t\t};\n\n\t\tconst observer = new MutationObserver(setElement);\n\t\tobserver.observe(this, { childList: true, subtree: true });\n\t\tthis.signals.cleanup(() => observer.disconnect());\n\t\tsetElement();\n\n\t\t// Optionally update attributes to match the library state.\n\t\t// This is kind of dangerous because it can create loops.\n\t\t// NOTE: This only runs when the element is connected to the DOM, which is not obvious.\n\t\t// This is because there's no destructor for web components to clean up our effects.\n\t\tthis.signals.run((effect) => {\n\t\t\tconst url = effect.get(this.connection.url);\n\t\t\tif (url) {\n\t\t\t\tthis.setAttribute(\"url\", url.toString());\n\t\t\t} else {\n\t\t\t\tthis.removeAttribute(\"url\");\n\t\t\t}\n\t\t});\n\n\t\tthis.signals.run((effect) => {\n\t\t\tconst name = effect.get(this.broadcast.name);\n\t\t\tthis.setAttribute(\"name\", name.toString());\n\t\t});\n\n\t\tthis.signals.run((effect) => {\n\t\t\tconst muted = effect.get(this.backend.audio.muted);\n\t\t\tif (muted) {\n\t\t\t\tthis.setAttribute(\"muted\", \"\");\n\t\t\t} else {\n\t\t\t\tthis.removeAttribute(\"muted\");\n\t\t\t}\n\t\t});\n\n\t\tthis.signals.run((effect) => {\n\t\t\tconst paused = effect.get(this.backend.paused);\n\t\t\tif (paused) {\n\t\t\t\tthis.setAttribute(\"paused\", \"true\");\n\t\t\t} else {\n\t\t\t\tthis.removeAttribute(\"paused\");\n\t\t\t}\n\t\t});\n\n\t\tthis.signals.run((effect) => {\n\t\t\tconst volume = effect.get(this.backend.audio.volume);\n\t\t\tthis.setAttribute(\"volume\", volume.toString());\n\t\t});\n\n\t\tthis.signals.run((effect) => {\n\t\t\tconst jitter = Math.floor(effect.get(this.backend.jitter));\n\t\t\tthis.setAttribute(\"jitter\", jitter.toString());\n\t\t});\n\t}\n\n\t// Annoyingly, we have to use these callbacks to figure out when the element is connected to the DOM.\n\t// This wouldn't be so bad if there was a destructor for web components to clean up our effects.\n\tconnectedCallback() {\n\t\tthis.#enabled.set(true);\n\t\tthis.style.display = \"block\";\n\t\tthis.style.position = \"relative\";\n\t}\n\n\tdisconnectedCallback() {\n\t\t// Stop everything but don't actually cleanup just in case we get added back to the DOM.\n\t\tthis.#enabled.set(false);\n\t}\n\n\tattributeChangedCallback(name: Observed, oldValue: string | null, newValue: string | null) {\n\t\tif (oldValue === newValue) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (name === \"url\") {\n\t\t\tthis.connection.url.set(newValue ? new URL(newValue) : undefined);\n\t\t} else if (name === \"name\") {\n\t\t\tthis.broadcast.name.set(Moq.Path.from(newValue ?? \"\"));\n\t\t} else if (name === \"paused\") {\n\t\t\tthis.backend.paused.set(newValue !== null);\n\t\t} else if (name === \"volume\") {\n\t\t\tconst volume = newValue ? Number.parseFloat(newValue) : 0.5;\n\t\t\tthis.backend.audio.volume.set(volume);\n\t\t} else if (name === \"muted\") {\n\t\t\tthis.backend.audio.muted.set(newValue !== null);\n\t\t} else if (name === \"reload\") {\n\t\t\tthis.broadcast.reload.set(newValue !== null);\n\t\t} else if (name === \"jitter\") {\n\t\t\tthis.backend.jitter.set((newValue ? Number.parseFloat(newValue) : 100) as Time.Milli);\n\t\t} else {\n\t\t\tconst exhaustive: never = name;\n\t\t\tthrow new Error(`Invalid attribute: ${exhaustive}`);\n\t\t}\n\t}\n\n\tget url(): URL | undefined {\n\t\treturn this.connection.url.peek();\n\t}\n\n\tset url(value: string | URL | undefined) {\n\t\tthis.connection.url.set(value ? new URL(value) : undefined);\n\t}\n\n\tget name(): Moq.Path.Valid {\n\t\treturn this.broadcast.name.peek();\n\t}\n\n\tset name(value: string | Moq.Path.Valid) {\n\t\tthis.broadcast.name.set(Moq.Path.from(value));\n\t}\n\n\tget paused(): boolean {\n\t\treturn this.backend.paused.peek();\n\t}\n\n\tset paused(value: boolean) {\n\t\tthis.backend.paused.set(value);\n\t}\n\n\tget volume(): number {\n\t\treturn this.backend.audio.volume.peek();\n\t}\n\n\tset volume(value: number) {\n\t\tthis.backend.audio.volume.set(value);\n\t}\n\n\tget muted(): boolean {\n\t\treturn this.backend.audio.muted.peek();\n\t}\n\n\tset muted(value: boolean) {\n\t\tthis.backend.audio.muted.set(value);\n\t}\n\n\tget reload(): boolean {\n\t\treturn this.broadcast.reload.peek();\n\t}\n\n\tset reload(value: boolean) {\n\t\tthis.broadcast.reload.set(value);\n\t}\n\n\tget jitter(): Time.Milli {\n\t\treturn this.backend.jitter.peek();\n\t}\n\n\tset jitter(value: number) {\n\t\tthis.backend.jitter.set(value as Time.Milli);\n\t}\n}\n\ncustomElements.define(\"moq-watch\", MoqWatch);\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t\"moq-watch\": MoqWatch;\n\t}\n}\n"],"names":["OBSERVED","cleanup","signals","MoqWatch","Sync","#enabled","Signal","Effect","Moq","Broadcast","MultiBackend","setElement","canvas","video","observer","effect","url","name","volume","jitter","oldValue","newValue","exhaustive","value"],"mappings":";;;AAOA,MAAMA,IAAW,CAAC,OAAO,QAAQ,UAAU,UAAU,SAAS,UAAU,QAAQ,GAM1EC,IAAU,IAAI,qBAA6B,CAACC,MAAYA,EAAQ,OAAO;AAG7E,MAAqBC,UAAiB,YAAY;AAAA,EACjD,OAAO,qBAAqBH;AAAA;AAAA,EAG5B;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA,OAAO,IAAII,EAAA;AAAA;AAAA,EAGX;AAAA;AAAA,EAGAC,KAAW,IAAIC,EAAO,EAAK;AAAA;AAAA,EAG3B,UAAU,IAAIC,EAAA;AAAA,EAEd,cAAc;AACb,UAAA,GAEAN,EAAQ,SAAS,MAAM,KAAK,OAAO,GAEnC,KAAK,aA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OAAOA,GAAgB;AAC1B,SAAK,UAAU,OAAO,IAAIA,CAAK;AAAA,EAChC;AAAA,EAEA,IAAI,SAAqB;AACxB,WAAO,KAAK,QAAQ,OAAO,KAAA;AAAA,EAC5B;AAAA,EAEA,IAAI,OAAOA,GAAe;AACzB,SAAK,QAAQ,OAAO,IAAIA,CAAmB;AAAA,EAC5C;AACD;AAEA,eAAe,OAAO,aAAapB,CAAQ;"}
1
+ {"version":3,"file":"element.js","sources":["../src/element.ts"],"sourcesContent":["import type { Time } from \"@moq/lite\";\nimport * as Moq from \"@moq/lite\";\nimport { Effect, Signal } from \"@moq/signals\";\nimport { MultiBackend } from \"./backend\";\nimport { Broadcast } from \"./broadcast\";\nimport { type Latency, Sync } from \"./sync\";\n\nconst OBSERVED = [\"url\", \"name\", \"paused\", \"volume\", \"muted\", \"reload\", \"latency\", \"jitter\"] as const;\ntype Observed = (typeof OBSERVED)[number];\n\n// Close everything when this element is garbage collected.\n// This is primarily to avoid a console.warn that we didn't close() before GC.\n// There's no destructor for web components so this is the best we can do.\nconst cleanup = new FinalizationRegistry<Effect>((signals) => signals.close());\n\n// An optional web component that wraps a <canvas>\nexport default class MoqWatch extends HTMLElement {\n\tstatic observedAttributes = OBSERVED;\n\n\t// The connection to the moq-relay server.\n\tconnection: Moq.Connection.Reload;\n\n\t// The broadcast being watched.\n\tbroadcast: Broadcast;\n\n\t// Used to sync audio and video playback at a target latency.\n\tsync = new Sync();\n\n\t// The backend that powers this element.\n\tbackend: MultiBackend;\n\n\t// Set when the element is connected to the DOM.\n\t#enabled = new Signal(false);\n\n\t// Expose the Effect class, so users can easily create effects scoped to this element.\n\tsignals = new Effect();\n\n\tconstructor() {\n\t\tsuper();\n\n\t\tcleanup.register(this, this.signals);\n\n\t\tthis.connection = new Moq.Connection.Reload({\n\t\t\tenabled: this.#enabled,\n\t\t});\n\t\tthis.signals.cleanup(() => this.connection.close());\n\n\t\tthis.broadcast = new Broadcast({\n\t\t\tconnection: this.connection.established,\n\t\t\tannounced: this.connection.announced,\n\t\t\tenabled: this.#enabled,\n\t\t});\n\t\tthis.signals.cleanup(() => this.broadcast.close());\n\n\t\t// Flatten the RTT signal from the connection for the backend.\n\t\tconst rtt = new Signal<number | undefined>(undefined);\n\t\tthis.signals.run((effect) => {\n\t\t\tconst conn = effect.get(this.connection.established);\n\t\t\tconst rttSignal = conn?.rtt;\n\t\t\trtt.set(rttSignal ? effect.get(rttSignal) : undefined);\n\t\t});\n\n\t\tthis.backend = new MultiBackend({\n\t\t\tbroadcast: this.broadcast,\n\t\t\trtt,\n\t\t});\n\t\tthis.signals.cleanup(() => this.backend.close());\n\n\t\t// Watch to see if the canvas element is added or removed.\n\t\tconst setElement = () => {\n\t\t\tconst canvas = this.querySelector(\"canvas\") as HTMLCanvasElement | undefined;\n\t\t\tconst video = this.querySelector(\"video\") as HTMLVideoElement | undefined;\n\t\t\tif (canvas && video) {\n\t\t\t\tthrow new Error(\"Cannot have both canvas and video elements\");\n\t\t\t}\n\t\t\tthis.backend.element.set(canvas ?? video);\n\t\t};\n\n\t\tconst observer = new MutationObserver(setElement);\n\t\tobserver.observe(this, { childList: true, subtree: true });\n\t\tthis.signals.cleanup(() => observer.disconnect());\n\t\tsetElement();\n\n\t\t// Optionally update attributes to match the library state.\n\t\t// This is kind of dangerous because it can create loops.\n\t\t// NOTE: This only runs when the element is connected to the DOM, which is not obvious.\n\t\t// This is because there's no destructor for web components to clean up our effects.\n\t\tthis.signals.run((effect) => {\n\t\t\tconst url = effect.get(this.connection.url);\n\t\t\tif (url) {\n\t\t\t\tthis.setAttribute(\"url\", url.toString());\n\t\t\t} else {\n\t\t\t\tthis.removeAttribute(\"url\");\n\t\t\t}\n\t\t});\n\n\t\tthis.signals.run((effect) => {\n\t\t\tconst name = effect.get(this.broadcast.name);\n\t\t\tthis.setAttribute(\"name\", name.toString());\n\t\t});\n\n\t\tthis.signals.run((effect) => {\n\t\t\tconst muted = effect.get(this.backend.audio.muted);\n\t\t\tif (muted) {\n\t\t\t\tthis.setAttribute(\"muted\", \"\");\n\t\t\t} else {\n\t\t\t\tthis.removeAttribute(\"muted\");\n\t\t\t}\n\t\t});\n\n\t\tthis.signals.run((effect) => {\n\t\t\tconst paused = effect.get(this.backend.paused);\n\t\t\tif (paused) {\n\t\t\t\tthis.setAttribute(\"paused\", \"true\");\n\t\t\t} else {\n\t\t\t\tthis.removeAttribute(\"paused\");\n\t\t\t}\n\t\t});\n\n\t\tthis.signals.run((effect) => {\n\t\t\tconst volume = effect.get(this.backend.audio.volume);\n\t\t\tthis.setAttribute(\"volume\", volume.toString());\n\t\t});\n\n\t\tthis.signals.run((effect) => {\n\t\t\tconst latency = effect.get(this.backend.latency);\n\t\t\tif (latency === \"real-time\") {\n\t\t\t\tthis.setAttribute(\"latency\", \"real-time\");\n\t\t\t} else {\n\t\t\t\tconst jitter = Math.floor(effect.get(this.backend.jitter));\n\t\t\t\tthis.setAttribute(\"latency\", jitter.toString());\n\t\t\t}\n\t\t});\n\t}\n\n\t// Annoyingly, we have to use these callbacks to figure out when the element is connected to the DOM.\n\t// This wouldn't be so bad if there was a destructor for web components to clean up our effects.\n\tconnectedCallback() {\n\t\tthis.#enabled.set(true);\n\t\tthis.style.display = \"block\";\n\t\tthis.style.position = \"relative\";\n\t}\n\n\tdisconnectedCallback() {\n\t\t// Stop everything but don't actually cleanup just in case we get added back to the DOM.\n\t\tthis.#enabled.set(false);\n\t}\n\n\t#setLatencyNumber(value: string | null) {\n\t\tconst parsed = value ? Number.parseFloat(value) : Number.NaN;\n\t\tthis.backend.latency.set((Number.isFinite(parsed) ? parsed : 100) as Time.Milli);\n\t}\n\n\tattributeChangedCallback(name: Observed, oldValue: string | null, newValue: string | null) {\n\t\tif (oldValue === newValue) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (name === \"url\") {\n\t\t\tthis.connection.url.set(newValue ? new URL(newValue) : undefined);\n\t\t} else if (name === \"name\") {\n\t\t\tthis.broadcast.name.set(Moq.Path.from(newValue ?? \"\"));\n\t\t} else if (name === \"paused\") {\n\t\t\tthis.backend.paused.set(newValue !== null);\n\t\t} else if (name === \"volume\") {\n\t\t\tconst volume = newValue ? Number.parseFloat(newValue) : 0.5;\n\t\t\tthis.backend.audio.volume.set(volume);\n\t\t} else if (name === \"muted\") {\n\t\t\tthis.backend.audio.muted.set(newValue !== null);\n\t\t} else if (name === \"reload\") {\n\t\t\tthis.broadcast.reload.set(newValue !== null);\n\t\t} else if (name === \"latency\") {\n\t\t\tif (!newValue || newValue === \"real-time\") {\n\t\t\t\tthis.backend.latency.set(\"real-time\");\n\t\t\t} else {\n\t\t\t\tthis.#setLatencyNumber(newValue);\n\t\t\t}\n\t\t} else if (name === \"jitter\") {\n\t\t\t// Deprecated: use latency=\"<number>\" instead.\n\t\t\tthis.#setLatencyNumber(newValue);\n\t\t} else {\n\t\t\tconst exhaustive: never = name;\n\t\t\tthrow new Error(`Invalid attribute: ${exhaustive}`);\n\t\t}\n\t}\n\n\tget url(): URL | undefined {\n\t\treturn this.connection.url.peek();\n\t}\n\n\tset url(value: string | URL | undefined) {\n\t\tthis.connection.url.set(value ? new URL(value) : undefined);\n\t}\n\n\tget name(): Moq.Path.Valid {\n\t\treturn this.broadcast.name.peek();\n\t}\n\n\tset name(value: string | Moq.Path.Valid) {\n\t\tthis.broadcast.name.set(Moq.Path.from(value));\n\t}\n\n\tget paused(): boolean {\n\t\treturn this.backend.paused.peek();\n\t}\n\n\tset paused(value: boolean) {\n\t\tthis.backend.paused.set(value);\n\t}\n\n\tget volume(): number {\n\t\treturn this.backend.audio.volume.peek();\n\t}\n\n\tset volume(value: number) {\n\t\tthis.backend.audio.volume.set(value);\n\t}\n\n\tget muted(): boolean {\n\t\treturn this.backend.audio.muted.peek();\n\t}\n\n\tset muted(value: boolean) {\n\t\tthis.backend.audio.muted.set(value);\n\t}\n\n\tget reload(): boolean {\n\t\treturn this.broadcast.reload.peek();\n\t}\n\n\tset reload(value: boolean) {\n\t\tthis.broadcast.reload.set(value);\n\t}\n\n\tget latency(): Latency {\n\t\treturn this.backend.latency.peek();\n\t}\n\n\tset latency(value: Latency) {\n\t\tthis.backend.latency.set(value);\n\t}\n\n\t/** The jitter buffer in milliseconds. */\n\tget jitter(): Time.Milli {\n\t\treturn this.backend.jitter.peek();\n\t}\n\n\t/** @deprecated Use `latency = <number>` instead. */\n\tset jitter(value: number) {\n\t\tthis.backend.latency.set(value as Time.Milli);\n\t}\n}\n\ncustomElements.define(\"moq-watch\", MoqWatch);\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t\"moq-watch\": MoqWatch;\n\t}\n}\n"],"names":["OBSERVED","cleanup","signals","MoqWatch","Sync","#enabled","Signal","Effect","Moq","Broadcast","rtt","effect","rttSignal","MultiBackend","setElement","canvas","video","observer","url","name","volume","jitter","#setLatencyNumber","value","parsed","oldValue","newValue","exhaustive"],"mappings":";;;AAOA,MAAMA,IAAW,CAAC,OAAO,QAAQ,UAAU,UAAU,SAAS,UAAU,WAAW,QAAQ,GAMrFC,IAAU,IAAI,qBAA6B,CAACC,MAAYA,EAAQ,OAAO;AAG7E,MAAqBC,UAAiB,YAAY;AAAA,EACjD,OAAO,qBAAqBH;AAAA;AAAA,EAG5B;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA,OAAO,IAAII,EAAA;AAAA;AAAA,EAGX;AAAA;AAAA,EAGAC,KAAW,IAAIC,EAAO,EAAK;AAAA;AAAA,EAG3B,UAAU,IAAIC,EAAA;AAAA,EAEd,cAAc;AACb,UAAA,GAEAN,EAAQ,SAAS,MAAM,KAAK,OAAO,GAEnC,KAAK,aAAa,IAAIO,EAAI,WAAW,OAAO;AAAA,MAC3C,SAAS,KAAKH;AAAA,IAAA,CACd,GACD,KAAK,QAAQ,QAAQ,MAAM,KAAK,WAAW,OAAO,GAElD,KAAK,YAAY,IAAII,EAAU;AAAA,MAC9B,YAAY,KAAK,WAAW;AAAA,MAC5B,WAAW,KAAK,WAAW;AAAA,MAC3B,SAAS,KAAKJ;AAAA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AM,OAAO,KAAA;AAAA,EAClC;AAAA,EAEA,IAAI,OAAOA,GAAe;AACzB,SAAK,QAAQ,MAAM,OAAO,IAAIA,CAAK;AAAA,EACpC;AAAA,EAEA,IAAI,QAAiB;AACpB,WAAO,KAAK,QAAQ,MAAM,MAAM,KAAA;AAAA,EACjC;AAAA,EAEA,IAAI,MAAMA,GAAgB;AACzB,SAAK,QAAQ,MAAM,MAAM,IAAIA,CAAK;AAAA,EACnC;AAAA,EAEA,IAAI,SAAkB;AACrB,WAAO,KAAK,UAAU,OAAO,KAAA;AAAA,EAC9B;AAAA,EAEA,IAAI,OAAOA,GAAgB;AAC1B,SAAK,UAAU,OAAO,IAAIA,CAAK;AAAA,EAChC;AAAA,EAEA,IAAI,UAAmB;AACtB,WAAO,KAAK,QAAQ,QAAQ,KAAA;AAAA,EAC7B;AAAA,EAEA,IAAI,QAAQA,GAAgB;AAC3B,SAAK,QAAQ,QAAQ,IAAIA,CAAK;AAAA,EAC/B;AAAA;AAAA,EAGA,IAAI,SAAqB;AACxB,WAAO,KAAK,QAAQ,OAAO,KAAA;AAAA,EAC5B;AAAA;AAAA,EAGA,IAAI,OAAOA,GAAe;AACzB,SAAK,QAAQ,QAAQ,IAAIA,CAAmB;AAAA,EAC7C;AACD;AAEA,eAAe,OAAO,aAAapB,CAAQ;"}
package/index.js CHANGED
@@ -1,22 +1,37 @@
1
- import * as $ from "@moq/lite";
2
- import { Signal as i, Effect as c } from "@moq/signals";
3
- import * as B from "@moq/signals";
4
- import { D as p, M as w, R as v, S as m, a as y, E as S, b as _, c as f, P as h, d as M, e as k, f as P } from "./broadcast-Djx16jPC.js";
5
- import { B as N, m as V, g as W, h as Y, t as G } from "./broadcast-Djx16jPC.js";
6
- const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
7
- __proto__: null,
8
- Decoder: p,
9
- Mse: w,
10
- Renderer: v,
11
- Source: m
12
- }, Symbol.toStringTag, { value: "Module" })), C = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1
+ import * as E from "@moq/lite";
2
+ import { Signal as i, Effect as h } from "@moq/signals";
3
+ import * as I from "@moq/signals";
4
+ import { o as m, a as c, b as d, s as w, D as y, M as S, R as _, S as f, c as M, E as k, d as P, e as O, P as g, f as j, g as x } from "./broadcast-CZkbruBC.js";
5
+ import { B as G, m as H, h as K, i as Q, t as U } from "./broadcast-CZkbruBC.js";
6
+ const T = m({
7
+ name: c(w()),
8
+ // name
9
+ avatar: c(w()),
10
+ // avatar
11
+ audio: c(d()),
12
+ // audio enabled
13
+ video: c(d()),
14
+ // video enabled
15
+ typing: c(d()),
16
+ // actively typing
17
+ chat: c(d()),
18
+ // chatted recently
19
+ screen: c(d())
20
+ // screen sharing
21
+ }), L = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
13
22
  __proto__: null,
14
23
  Decoder: y,
15
- Emitter: S,
16
- Mse: _,
24
+ Mse: S,
25
+ Renderer: _,
17
26
  Source: f
27
+ }, Symbol.toStringTag, { value: "Module" })), q = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
28
+ __proto__: null,
29
+ Decoder: M,
30
+ Emitter: k,
31
+ Mse: P,
32
+ Source: O
18
33
  }, Symbol.toStringTag, { value: "Module" }));
19
- class O {
34
+ class A {
20
35
  broadcast;
21
36
  enabled;
22
37
  // Empty string is a valid message.
@@ -24,7 +39,7 @@ class O {
24
39
  latest = this.#t;
25
40
  #s = new i(void 0);
26
41
  catalog = this.#s;
27
- #e = new c();
42
+ #e = new h();
28
43
  constructor(s, e, a) {
29
44
  this.broadcast = s, this.enabled = i.from(a?.enabled ?? !1), this.#e.run((t) => {
30
45
  t.get(this.enabled) && this.#s.set(t.get(e)?.chat?.message);
@@ -33,7 +48,7 @@ class O {
33
48
  #a(s) {
34
49
  const e = s.getAll([this.enabled, this.#s, this.broadcast]);
35
50
  if (!e) return;
36
- const [a, t, o] = e, n = o.subscribe(t.name, h.chat);
51
+ const [a, t, o] = e, n = o.subscribe(t.name, g.chat);
37
52
  s.cleanup(() => n.close()), s.set(this.#t, ""), s.cleanup(() => this.#t.set(void 0)), s.spawn(async () => {
38
53
  for (; ; ) {
39
54
  const r = await n.readString();
@@ -46,13 +61,13 @@ class O {
46
61
  this.#e.close();
47
62
  }
48
63
  }
49
- class x {
64
+ class R {
50
65
  broadcast;
51
66
  enabled;
52
67
  active;
53
68
  #t = new i(void 0);
54
69
  catalog = this.#t;
55
- #s = new c();
70
+ #s = new h();
56
71
  constructor(s, e, a) {
57
72
  this.broadcast = s, this.active = new i(void 0), this.enabled = i.from(a?.enabled ?? !1), this.#s.run((t) => {
58
73
  t.get(this.enabled) && this.#t.set(t.get(e)?.chat?.typing);
@@ -61,7 +76,7 @@ class x {
61
76
  #e(s) {
62
77
  const e = s.getAll([this.enabled, this.#t, this.broadcast]);
63
78
  if (!e) return;
64
- const [a, t, o] = e, n = o.subscribe(t.name, h.typing);
79
+ const [a, t, o] = e, n = o.subscribe(t.name, g.typing);
65
80
  s.cleanup(() => n.close()), s.spawn(async () => {
66
81
  for (; ; ) {
67
82
  const r = await n.readBool();
@@ -74,13 +89,13 @@ class x {
74
89
  this.#s.close();
75
90
  }
76
91
  }
77
- class T {
92
+ class $ {
78
93
  message;
79
94
  typing;
80
95
  #t = new i(void 0);
81
- #s = new c();
96
+ #s = new h();
82
97
  constructor(s, e, a) {
83
- this.message = new O(s, e, a?.message), this.typing = new x(s, e, a?.typing), this.#s.run((t) => {
98
+ this.message = new A(s, e, a?.message), this.typing = new R(s, e, a?.typing), this.#s.run((t) => {
84
99
  const o = t.get(this.message.catalog), n = t.get(this.typing.catalog);
85
100
  !o && !n || t.set(this.#t, {
86
101
  message: o,
@@ -92,21 +107,21 @@ class T {
92
107
  this.#s.close(), this.message.close(), this.typing.close();
93
108
  }
94
109
  }
95
- const I = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
110
+ const F = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
96
111
  __proto__: null,
97
- Chat: T
112
+ Chat: $
98
113
  }, Symbol.toStringTag, { value: "Module" }));
99
- async function g(l, s) {
114
+ async function b(l, s) {
100
115
  const e = await l.readJson();
101
116
  if (e !== void 0)
102
117
  return s.parse(e);
103
118
  }
104
- class j {
119
+ class z {
105
120
  enabled;
106
121
  broadcast;
107
122
  #t = new i(void 0);
108
123
  #s = new i(void 0);
109
- signals = new c();
124
+ signals = new h();
110
125
  constructor(s, e, a) {
111
126
  this.broadcast = s, this.enabled = i.from(a?.enabled ?? !1), this.signals.run((t) => {
112
127
  this.#t.set(t.get(e)?.location?.peers);
@@ -115,13 +130,13 @@ class j {
115
130
  #e(s) {
116
131
  const e = s.getAll([this.enabled, this.#t, this.broadcast]);
117
132
  if (!e) return;
118
- const [a, t, o] = e, n = o.subscribe(t.name, h.location);
133
+ const [a, t, o] = e, n = o.subscribe(t.name, g.location);
119
134
  s.cleanup(() => n.close()), s.spawn(this.#a.bind(this, n));
120
135
  }
121
136
  async #a(s) {
122
137
  try {
123
138
  for (; ; ) {
124
- const e = await g(s, M);
139
+ const e = await b(s, j);
125
140
  if (!e) break;
126
141
  this.#s.set(e);
127
142
  }
@@ -136,7 +151,7 @@ class j {
136
151
  this.signals.close();
137
152
  }
138
153
  }
139
- class A {
154
+ class B {
140
155
  broadcast;
141
156
  enabled;
142
157
  #t = new i(void 0);
@@ -144,7 +159,7 @@ class A {
144
159
  #s = new i(void 0);
145
160
  #e = new i(void 0);
146
161
  position = this.#e;
147
- signals = new c();
162
+ signals = new h();
148
163
  constructor(s, e, a) {
149
164
  this.broadcast = s, this.enabled = i.from(a?.enabled ?? !1), this.signals.run((t) => {
150
165
  this.#s.set(t.get(e)?.location);
@@ -157,14 +172,14 @@ class A {
157
172
  if (!o) return;
158
173
  const n = t.get(this.#s)?.track;
159
174
  if (!n) return;
160
- const r = o.subscribe(n.name, h.location);
175
+ const r = o.subscribe(n.name, g.location);
161
176
  t.cleanup(() => r.close()), t.spawn(this.#a.bind(this, r));
162
177
  });
163
178
  }
164
179
  async #a(s) {
165
180
  try {
166
181
  for (; ; ) {
167
- const e = await g(s, k);
182
+ const e = await b(s, x);
168
183
  if (!e) break;
169
184
  this.#e.set(e);
170
185
  }
@@ -176,41 +191,41 @@ class A {
176
191
  this.signals.close();
177
192
  }
178
193
  }
179
- class R {
194
+ class D {
180
195
  window;
181
196
  peers;
182
- signals = new c();
197
+ signals = new h();
183
198
  constructor(s, e, a) {
184
- this.window = new A(s, e, a?.window), this.peers = new j(s, e, a?.peers);
199
+ this.window = new B(s, e, a?.window), this.peers = new z(s, e, a?.peers);
185
200
  }
186
201
  close() {
187
202
  this.signals.close(), this.window.close(), this.peers.close();
188
203
  }
189
204
  }
190
- const J = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
205
+ const N = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
191
206
  __proto__: null,
192
- Root: R
207
+ Root: D
193
208
  }, Symbol.toStringTag, { value: "Module" }));
194
- class L {
209
+ class V {
195
210
  broadcast;
196
211
  enabled;
197
212
  preview = new i(void 0);
198
213
  #t = new i(void 0);
199
- #s = new c();
214
+ #s = new h();
200
215
  constructor(s, e, a) {
201
216
  this.broadcast = s, this.enabled = i.from(a?.enabled ?? !1), this.#s.run((t) => {
202
217
  this.#t.set(t.get(e)?.preview);
203
218
  }), this.#s.run((t) => {
204
219
  const o = t.getAll([this.enabled, this.broadcast, this.#t]);
205
220
  if (!o) return;
206
- const [n, r, b] = o, u = r.subscribe(b.name, h.preview);
207
- t.cleanup(() => u.close()), t.spawn(async () => {
221
+ const [n, r, v] = o, p = r.subscribe(v.name, g.preview);
222
+ t.cleanup(() => p.close()), t.spawn(async () => {
208
223
  try {
209
- const d = await g(u, P);
210
- if (!d) return;
211
- this.preview.set(d);
212
- } catch (d) {
213
- console.warn("Failed to parse preview JSON:", d);
224
+ const u = await b(p, T);
225
+ if (!u) return;
226
+ this.preview.set(u);
227
+ } catch (u) {
228
+ console.warn("Failed to parse preview JSON:", u);
214
229
  }
215
230
  }), t.cleanup(() => this.preview.set(void 0));
216
231
  });
@@ -220,17 +235,17 @@ class L {
220
235
  }
221
236
  }
222
237
  export {
223
- C as Audio,
224
- N as Broadcast,
225
- I as Chat,
226
- $ as Lite,
227
- J as Location,
228
- V as Mse,
229
- W as MultiBackend,
230
- L as Preview,
231
- B as Signals,
232
- Y as Sync,
233
- E as Video,
234
- G as timeRangesToArray
238
+ q as Audio,
239
+ G as Broadcast,
240
+ F as Chat,
241
+ E as Lite,
242
+ N as Location,
243
+ H as Mse,
244
+ K as MultiBackend,
245
+ V as Preview,
246
+ I as Signals,
247
+ Q as Sync,
248
+ L as Video,
249
+ U as timeRangesToArray
235
250
  };
236
251
  //# sourceMappingURL=index.js.map