]>
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, { | |
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 | ||
57d65032 | 49 | ...this.getSettingsButton() |
9597920e C |
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 | } |