-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathmain.ts
More file actions
46 lines (38 loc) · 1.48 KB
/
main.ts
File metadata and controls
46 lines (38 loc) · 1.48 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
import '@app/styles.css';
import '@videojs/html/video/player';
import '@videojs/html/media/simple-hls-video';
import { createHtmlSandboxState, createLatestLoader } from '@app/shared/html/sandbox-state';
import { loadVideoSkinTag } from '@app/shared/html/skins';
import { renderStoryboard } from '@app/shared/html/storyboard';
import { onSkinChange, onSourceChange } from '@app/shared/sandbox-listener';
import { getPosterSrc, getStoryboardSrc, isLiveSource, SOURCES } from '@app/shared/sources';
const html = String.raw;
const state = createHtmlSandboxState();
const loadLatest = createLatestLoader();
async function render() {
const live = isLiveSource(state.source);
const tag = await loadLatest(() => loadVideoSkinTag(state.skin, state.styling, { live }));
if (!tag) return;
const storyboard = getStoryboardSrc(state.source);
const poster = getPosterSrc(state.source);
const liveAttrs = live ? 'autoplay muted' : '';
document.getElementById('root')!.innerHTML = html`
<video-player>
<${tag} class="aspect-video max-w-4xl mx-auto">
<simple-hls-video src="${SOURCES[state.source].url}" ${liveAttrs} playsinline crossorigin="anonymous">
${renderStoryboard(storyboard)}
</simple-hls-video>
${poster ? html`<img slot="poster" src="${poster}" alt="Video poster" />` : ''}
</${tag}>
</video-player>
`;
}
render();
onSkinChange((skin) => {
state.skin = skin;
render();
});
onSourceChange((source) => {
state.source = source;
render();
});