diff options
Diffstat (limited to 'client/src/assets/player/peertube-player.ts')
-rw-r--r-- | client/src/assets/player/peertube-player.ts | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/client/src/assets/player/peertube-player.ts b/client/src/assets/player/peertube-player.ts new file mode 100644 index 000000000..4ae3e71bd --- /dev/null +++ b/client/src/assets/player/peertube-player.ts | |||
@@ -0,0 +1,96 @@ | |||
1 | import { VideoFile } from '../../../../shared/models/videos' | ||
2 | |||
3 | import 'videojs-hotkeys' | ||
4 | import 'videojs-dock/dist/videojs-dock.es.js' | ||
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 | }) { | ||
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 | |||
54 | function 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 | |||
96 | export { getVideojsOptions } | ||