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