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