]>
Commit | Line | Data |
---|---|---|
57d65032 C |
1 | import { |
2 | CommonOptions, | |
3 | NextPreviousVideoButtonOptions, | |
4 | PeerTubeLinkButtonOptions, | |
5 | PeertubePlayerManagerOptions, | |
6 | PlayerMode | |
7 | } from '../../types' | |
9597920e C |
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, { | |
0e7c4b03 | 33 | ...this.getTimeControls(), |
9597920e C |
34 | |
35 | flexibleWidthSpacer: {}, | |
36 | ||
37 | ...this.getProgressControl(), | |
38 | ||
39 | p2PInfoButton: { | |
40 | p2pEnabled: this.options.p2pEnabled | |
41 | }, | |
42 | ||
43 | muteToggle: {}, | |
44 | volumeControl: {}, | |
45 | ||
57d65032 | 46 | ...this.getSettingsButton() |
9597920e C |
47 | }) |
48 | ||
49 | if (this.options.peertubeLink === true) { | |
50 | Object.assign(children, { | |
bd2b51be C |
51 | peerTubeLinkButton: { |
52 | shortUUID: this.options.videoShortUUID, | |
53 | instanceName: this.options.instanceName | |
54 | } as PeerTubeLinkButtonOptions | |
9597920e C |
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 | ||
0e7c4b03 C |
90 | private getTimeControls () { |
91 | if (this.options.isLive) { | |
92 | return { | |
93 | peerTubeLiveDisplay: {} | |
94 | } | |
95 | } | |
96 | ||
97 | return { | |
98 | currentTimeDisplay: {}, | |
99 | timeDivider: {}, | |
100 | durationDisplay: {} | |
101 | } | |
102 | } | |
103 | ||
9597920e | 104 | private getProgressControl () { |
0e7c4b03 C |
105 | if (this.options.isLive) return {} |
106 | ||
9597920e C |
107 | const loadProgressBar = this.mode === 'webtorrent' |
108 | ? 'peerTubeLoadProgressBar' | |
109 | : 'loadProgressBar' | |
110 | ||
111 | return { | |
112 | progressControl: { | |
113 | children: { | |
114 | seekBar: { | |
115 | children: { | |
116 | [loadProgressBar]: {}, | |
117 | mouseTimeDisplay: {}, | |
118 | playProgressBar: {} | |
119 | } | |
120 | } | |
121 | } | |
122 | } | |
123 | } | |
124 | } | |
125 | ||
126 | private getPreviousVideo () { | |
127 | const buttonOptions: NextPreviousVideoButtonOptions = { | |
128 | type: 'previous', | |
129 | handler: this.options.previousVideo, | |
130 | isDisabled: () => { | |
131 | if (!this.options.hasPreviousVideo) return false | |
132 | ||
133 | return !this.options.hasPreviousVideo() | |
134 | } | |
135 | } | |
136 | ||
137 | return { previousVideoButton: buttonOptions } | |
138 | } | |
139 | ||
140 | private getNextVideo () { | |
141 | const buttonOptions: NextPreviousVideoButtonOptions = { | |
142 | type: 'next', | |
143 | handler: this.options.nextVideo, | |
144 | isDisabled: () => { | |
145 | if (!this.options.hasNextVideo) return false | |
146 | ||
147 | return !this.options.hasNextVideo() | |
148 | } | |
149 | } | |
150 | ||
151 | return { nextVideoButton: buttonOptions } | |
152 | } | |
153 | } |