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