]>
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 | ||
b27bce21 C |
74 | if (!this.options.isLive) { |
75 | settingEntries.push('playbackRateMenuButton') | |
76 | } | |
9597920e C |
77 | |
78 | if (this.options.captions === true) settingEntries.push('captionsButton') | |
79 | ||
80 | settingEntries.push('resolutionMenuButton') | |
81 | ||
82 | return { | |
83 | settingsButton: { | |
84 | setup: { | |
85 | maxHeightOffset: 40 | |
86 | }, | |
87 | entries: settingEntries | |
88 | } | |
89 | } | |
90 | } | |
91 | ||
0e7c4b03 C |
92 | private getTimeControls () { |
93 | if (this.options.isLive) { | |
94 | return { | |
95 | peerTubeLiveDisplay: {} | |
96 | } | |
97 | } | |
98 | ||
99 | return { | |
100 | currentTimeDisplay: {}, | |
101 | timeDivider: {}, | |
102 | durationDisplay: {} | |
103 | } | |
104 | } | |
105 | ||
9597920e | 106 | private getProgressControl () { |
0e7c4b03 C |
107 | if (this.options.isLive) return {} |
108 | ||
9597920e C |
109 | const loadProgressBar = this.mode === 'webtorrent' |
110 | ? 'peerTubeLoadProgressBar' | |
111 | : 'loadProgressBar' | |
112 | ||
113 | return { | |
114 | progressControl: { | |
115 | children: { | |
116 | seekBar: { | |
117 | children: { | |
118 | [loadProgressBar]: {}, | |
119 | mouseTimeDisplay: {}, | |
120 | playProgressBar: {} | |
121 | } | |
122 | } | |
123 | } | |
124 | } | |
125 | } | |
126 | } | |
127 | ||
128 | private getPreviousVideo () { | |
129 | const buttonOptions: NextPreviousVideoButtonOptions = { | |
130 | type: 'previous', | |
131 | handler: this.options.previousVideo, | |
132 | isDisabled: () => { | |
133 | if (!this.options.hasPreviousVideo) return false | |
134 | ||
135 | return !this.options.hasPreviousVideo() | |
136 | } | |
137 | } | |
138 | ||
139 | return { previousVideoButton: buttonOptions } | |
140 | } | |
141 | ||
142 | private getNextVideo () { | |
143 | const buttonOptions: NextPreviousVideoButtonOptions = { | |
144 | type: 'next', | |
145 | handler: this.options.nextVideo, | |
146 | isDisabled: () => { | |
147 | if (!this.options.hasNextVideo) return false | |
148 | ||
149 | return !this.options.hasNextVideo() | |
150 | } | |
151 | } | |
152 | ||
153 | return { nextVideoButton: buttonOptions } | |
154 | } | |
155 | } |