]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/assets/player/peertube-player.ts
Improve player
[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,
23 peertubeLink: boolean
24}) {
25 const videojsOptions = {
26 controls: true,
27 autoplay: options.autoplay,
28 inactivityTimeout: options.inactivityTimeout,
29 playbackRates: [ 0.5, 1, 1.5, 2 ],
30 plugins: {
31 peertube: {
32 videoFiles: options.videoFiles,
33 playerElement: options.playerElement,
34 videoViewUrl: options.videoViewUrl,
35 videoDuration: options.videoDuration
36 }
37 },
38 controlBar: {
39 children: getControlBarChildren(options)
40 }
41 }
42
43 if (options.enableHotkeys === true) {
44 Object.assign(videojsOptions.plugins, {
45 hotkeys: {
46 enableVolumeScroll: false
47 }
48 })
49 }
50
51 return videojsOptions
52}
53
54function getControlBarChildren (options: {
55 peertubeLink: boolean
56}) {
57 const children = {
58 'playToggle': {},
59 'currentTimeDisplay': {},
60 'timeDivider': {},
61 'durationDisplay': {},
62 'liveDisplay': {},
63
64 'flexibleWidthSpacer': {},
65 'progressControl': {},
66
67 'webTorrentButton': {},
68
69 'muteToggle': {},
70 'volumeControl': {},
71
72 'settingsButton': {
73 setup: {
74 maxHeightOffset: 40
75 },
76 entries: [
77 'resolutionMenuButton',
78 'playbackRateMenuButton'
79 ]
80 }
81 }
82
83 if (options.peertubeLink === true) {
84 Object.assign(children, {
85 'peerTubeLinkButton': {}
86 })
87 }
88
89 Object.assign(children, {
90 'fullscreenToggle': {}
91 })
92
93 return children
94}
95
96export { getVideojsOptions }