-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwatch-embed.tsx
More file actions
71 lines (58 loc) · 2.3 KB
/
Copy pathwatch-embed.tsx
File metadata and controls
71 lines (58 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import hljs from "@/lib/highlight";
export default function WatchEmbed() {
const params = new URLSearchParams(window.location.search);
const name = params.get("name") ?? "bbb";
// The relay URL on /watch may include a JWT for BBB; strip query params.
const relay = new URL("/anon", import.meta.env.PUBLIC_RELAY_URL);
const publicUrl = new URL(relay.pathname, relay.origin).toString();
const embedHtml = `<script type="module">
import "https://cdn.jsdelivr.net/npm/@moq/watch/element.js/+esm";
import "https://cdn.jsdelivr.net/npm/@moq/watch/ui/index.js/+esm";
</script>
<!-- Optional wrapper that adds pause/volume controls. -->
<moq-watch-ui>
<!-- See https://doc.moq.dev/js/@moq/watch for all supported attributes. -->
<moq-watch id="watch" url="${publicUrl}" name="${name}" muted reload>
<!-- Provide your own canvas to style as needed. -->
<canvas></canvas>
</moq-watch>
</moq-watch-ui>`;
const embedJs = `import * as Watch from "@moq/watch";
// A MoQ connection that is automatically re-established on drop.
const connection = new Watch.Lite.Connection.Reload({
url: new URL("${publicUrl}"),
enabled: true,
});
// The MoQ broadcast being fetched.
const broadcast = new Watch.Broadcast({
connection: connection.established,
enabled: true,
name: Watch.Lite.Path.from("${name}"),
});
// Synchronize audio and video playback.
const sync = new Watch.Sync();
// Decode and render video into your own canvas.
const videoSource = new Watch.Video.Source(sync, { broadcast });
const videoDecoder = new Watch.Video.Decoder(videoSource);
const videoRenderer = new Watch.Video.Renderer(videoDecoder, { canvas, paused: false });
// Decode and emit audio through WebAudio.
const audioSource = new Watch.Audio.Source(sync, { broadcast });
const audioDecoder = new Watch.Audio.Decoder(audioSource);
const audioEmitter = new Watch.Audio.Emitter(audioDecoder, { paused: false });`;
const highlight = (el: HTMLElement) => queueMicrotask(() => hljs.highlightElement(el));
return (
<>
<pre>
<code ref={highlight} class="language-html">
{embedHtml}
</code>
</pre>
<p>Or skip the web component entirely and drive the lower-level JavaScript API directly.</p>
<pre>
<code ref={highlight} class="language-typescript">
{embedJs}
</code>
</pre>
</>
);
}