diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-14 14:28:20 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-14 14:36:35 +0100 |
commit | 57d6503286b114fee61b5e4725825e2490dcac29 (patch) | |
tree | 2d3d23f697b2986d7e41bb443754394296b66ec3 /client/src/assets/player/shared/manager-options/control-bar-options-builder.ts | |
parent | 9597920ee3d4ac99803e7107983ddf98a9dfb3c4 (diff) | |
download | PeerTube-57d6503286b114fee61b5e4725825e2490dcac29.tar.gz PeerTube-57d6503286b114fee61b5e4725825e2490dcac29.tar.zst PeerTube-57d6503286b114fee61b5e4725825e2490dcac29.zip |
Reorganize player files
Diffstat (limited to 'client/src/assets/player/shared/manager-options/control-bar-options-builder.ts')
-rw-r--r-- | client/src/assets/player/shared/manager-options/control-bar-options-builder.ts | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/client/src/assets/player/shared/manager-options/control-bar-options-builder.ts b/client/src/assets/player/shared/manager-options/control-bar-options-builder.ts new file mode 100644 index 000000000..72a10eb26 --- /dev/null +++ b/client/src/assets/player/shared/manager-options/control-bar-options-builder.ts | |||
@@ -0,0 +1,137 @@ | |||
1 | import { | ||
2 | CommonOptions, | ||
3 | NextPreviousVideoButtonOptions, | ||
4 | PeerTubeLinkButtonOptions, | ||
5 | PeertubePlayerManagerOptions, | ||
6 | PlayerMode | ||
7 | } from '../../types' | ||
8 | |||
9 | export class ControlBarOptionsBuilder { | ||
10 | private options: CommonOptions | ||
11 | |||
12 | constructor ( | ||
13 | globalOptions: PeertubePlayerManagerOptions, | ||
14 | private mode: PlayerMode | ||
15 | ) { | ||
16 | this.options = globalOptions.common | ||
17 | } | ||
18 | |||
19 | getChildrenOptions () { | ||
20 | const children = {} | ||
21 | |||
22 | if (this.options.previousVideo) { | ||
23 | Object.assign(children, this.getPreviousVideo()) | ||
24 | } | ||
25 | |||
26 | Object.assign(children, { playToggle: {} }) | ||
27 | |||
28 | if (this.options.nextVideo) { | ||
29 | Object.assign(children, this.getNextVideo()) | ||
30 | } | ||
31 | |||
32 | Object.assign(children, { | ||
33 | currentTimeDisplay: {}, | ||
34 | timeDivider: {}, | ||
35 | durationDisplay: {}, | ||
36 | liveDisplay: {}, | ||
37 | |||
38 | flexibleWidthSpacer: {}, | ||
39 | |||
40 | ...this.getProgressControl(), | ||
41 | |||
42 | p2PInfoButton: { | ||
43 | p2pEnabled: this.options.p2pEnabled | ||
44 | }, | ||
45 | |||
46 | muteToggle: {}, | ||
47 | volumeControl: {}, | ||
48 | |||
49 | ...this.getSettingsButton() | ||
50 | }) | ||
51 | |||
52 | if (this.options.peertubeLink === true) { | ||
53 | Object.assign(children, { | ||
54 | peerTubeLinkButton: { shortUUID: this.options.videoShortUUID } as PeerTubeLinkButtonOptions | ||
55 | }) | ||
56 | } | ||
57 | |||
58 | if (this.options.theaterButton === true) { | ||
59 | Object.assign(children, { | ||
60 | theaterButton: {} | ||
61 | }) | ||
62 | } | ||
63 | |||
64 | Object.assign(children, { | ||
65 | fullscreenToggle: {} | ||
66 | }) | ||
67 | |||
68 | return children | ||
69 | } | ||
70 | |||
71 | private getSettingsButton () { | ||
72 | const settingEntries: string[] = [] | ||
73 | |||
74 | settingEntries.push('playbackRateMenuButton') | ||
75 | |||
76 | if (this.options.captions === true) settingEntries.push('captionsButton') | ||
77 | |||
78 | settingEntries.push('resolutionMenuButton') | ||
79 | |||
80 | return { | ||
81 | settingsButton: { | ||
82 | setup: { | ||
83 | maxHeightOffset: 40 | ||
84 | }, | ||
85 | entries: settingEntries | ||
86 | } | ||
87 | } | ||
88 | } | ||
89 | |||
90 | private getProgressControl () { | ||
91 | const loadProgressBar = this.mode === 'webtorrent' | ||
92 | ? 'peerTubeLoadProgressBar' | ||
93 | : 'loadProgressBar' | ||
94 | |||
95 | return { | ||
96 | progressControl: { | ||
97 | children: { | ||
98 | seekBar: { | ||
99 | children: { | ||
100 | [loadProgressBar]: {}, | ||
101 | mouseTimeDisplay: {}, | ||
102 | playProgressBar: {} | ||
103 | } | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | |||
110 | private getPreviousVideo () { | ||
111 | const buttonOptions: NextPreviousVideoButtonOptions = { | ||
112 | type: 'previous', | ||
113 | handler: this.options.previousVideo, | ||
114 | isDisabled: () => { | ||
115 | if (!this.options.hasPreviousVideo) return false | ||
116 | |||
117 | return !this.options.hasPreviousVideo() | ||
118 | } | ||
119 | } | ||
120 | |||
121 | return { previousVideoButton: buttonOptions } | ||
122 | } | ||
123 | |||
124 | private getNextVideo () { | ||
125 | const buttonOptions: NextPreviousVideoButtonOptions = { | ||
126 | type: 'next', | ||
127 | handler: this.options.nextVideo, | ||
128 | isDisabled: () => { | ||
129 | if (!this.options.hasNextVideo) return false | ||
130 | |||
131 | return !this.options.hasNextVideo() | ||
132 | } | ||
133 | } | ||
134 | |||
135 | return { nextVideoButton: buttonOptions } | ||
136 | } | ||
137 | } | ||