]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/assets/player/shared/manager-options/control-bar-options-builder.ts
Merge branch 'release/4.3.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / shared / manager-options / control-bar-options-builder.ts
CommitLineData
57d65032
C
1import {
2 CommonOptions,
3 NextPreviousVideoButtonOptions,
4 PeerTubeLinkButtonOptions,
5 PeertubePlayerManagerOptions,
6 PlayerMode
7} from '../../types'
9597920e
C
8
9export 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, {
bd2b51be
C
54 peerTubeLinkButton: {
55 shortUUID: this.options.videoShortUUID,
56 instanceName: this.options.instanceName
57 } as PeerTubeLinkButtonOptions
9597920e
C
58 })
59 }
60
61 if (this.options.theaterButton === true) {
62 Object.assign(children, {
63 theaterButton: {}
64 })
65 }
66
67 Object.assign(children, {
68 fullscreenToggle: {}
69 })
70
71 return children
72 }
73
74 private getSettingsButton () {
75 const settingEntries: string[] = []
76
77 settingEntries.push('playbackRateMenuButton')
78
79 if (this.options.captions === true) settingEntries.push('captionsButton')
80
81 settingEntries.push('resolutionMenuButton')
82
83 return {
84 settingsButton: {
85 setup: {
86 maxHeightOffset: 40
87 },
88 entries: settingEntries
89 }
90 }
91 }
92
93 private getProgressControl () {
94 const loadProgressBar = this.mode === 'webtorrent'
95 ? 'peerTubeLoadProgressBar'
96 : 'loadProgressBar'
97
98 return {
99 progressControl: {
100 children: {
101 seekBar: {
102 children: {
103 [loadProgressBar]: {},
104 mouseTimeDisplay: {},
105 playProgressBar: {}
106 }
107 }
108 }
109 }
110 }
111 }
112
113 private getPreviousVideo () {
114 const buttonOptions: NextPreviousVideoButtonOptions = {
115 type: 'previous',
116 handler: this.options.previousVideo,
117 isDisabled: () => {
118 if (!this.options.hasPreviousVideo) return false
119
120 return !this.options.hasPreviousVideo()
121 }
122 }
123
124 return { previousVideoButton: buttonOptions }
125 }
126
127 private getNextVideo () {
128 const buttonOptions: NextPreviousVideoButtonOptions = {
129 type: 'next',
130 handler: this.options.nextVideo,
131 isDisabled: () => {
132 if (!this.options.hasNextVideo) return false
133
134 return !this.options.hasNextVideo()
135 }
136 }
137
138 return { nextVideoButton: buttonOptions }
139 }
140}