@moq/watch 0.1.0 → 0.2.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/{broadcast-CSXy8QiX.js → broadcast-DhcOJtcZ.js} +39 -32
- package/{broadcast-CSXy8QiX.js.map → broadcast-DhcOJtcZ.js.map} +1 -1
- package/broadcast.d.ts +2 -2
- package/element.d.ts +13 -13
- package/element.d.ts.map +1 -1
- package/element.js +70 -64
- package/element.js.map +1 -1
- package/index.js +97 -97
- package/index.js.map +1 -1
- package/package.json +5 -5
- package/support/element.js +6 -6
- package/support/element.js.map +1 -1
- package/ui/components/BufferControl.d.ts.map +1 -1
- package/ui/components/WatchStatusIndicator.d.ts.map +1 -1
- package/ui/context.d.ts +1 -1
- package/ui/context.d.ts.map +1 -1
- package/ui/index.js +693 -728
- package/ui/index.js.map +1 -1
- package/ui/components/LatencySlider.d.ts +0 -2
- package/ui/components/LatencySlider.d.ts.map +0 -1
package/broadcast.d.ts
CHANGED
|
@@ -4,14 +4,14 @@ import { type Getter, Signal } from "@moq/signals";
|
|
|
4
4
|
export interface BroadcastProps {
|
|
5
5
|
connection?: Moq.Connection.Established | Signal<Moq.Connection.Established | undefined>;
|
|
6
6
|
enabled?: boolean | Signal<boolean>;
|
|
7
|
-
|
|
7
|
+
name?: Moq.Path.Valid | Signal<Moq.Path.Valid | undefined>;
|
|
8
8
|
reload?: boolean | Signal<boolean>;
|
|
9
9
|
}
|
|
10
10
|
export declare class Broadcast {
|
|
11
11
|
#private;
|
|
12
12
|
connection: Signal<Moq.Connection.Established | undefined>;
|
|
13
13
|
enabled: Signal<boolean>;
|
|
14
|
-
|
|
14
|
+
name: Signal<Moq.Path.Valid | undefined>;
|
|
15
15
|
status: Moq.Signals.Signal<"offline" | "loading" | "live">;
|
|
16
16
|
reload: Signal<boolean>;
|
|
17
17
|
readonly active: Getter<Moq.Broadcast | undefined>;
|
package/element.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import type { Time } from "@moq/lite";
|
|
2
2
|
import * as Moq from "@moq/lite";
|
|
3
|
-
import {
|
|
4
|
-
import type * as Audio from "./audio";
|
|
5
|
-
import { type Backend } from "./backend";
|
|
3
|
+
import { MultiBackend } from "./backend";
|
|
6
4
|
import { Broadcast } from "./broadcast";
|
|
7
5
|
import { Sync } from "./sync";
|
|
8
|
-
|
|
9
|
-
declare const OBSERVED: readonly ["url", "name", "path", "paused", "volume", "muted", "reload", "jitter", "latency"];
|
|
6
|
+
declare const OBSERVED: readonly ["url", "name", "paused", "volume", "muted", "reload", "jitter"];
|
|
10
7
|
type Observed = (typeof OBSERVED)[number];
|
|
11
|
-
export default class MoqWatch extends HTMLElement
|
|
8
|
+
export default class MoqWatch extends HTMLElement {
|
|
12
9
|
#private;
|
|
13
|
-
static observedAttributes: readonly ["url", "name", "
|
|
10
|
+
static observedAttributes: readonly ["url", "name", "paused", "volume", "muted", "reload", "jitter"];
|
|
14
11
|
connection: Moq.Connection.Reload;
|
|
15
12
|
broadcast: Broadcast;
|
|
16
13
|
sync: Sync;
|
|
14
|
+
backend: MultiBackend;
|
|
17
15
|
signals: Moq.Signals.Effect;
|
|
18
16
|
constructor();
|
|
19
17
|
connectedCallback(): void;
|
|
20
18
|
disconnectedCallback(): void;
|
|
21
19
|
attributeChangedCallback(name: Observed, oldValue: string | null, newValue: string | null): void;
|
|
22
|
-
get url():
|
|
23
|
-
|
|
24
|
-
get
|
|
25
|
-
|
|
26
|
-
get
|
|
27
|
-
|
|
20
|
+
get url(): URL | undefined;
|
|
21
|
+
set url(value: string | URL | undefined);
|
|
22
|
+
get name(): Moq.Path.Valid | undefined;
|
|
23
|
+
set name(value: string | Moq.Path.Valid | undefined);
|
|
24
|
+
get paused(): boolean;
|
|
25
|
+
set paused(value: boolean);
|
|
26
|
+
get jitter(): Time.Milli;
|
|
27
|
+
set jitter(value: number);
|
|
28
28
|
}
|
|
29
29
|
declare global {
|
|
30
30
|
interface HTMLElementTagNameMap {
|
package/element.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,QAAA,MAAM,QAAQ,2EAA4E,CAAC;AAC3F,KAAK,QAAQ,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAQ1C,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,WAAW;;IAChD,MAAM,CAAC,kBAAkB,4EAAY;IAGrC,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC;IAGlC,SAAS,EAAE,SAAS,CAAC;IAGrB,IAAI,OAAc;IAGlB,OAAO,EAAE,YAAY,CAAC;IAMtB,OAAO,qBAAgB;;IA2FvB,iBAAiB;IAMjB,oBAAoB;IAKpB,wBAAwB,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IA0BzF,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,GAAG,SAAS,CAErC;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,SAAS,EAElD;IAED,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,EAExB;IAED,IAAI,MAAM,IAAI,IAAI,CAAC,KAAK,CAEvB;IAED,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,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { Signal as a, Effect as
|
|
3
|
-
import { h as
|
|
4
|
-
const u = ["url", "name", "
|
|
1
|
+
import * as n from "@moq/lite";
|
|
2
|
+
import { Signal as a, Effect as r } from "@moq/signals";
|
|
3
|
+
import { h as c, B as l, g as d } from "./broadcast-DhcOJtcZ.js";
|
|
4
|
+
const u = ["url", "name", "paused", "volume", "muted", "reload", "jitter"], h = new FinalizationRegistry((o) => o.close());
|
|
5
5
|
class b extends HTMLElement {
|
|
6
6
|
static observedAttributes = u;
|
|
7
7
|
// The connection to the moq-relay server.
|
|
@@ -9,93 +9,99 @@ class b extends HTMLElement {
|
|
|
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
|
|
12
|
+
sync = new c();
|
|
13
13
|
// The backend that powers this element.
|
|
14
|
-
|
|
14
|
+
backend;
|
|
15
15
|
// Set when the element is connected to the DOM.
|
|
16
|
-
#
|
|
16
|
+
#t = new a(!1);
|
|
17
17
|
// Expose the Effect class, so users can easily create effects scoped to this element.
|
|
18
|
-
signals = new
|
|
18
|
+
signals = new r();
|
|
19
19
|
constructor() {
|
|
20
|
-
super(),
|
|
21
|
-
enabled: this.#
|
|
22
|
-
}), this.signals.cleanup(() => this.connection.close()), this.broadcast = new
|
|
20
|
+
super(), h.register(this, this.signals), this.connection = new n.Connection.Reload({
|
|
21
|
+
enabled: this.#t
|
|
22
|
+
}), this.signals.cleanup(() => this.connection.close()), this.broadcast = new l({
|
|
23
23
|
connection: this.connection.established,
|
|
24
|
-
enabled: this.#
|
|
25
|
-
}), this.signals.cleanup(() => this.broadcast.close()), this
|
|
24
|
+
enabled: this.#t
|
|
25
|
+
}), this.signals.cleanup(() => this.broadcast.close()), this.backend = new d({
|
|
26
26
|
broadcast: this.broadcast
|
|
27
|
-
}), this.signals.cleanup(() => this
|
|
28
|
-
const
|
|
29
|
-
const t = this.querySelector("canvas"),
|
|
30
|
-
if (t &&
|
|
27
|
+
}), this.signals.cleanup(() => this.backend.close());
|
|
28
|
+
const e = () => {
|
|
29
|
+
const t = this.querySelector("canvas"), s = this.querySelector("video");
|
|
30
|
+
if (t && s)
|
|
31
31
|
throw new Error("Cannot have both canvas and video elements");
|
|
32
|
-
this
|
|
33
|
-
}, i = new MutationObserver(
|
|
34
|
-
i.observe(this, { childList: !0, subtree: !0 }), this.signals.cleanup(() => i.disconnect()),
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
}), this.signals.
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
}), this.signals.
|
|
41
|
-
t.get(this.audio.muted) ? this.setAttribute("muted", "") : this.removeAttribute("muted");
|
|
42
|
-
}), this.signals.
|
|
43
|
-
t.get(this.paused) ? this.setAttribute("paused", "true") : this.removeAttribute("paused");
|
|
44
|
-
}), this.signals.
|
|
45
|
-
const
|
|
46
|
-
this.setAttribute("volume",
|
|
47
|
-
}), this.signals.
|
|
48
|
-
const
|
|
49
|
-
this.setAttribute("jitter",
|
|
32
|
+
this.backend.element.set(t ?? s);
|
|
33
|
+
}, i = new MutationObserver(e);
|
|
34
|
+
i.observe(this, { childList: !0, subtree: !0 }), this.signals.cleanup(() => i.disconnect()), e(), this.signals.run((t) => {
|
|
35
|
+
const s = t.get(this.connection.url);
|
|
36
|
+
s ? this.setAttribute("url", s.toString()) : this.removeAttribute("url");
|
|
37
|
+
}), this.signals.run((t) => {
|
|
38
|
+
const s = t.get(this.broadcast.name);
|
|
39
|
+
s ? this.setAttribute("name", s.toString()) : this.removeAttribute("name");
|
|
40
|
+
}), this.signals.run((t) => {
|
|
41
|
+
t.get(this.backend.audio.muted) ? this.setAttribute("muted", "") : this.removeAttribute("muted");
|
|
42
|
+
}), this.signals.run((t) => {
|
|
43
|
+
t.get(this.backend.paused) ? this.setAttribute("paused", "true") : this.removeAttribute("paused");
|
|
44
|
+
}), this.signals.run((t) => {
|
|
45
|
+
const s = t.get(this.backend.audio.volume);
|
|
46
|
+
this.setAttribute("volume", s.toString());
|
|
47
|
+
}), this.signals.run((t) => {
|
|
48
|
+
const s = Math.floor(t.get(this.backend.jitter));
|
|
49
|
+
this.setAttribute("jitter", s.toString());
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
// Annoyingly, we have to use these callbacks to figure out when the element is connected to the DOM.
|
|
53
53
|
// This wouldn't be so bad if there was a destructor for web components to clean up our effects.
|
|
54
54
|
connectedCallback() {
|
|
55
|
-
this.#
|
|
55
|
+
this.#t.set(!0), this.style.display = "block", this.style.position = "relative";
|
|
56
56
|
}
|
|
57
57
|
disconnectedCallback() {
|
|
58
|
-
this.#
|
|
58
|
+
this.#t.set(!1);
|
|
59
59
|
}
|
|
60
|
-
attributeChangedCallback(
|
|
60
|
+
attributeChangedCallback(e, i, t) {
|
|
61
61
|
if (i !== t)
|
|
62
|
-
if (
|
|
63
|
-
this.url.set(t ? new URL(t) : void 0);
|
|
64
|
-
else if (
|
|
65
|
-
this.
|
|
66
|
-
else if (
|
|
67
|
-
this.paused.set(t !== null);
|
|
68
|
-
else if (
|
|
69
|
-
const
|
|
70
|
-
this.audio.volume.set(
|
|
71
|
-
} else if (
|
|
72
|
-
this.audio.muted.set(t !== null);
|
|
73
|
-
else if (
|
|
62
|
+
if (e === "url")
|
|
63
|
+
this.connection.url.set(t ? new URL(t) : void 0);
|
|
64
|
+
else if (e === "name")
|
|
65
|
+
this.broadcast.name.set(t ? n.Path.from(t) : void 0);
|
|
66
|
+
else if (e === "paused")
|
|
67
|
+
this.backend.paused.set(t !== null);
|
|
68
|
+
else if (e === "volume") {
|
|
69
|
+
const s = t ? Number.parseFloat(t) : 0.5;
|
|
70
|
+
this.backend.audio.volume.set(s);
|
|
71
|
+
} else if (e === "muted")
|
|
72
|
+
this.backend.audio.muted.set(t !== null);
|
|
73
|
+
else if (e === "reload")
|
|
74
74
|
this.broadcast.reload.set(t !== null);
|
|
75
|
-
else if (
|
|
76
|
-
this.jitter.set(t ? Number.parseFloat(t) : 100);
|
|
75
|
+
else if (e === "jitter")
|
|
76
|
+
this.backend.jitter.set(t ? Number.parseFloat(t) : 100);
|
|
77
77
|
else {
|
|
78
|
-
const
|
|
79
|
-
throw new Error(`Invalid attribute: ${
|
|
78
|
+
const s = e;
|
|
79
|
+
throw new Error(`Invalid attribute: ${s}`);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
get url() {
|
|
83
|
-
return this.connection.url;
|
|
83
|
+
return this.connection.url.peek();
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
set url(e) {
|
|
86
|
+
this.connection.url.set(e ? new URL(e) : void 0);
|
|
87
87
|
}
|
|
88
|
-
get
|
|
89
|
-
return this
|
|
88
|
+
get name() {
|
|
89
|
+
return this.broadcast.name.peek();
|
|
90
|
+
}
|
|
91
|
+
set name(e) {
|
|
92
|
+
this.broadcast.name.set(e ? n.Path.from(e) : void 0);
|
|
90
93
|
}
|
|
91
94
|
get paused() {
|
|
92
|
-
return this
|
|
95
|
+
return this.backend.paused.peek();
|
|
93
96
|
}
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
set paused(e) {
|
|
98
|
+
this.backend.paused.set(e);
|
|
99
|
+
}
|
|
100
|
+
get jitter() {
|
|
101
|
+
return this.backend.jitter.peek();
|
|
96
102
|
}
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
set jitter(e) {
|
|
104
|
+
this.backend.jitter.set(e);
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
107
|
customElements.define("moq-watch", b);
|
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 type * as Audio from \"./audio\";\nimport { type Backend, MultiBackend } from \"./backend\";\nimport { Broadcast } from \"./broadcast\";\nimport { Sync } from \"./sync\";\nimport type * as Video from \"./video\";\n\n// TODO remove name; replaced with path\n// TODO remove latency; replaced with buffer\nconst OBSERVED = [\"url\", \"name\", \"path\", \"paused\", \"volume\", \"muted\", \"reload\", \"jitter\", \"latency\"] 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 implements Backend {\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\t#backend: 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.effect((effect) => {\n\t\t\tconst url = effect.get(this.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.effect((effect) => {\n\t\t\tconst broadcast = effect.get(this.path);\n\t\t\tif (broadcast) {\n\t\t\t\tthis.setAttribute(\"path\", broadcast.toString());\n\t\t\t} else {\n\t\t\t\tthis.removeAttribute(\"path\");\n\t\t\t}\n\t\t});\n\n\t\tthis.signals.effect((effect) => {\n\t\t\tconst muted = effect.get(this.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.effect((effect) => {\n\t\t\tconst paused = effect.get(this.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.effect((effect) => {\n\t\t\tconst volume = effect.get(this.audio.volume);\n\t\t\tthis.setAttribute(\"volume\", volume.toString());\n\t\t});\n\n\t\tthis.signals.effect((effect) => {\n\t\t\tconst jitter = Math.floor(effect.get(this.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.url.set(newValue ? new URL(newValue) : undefined);\n\t\t} else if (name === \"name\" || name === \"path\") {\n\t\t\tthis.path.set(newValue ? Moq.Path.from(newValue) : undefined);\n\t\t} else if (name === \"paused\") {\n\t\t\tthis.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.audio.volume.set(volume);\n\t\t} else if (name === \"muted\") {\n\t\t\tthis.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\" || name === \"latency\") {\n\t\t\t// \"latency\" is a legacy alias for \"jitter\"\n\t\t\tthis.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(): Signal<URL | undefined> {\n\t\treturn this.connection.url;\n\t}\n\n\tget path(): Signal<Moq.Path.Valid | undefined> {\n\t\treturn this.broadcast.path;\n\t}\n\n\tget jitter(): Signal<Time.Milli> {\n\t\treturn this.#backend.jitter;\n\t}\n\n\tget paused(): Signal<boolean> {\n\t\treturn this.#backend.paused;\n\t}\n\n\tget audio(): Audio.Backend {\n\t\treturn this.#backend.audio;\n\t}\n\n\tget video(): Video.Backend {\n\t\treturn this.#backend.video;\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","#backend","#enabled","Signal","Effect","Moq","Broadcast","MultiBackend","setElement","canvas","video","observer","effect","url","broadcast","volume","jitter","name","oldValue","newValue","exhaustive"],"mappings":";;;AAWA,MAAMA,IAAW,CAAC,OAAO,QAAQ,QAAQ,UAAU,UAAU,SAAS,UAAU,UAAU,SAAS,GAM7FC,IAAU,IAAI,qBAA6B,CAACC,MAAYA,EAAQ,OAAO;AAG7E,MAAqBC,UAAiB,YAA+B;AAAA,EACpE,OAAO,qBAAqBH;AAAA;AAAA,EAG5B;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA,OAAO,IAAII,EAAA;AAAA;AAAA,EAGXC;AAAA;AAAA,EAGAC,KAAW,IAAIC,EAAO,EAAK;AAAA;AAAA,EAG3B,UAAU,IAAIC,EAAA;AAAA,EAEd,cAAc;AACb,UAAA,GAEAP,EAAQ,SAAS,MAAM,KAAK,OAAO,GAEnC,KAAK,aAAa,IAAIQ,EAAI,WAAW,OAAO;AAAA,MAC3C,SAAS,KAAKH;AAAA,IAAA,CACd,GACD,KAAK,QAAQ,QAAQ,MAAM,KAAK,WAAW,OAAO,GAEl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AO,WAAWA,CAAQ,IAAI,GAAkB;AAAA,WACtE;AACN,cAAMC,IAAoBH;AAC1B,cAAM,IAAI,MAAM,sBAAsBG,CAAU,EAAE;AAAA,MACnD;AAAA,EACD;AAAA,EAEA,IAAI,MAA+B;AAClC,WAAO,KAAK,WAAW;AAAA,EACxB;AAAA,EAEA,IAAI,OAA2C;AAC9C,WAAO,KAAK,UAAU;AAAA,EACvB;AAAA,EAEA,IAAI,SAA6B;AAChC,WAAO,KAAKnB,GAAS;AAAA,EACtB;AAAA,EAEA,IAAI,SAA0B;AAC7B,WAAO,KAAKA,GAAS;AAAA,EACtB;AAAA,EAEA,IAAI,QAAuB;AAC1B,WAAO,KAAKA,GAAS;AAAA,EACtB;AAAA,EAEA,IAAI,QAAuB;AAC1B,WAAO,KAAKA,GAAS;AAAA,EACtB;AACD;AAEA,eAAe,OAAO,aAAaF,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 { 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\tif (name) {\n\t\t\t\tthis.setAttribute(\"name\", name.toString());\n\t\t\t} else {\n\t\t\t\tthis.removeAttribute(\"name\");\n\t\t\t}\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(newValue ? Moq.Path.from(newValue) : undefined);\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 | undefined {\n\t\treturn this.broadcast.name.peek();\n\t}\n\n\tset name(value: string | Moq.Path.Valid | undefined) {\n\t\tthis.broadcast.name.set(value ? Moq.Path.from(value) : undefined);\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 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;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AAmB;AAAA,EAC5C;AACD;AAEA,eAAe,OAAO,aAAapB,CAAQ;"}
|
package/index.js
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { D as w, M as p, R as v, S as
|
|
2
|
-
import { B as L, m as N, g as V, h as W, t as Y } from "./broadcast-
|
|
3
|
-
import { Signal as i, Effect as
|
|
1
|
+
import { D as w, M as p, R as v, S as m, a as y, E as _, b as S, c as k, P as h, d as M, e as P, f } from "./broadcast-DhcOJtcZ.js";
|
|
2
|
+
import { B as L, m as N, g as V, h as W, t as Y } from "./broadcast-DhcOJtcZ.js";
|
|
3
|
+
import { Signal as i, Effect as c } from "@moq/signals";
|
|
4
4
|
const B = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5
5
|
__proto__: null,
|
|
6
6
|
Decoder: w,
|
|
7
7
|
Mse: p,
|
|
8
8
|
Renderer: v,
|
|
9
|
-
Source:
|
|
9
|
+
Source: m
|
|
10
10
|
}, Symbol.toStringTag, { value: "Module" })), D = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
11
11
|
__proto__: null,
|
|
12
|
-
Decoder:
|
|
13
|
-
Emitter:
|
|
14
|
-
Mse:
|
|
15
|
-
Source:
|
|
12
|
+
Decoder: y,
|
|
13
|
+
Emitter: _,
|
|
14
|
+
Mse: S,
|
|
15
|
+
Source: k
|
|
16
16
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
17
17
|
class O {
|
|
18
18
|
broadcast;
|
|
19
19
|
enabled;
|
|
20
20
|
// Empty string is a valid message.
|
|
21
|
-
#
|
|
22
|
-
latest = this.#
|
|
21
|
+
#t = new i(void 0);
|
|
22
|
+
latest = this.#t;
|
|
23
23
|
#s = new i(void 0);
|
|
24
24
|
catalog = this.#s;
|
|
25
|
-
#
|
|
26
|
-
constructor(s,
|
|
27
|
-
this.broadcast = s, this.enabled = i.from(a?.enabled ?? !1), this.#
|
|
28
|
-
|
|
29
|
-
}), this.#
|
|
25
|
+
#e = new c();
|
|
26
|
+
constructor(s, e, a) {
|
|
27
|
+
this.broadcast = s, this.enabled = i.from(a?.enabled ?? !1), this.#e.run((t) => {
|
|
28
|
+
t.get(this.enabled) && this.#s.set(t.get(e)?.chat?.message);
|
|
29
|
+
}), this.#e.run(this.#a.bind(this));
|
|
30
30
|
}
|
|
31
31
|
#a(s) {
|
|
32
|
-
const
|
|
33
|
-
if (!
|
|
34
|
-
const [a,
|
|
35
|
-
s.cleanup(() => n.close()), s.set(this.#
|
|
32
|
+
const e = s.getAll([this.enabled, this.#s, this.broadcast]);
|
|
33
|
+
if (!e) return;
|
|
34
|
+
const [a, t, o] = e, n = o.subscribe(t.name, h.chat);
|
|
35
|
+
s.cleanup(() => n.close()), s.set(this.#t, ""), s.cleanup(() => this.#t.set(void 0)), s.spawn(async () => {
|
|
36
36
|
for (; ; ) {
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
this.#
|
|
37
|
+
const r = await n.readString();
|
|
38
|
+
if (r === void 0) break;
|
|
39
|
+
this.#t.set(r);
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
close() {
|
|
44
|
-
this.#
|
|
44
|
+
this.#e.close();
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
class T {
|
|
48
48
|
broadcast;
|
|
49
49
|
enabled;
|
|
50
50
|
active;
|
|
51
|
-
#
|
|
52
|
-
catalog = this.#
|
|
53
|
-
#s = new
|
|
54
|
-
constructor(s,
|
|
55
|
-
this.broadcast = s, this.active = new i(void 0), this.enabled = i.from(a?.enabled ?? !1), this.#s.
|
|
56
|
-
|
|
57
|
-
}), this.#s.
|
|
58
|
-
}
|
|
59
|
-
#
|
|
60
|
-
const
|
|
61
|
-
if (!
|
|
62
|
-
const [a,
|
|
51
|
+
#t = new i(void 0);
|
|
52
|
+
catalog = this.#t;
|
|
53
|
+
#s = new c();
|
|
54
|
+
constructor(s, e, a) {
|
|
55
|
+
this.broadcast = s, this.active = new i(void 0), this.enabled = i.from(a?.enabled ?? !1), this.#s.run((t) => {
|
|
56
|
+
t.get(this.enabled) && this.#t.set(t.get(e)?.chat?.typing);
|
|
57
|
+
}), this.#s.run(this.#e.bind(this));
|
|
58
|
+
}
|
|
59
|
+
#e(s) {
|
|
60
|
+
const e = s.getAll([this.enabled, this.#t, this.broadcast]);
|
|
61
|
+
if (!e) return;
|
|
62
|
+
const [a, t, o] = e, n = o.subscribe(t.name, h.typing);
|
|
63
63
|
s.cleanup(() => n.close()), s.spawn(async () => {
|
|
64
64
|
for (; ; ) {
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
this.active.set(
|
|
65
|
+
const r = await n.readBool();
|
|
66
|
+
if (r === void 0) break;
|
|
67
|
+
this.active.set(r);
|
|
68
68
|
}
|
|
69
69
|
}), s.cleanup(() => this.active.set(void 0));
|
|
70
70
|
}
|
|
@@ -75,12 +75,12 @@ class T {
|
|
|
75
75
|
class j {
|
|
76
76
|
message;
|
|
77
77
|
typing;
|
|
78
|
-
#
|
|
79
|
-
#s = new
|
|
80
|
-
constructor(s,
|
|
81
|
-
this.message = new O(s,
|
|
82
|
-
const o =
|
|
83
|
-
!o && !n ||
|
|
78
|
+
#t = new i(void 0);
|
|
79
|
+
#s = new c();
|
|
80
|
+
constructor(s, e, a) {
|
|
81
|
+
this.message = new O(s, e, a?.message), this.typing = new T(s, e, a?.typing), this.#s.run((t) => {
|
|
82
|
+
const o = t.get(this.message.catalog), n = t.get(this.typing.catalog);
|
|
83
|
+
!o && !n || t.set(this.#t, {
|
|
84
84
|
message: o,
|
|
85
85
|
typing: n
|
|
86
86
|
});
|
|
@@ -94,34 +94,34 @@ const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
94
94
|
__proto__: null,
|
|
95
95
|
Chat: j
|
|
96
96
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
97
|
-
async function g(
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
100
|
-
return s.parse(
|
|
97
|
+
async function g(l, s) {
|
|
98
|
+
const e = await l.readJson();
|
|
99
|
+
if (e !== void 0)
|
|
100
|
+
return s.parse(e);
|
|
101
101
|
}
|
|
102
102
|
class x {
|
|
103
103
|
enabled;
|
|
104
104
|
broadcast;
|
|
105
|
-
#
|
|
105
|
+
#t = new i(void 0);
|
|
106
106
|
#s = new i(void 0);
|
|
107
|
-
signals = new
|
|
108
|
-
constructor(s,
|
|
109
|
-
this.broadcast = s, this.enabled = i.from(a?.enabled ?? !1), this.signals.
|
|
110
|
-
this.#
|
|
111
|
-
}), this.signals.
|
|
112
|
-
}
|
|
113
|
-
#
|
|
114
|
-
const
|
|
115
|
-
if (!
|
|
116
|
-
const [a,
|
|
107
|
+
signals = new c();
|
|
108
|
+
constructor(s, e, a) {
|
|
109
|
+
this.broadcast = s, this.enabled = i.from(a?.enabled ?? !1), this.signals.run((t) => {
|
|
110
|
+
this.#t.set(t.get(e)?.location?.peers);
|
|
111
|
+
}), this.signals.run(this.#e.bind(this));
|
|
112
|
+
}
|
|
113
|
+
#e(s) {
|
|
114
|
+
const e = s.getAll([this.enabled, this.#t, this.broadcast]);
|
|
115
|
+
if (!e) return;
|
|
116
|
+
const [a, t, o] = e, n = o.subscribe(t.name, h.location);
|
|
117
117
|
s.cleanup(() => n.close()), s.spawn(this.#a.bind(this, n));
|
|
118
118
|
}
|
|
119
119
|
async #a(s) {
|
|
120
120
|
try {
|
|
121
121
|
for (; ; ) {
|
|
122
|
-
const
|
|
123
|
-
if (!
|
|
124
|
-
this.#s.set(
|
|
122
|
+
const e = await g(s, M);
|
|
123
|
+
if (!e) break;
|
|
124
|
+
this.#s.set(e);
|
|
125
125
|
}
|
|
126
126
|
} finally {
|
|
127
127
|
this.#s.set(void 0), s.close();
|
|
@@ -137,37 +137,37 @@ class x {
|
|
|
137
137
|
class A {
|
|
138
138
|
broadcast;
|
|
139
139
|
enabled;
|
|
140
|
-
#e = new i(void 0);
|
|
141
|
-
handle = this.#e;
|
|
142
|
-
#s = new i(void 0);
|
|
143
140
|
#t = new i(void 0);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
141
|
+
handle = this.#t;
|
|
142
|
+
#s = new i(void 0);
|
|
143
|
+
#e = new i(void 0);
|
|
144
|
+
position = this.#e;
|
|
145
|
+
signals = new c();
|
|
146
|
+
constructor(s, e, a) {
|
|
147
|
+
this.broadcast = s, this.enabled = i.from(a?.enabled ?? !1), this.signals.run((t) => {
|
|
148
|
+
this.#s.set(t.get(e)?.location);
|
|
149
|
+
}), this.signals.run((t) => {
|
|
150
|
+
t.get(this.enabled) && this.#e.set(t.get(this.#s)?.initial);
|
|
151
|
+
}), this.signals.run((t) => {
|
|
152
|
+
this.#t.set(t.get(this.#s)?.handle);
|
|
153
|
+
}), this.signals.run((t) => {
|
|
154
|
+
const o = t.get(this.broadcast);
|
|
155
155
|
if (!o) return;
|
|
156
|
-
const n =
|
|
156
|
+
const n = t.get(this.#s)?.track;
|
|
157
157
|
if (!n) return;
|
|
158
|
-
const
|
|
159
|
-
|
|
158
|
+
const r = o.subscribe(n.name, h.location);
|
|
159
|
+
t.cleanup(() => r.close()), t.spawn(this.#a.bind(this, r));
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
162
|
async #a(s) {
|
|
163
163
|
try {
|
|
164
164
|
for (; ; ) {
|
|
165
|
-
const
|
|
166
|
-
if (!
|
|
167
|
-
this.#
|
|
165
|
+
const e = await g(s, P);
|
|
166
|
+
if (!e) break;
|
|
167
|
+
this.#e.set(e);
|
|
168
168
|
}
|
|
169
169
|
} finally {
|
|
170
|
-
this.#
|
|
170
|
+
this.#e.set(void 0), s.close();
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
close() {
|
|
@@ -177,9 +177,9 @@ class A {
|
|
|
177
177
|
class R {
|
|
178
178
|
window;
|
|
179
179
|
peers;
|
|
180
|
-
signals = new
|
|
181
|
-
constructor(s,
|
|
182
|
-
this.window = new A(s,
|
|
180
|
+
signals = new c();
|
|
181
|
+
constructor(s, e, a) {
|
|
182
|
+
this.window = new A(s, e, a?.window), this.peers = new x(s, e, a?.peers);
|
|
183
183
|
}
|
|
184
184
|
close() {
|
|
185
185
|
this.signals.close(), this.window.close(), this.peers.close();
|
|
@@ -193,24 +193,24 @@ class I {
|
|
|
193
193
|
broadcast;
|
|
194
194
|
enabled;
|
|
195
195
|
preview = new i(void 0);
|
|
196
|
-
#
|
|
197
|
-
#s = new
|
|
198
|
-
constructor(s,
|
|
199
|
-
this.broadcast = s, this.enabled = i.from(a?.enabled ?? !1), this.#s.
|
|
200
|
-
this.#
|
|
201
|
-
}), this.#s.
|
|
202
|
-
const o =
|
|
196
|
+
#t = new i(void 0);
|
|
197
|
+
#s = new c();
|
|
198
|
+
constructor(s, e, a) {
|
|
199
|
+
this.broadcast = s, this.enabled = i.from(a?.enabled ?? !1), this.#s.run((t) => {
|
|
200
|
+
this.#t.set(t.get(e)?.preview);
|
|
201
|
+
}), this.#s.run((t) => {
|
|
202
|
+
const o = t.getAll([this.enabled, this.broadcast, this.#t]);
|
|
203
203
|
if (!o) return;
|
|
204
|
-
const [n,
|
|
205
|
-
|
|
204
|
+
const [n, r, b] = o, u = r.subscribe(b.name, h.preview);
|
|
205
|
+
t.cleanup(() => u.close()), t.spawn(async () => {
|
|
206
206
|
try {
|
|
207
|
-
const d = await g(
|
|
207
|
+
const d = await g(u, f);
|
|
208
208
|
if (!d) return;
|
|
209
209
|
this.preview.set(d);
|
|
210
210
|
} catch (d) {
|
|
211
211
|
console.warn("Failed to parse preview JSON:", d);
|
|
212
212
|
}
|
|
213
|
-
}),
|
|
213
|
+
}), t.cleanup(() => this.preview.set(void 0));
|
|
214
214
|
});
|
|
215
215
|
}
|
|
216
216
|
close() {
|