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