Do not bundle two different videojs versions
[oweals/peertube.git] / client / src / assets / player / peertube-player.ts
1 import { VideoFile } from '../../../../shared/models/videos'
2
3 import 'videojs-hotkeys'
4 import 'videojs-dock'
5 import './peertube-link-button'
6 import './resolution-menu-button'
7 import './settings-menu-button'
8 import './webtorrent-info-button'
9 import './peertube-videojs-plugin'
10 import { videojsUntyped } from './peertube-videojs-typings'
11
12 // Change 'Playback Rate' to 'Speed' (smaller for our settings menu)
13 videojsUntyped.getComponent('PlaybackRateMenuButton').prototype.controlText_ = 'Speed'
14
15 function getVideojsOptions (options: {
16   autoplay: boolean,
17   playerElement: HTMLVideoElement,
18   videoViewUrl: string,
19   videoDuration: number,
20   videoFiles: VideoFile[],
21   enableHotkeys: boolean,
22   inactivityTimeout: number,
23   peertubeLink: boolean,
24   poster: string,
25   startTime: number
26 }) {
27   const videojsOptions = {
28     controls: true,
29     poster: options.poster,
30     autoplay: false,
31     inactivityTimeout: options.inactivityTimeout,
32     playbackRates: [ 0.5, 1, 1.5, 2 ],
33     plugins: {
34       peertube: {
35         autoplay: options.autoplay, // Use peertube plugin autoplay because we get the file by webtorrent
36         videoFiles: options.videoFiles,
37         playerElement: options.playerElement,
38         videoViewUrl: options.videoViewUrl,
39         videoDuration: options.videoDuration,
40         startTime: options.startTime
41       }
42     },
43     controlBar: {
44       children: getControlBarChildren(options)
45     }
46   }
47
48   if (options.enableHotkeys === true) {
49     Object.assign(videojsOptions.plugins, {
50       hotkeys: {
51         enableVolumeScroll: false
52       }
53     })
54   }
55
56   return videojsOptions
57 }
58
59 function getControlBarChildren (options: {
60   peertubeLink: boolean
61 }) {
62   const children = {
63     'playToggle': {},
64     'currentTimeDisplay': {},
65     'timeDivider': {},
66     'durationDisplay': {},
67     'liveDisplay': {},
68
69     'flexibleWidthSpacer': {},
70     'progressControl': {},
71
72     'webTorrentButton': {},
73
74     'muteToggle': {},
75     'volumeControl': {},
76
77     'settingsButton': {
78       setup: {
79         maxHeightOffset: 40
80       },
81       entries: [
82         'resolutionMenuButton',
83         'playbackRateMenuButton'
84       ]
85     }
86   }
87
88   if (options.peertubeLink === true) {
89     Object.assign(children, {
90       'peerTubeLinkButton': {}
91     })
92   }
93
94   Object.assign(children, {
95     'fullscreenToggle': {}
96   })
97
98   return children
99 }
100
101 export { getVideojsOptions }