forked from muxinc/elements
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.ts
More file actions
160 lines (153 loc) · 5.85 KB
/
template.ts
File metadata and controls
160 lines (153 loc) · 5.85 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import 'media-chrome/dist/media-theme-element.js';
// @ts-ignore
import cssStr from './styles.css';
import { getStreamTypeFromAttr } from './helpers';
import { html } from './html';
import { stylePropsToString } from './utils';
import type { MuxTemplateProps } from './types';
import { StreamTypes, toMuxVideoURL } from '@mux/playback-core';
const getPropsCSS = (props: MuxTemplateProps) => {
const { tokens } = props;
if (!tokens.drm) return '';
// See styles.css for usage.
return ':host(:not([cast-receiver])) { --_cast-button-drm-display: none; }';
};
export const template = (props: MuxTemplateProps) => html`
<style>
${getPropsCSS(props)}
${cssStr}
</style>
${content(props)}
`;
const getHotKeys = (props: MuxTemplateProps) => {
let hotKeys = props.hotKeys ? `${props.hotKeys}` : '';
// Applies to any live content, including "dvr". We may want to only apply for non-DVR live.
if (getStreamTypeFromAttr(props.streamType) === 'live') {
hotKeys += ' noarrowleft noarrowright';
}
return hotKeys;
};
// Warning: remember to update `ThemeAttributeNames` in index.ts
// if you add or remove attributes in <media-theme>.
// NOTE: Make sure to add/update internal parts here so they're available for Mux Player users for advanced CSS customization!
export const Parts = {
// media container regions
TOP: 'top',
CENTER: 'center',
BOTTOM: 'bottom',
// media container layers
LAYER: 'layer', // Generic
MEDIA_LAYER: 'media-layer',
POSTER_LAYER: 'poster-layer',
VERTICAL_LAYER: 'vertical-layer',
CENTERED_LAYER: 'centered-layer',
GESTURE_LAYER: 'gesture-layer',
CONTROLLER_LAYER: 'controller',
// component/subcomponent types
BUTTON: 'button',
RANGE: 'range',
THUMB: 'thumb',
DISPLAY: 'display',
CONTROL_BAR: 'control-bar',
MENU_BUTTON: 'menu-button',
MENU: 'menu',
MENU_ITEM: 'menu-item',
OPTION: 'option',
// component/subcomponent purposes
POSTER: 'poster',
LIVE: 'live',
PLAY: 'play',
PRE_PLAY: 'pre-play',
SEEK_BACKWARD: 'seek-backward',
SEEK_FORWARD: 'seek-forward',
MUTE: 'mute',
CAPTIONS: 'captions',
AIRPLAY: 'airplay',
PIP: 'pip',
FULLSCREEN: 'fullscreen',
CAST: 'cast',
PLAYBACK_RATE: 'playback-rate',
VOLUME: 'volume',
TIME: 'time',
TITLE: 'title',
AUDIO_TRACK: 'audio-track',
RENDITION: 'rendition',
};
export const partsListStr = Object.values(Parts).join(', ');
export const content = (props: MuxTemplateProps) => html`
<media-theme
template="${props.themeTemplate || false}"
defaultstreamtype="${props.defaultStreamType ?? false}"
hotkeys="${getHotKeys(props) || false}"
nohotkeys="${props.noHotKeys || !props.hasSrc || false}"
noautoseektolive="${!!props.streamType?.includes(StreamTypes.LIVE) && props.targetLiveWindow !== 0}"
novolumepref="${props.novolumepref || false}"
nomutedpref="${props.nomutedpref || false}"
disabled="${!props.hasSrc || props.isDialogOpen}"
audio="${props.audio ?? false}"
style="${stylePropsToString({
'--media-primary-color': props.primaryColor,
'--media-secondary-color': props.secondaryColor,
'--media-accent-color': props.accentColor,
}) ?? false}"
defaultsubtitles="${!props.defaultHiddenCaptions}"
forwardseekoffset="${props.forwardSeekOffset ?? false}"
backwardseekoffset="${props.backwardSeekOffset ?? false}"
playbackrates="${props.playbackRates ?? false}"
defaultshowremainingtime="${props.defaultShowRemainingTime ?? false}"
defaultduration="${props.defaultDuration ?? false}"
hideduration="${props.hideDuration ?? false}"
title="${props.title ?? false}"
videotitle="${props.videoTitle ?? false}"
proudlydisplaymuxbadge="${props.proudlyDisplayMuxBadge ?? false}"
exportparts="${partsListStr}"
onclose="${props.onCloseErrorDialog}"
onfocusin="${props.onFocusInErrorDialog}"
>
<mux-video
slot="media"
inert="${props.noHotKeys ?? false}"
target-live-window="${props.targetLiveWindow ?? false}"
stream-type="${getStreamTypeFromAttr(props.streamType) ?? false}"
crossorigin="${props.crossOrigin ?? ''}"
playsinline
autoplay="${props.autoplay ?? false}"
muted="${props.muted ?? false}"
loop="${props.loop ?? false}"
preload="${props.preload ?? false}"
debug="${props.debug ?? false}"
prefer-cmcd="${props.preferCmcd ?? false}"
disable-tracking="${props.disableTracking ?? false}"
disable-cookies="${props.disableCookies ?? false}"
prefer-playback="${props.preferPlayback ?? false}"
start-time="${props.startTime != null ? props.startTime : false}"
beacon-collection-domain="${props.beaconCollectionDomain ?? false}"
player-init-time="${props.playerInitTime ?? false}"
player-software-name="${props.playerSoftwareName ?? false}"
player-software-version="${props.playerSoftwareVersion ?? false}"
env-key="${props.envKey ?? false}"
custom-domain="${props.customDomain ?? false}"
src="${!!props.src ? props.src : props.playbackId ? toMuxVideoURL(props) : false}"
cast-src="${!!props.src ? props.src : props.playbackId ? toMuxVideoURL(props) : false}"
cast-receiver="${props.castReceiver ?? false}"
drm-token="${props.tokens?.drm ?? false}"
exportparts="video"
disable-pseudo-ended="${props.disablePseudoEnded ?? false}"
prefer-lower-resolution="${props.preferLowerResolution ?? false}"
cap-default-resolution="${props.capDefaultResolution ?? false}"
>
${props.storyboard
? html`<track label="thumbnails" default kind="metadata" src="${props.storyboard}" />`
: html``}
<slot></slot>
</mux-video>
<slot name="poster" slot="poster">
<media-poster-image
part="poster"
exportparts="poster, img"
src="${!!props.poster ? props.poster : false}"
placeholdersrc="${props.placeholder ?? false}"
></media-poster-image>
</slot>
</media-theme>
`;