1 import { VideoFile } from '../../../../shared/models/videos'
3 import 'videojs-hotkeys'
5 import 'videojs-contextmenu'
6 import 'videojs-contextmenu-ui'
7 import './peertube-link-button'
8 import './resolution-menu-button'
9 import './settings-menu-button'
10 import './webtorrent-info-button'
11 import './peertube-videojs-plugin'
12 import './peertube-load-progress-bar'
13 import './theater-button'
14 import { videojsUntyped } from './peertube-videojs-typings'
15 import { buildVideoEmbed, buildVideoLink, copyToClipboard } from './utils'
16 import { getCompleteLocale, getShortLocale, is18nLocale, isDefaultLocale } from '../../../../shared/models/i18n/i18n'
18 // Change 'Playback Rate' to 'Speed' (smaller for our settings menu)
19 videojsUntyped.getComponent('PlaybackRateMenuButton').prototype.controlText_ = 'Speed'
21 function getVideojsOptions (options: {
23 playerElement: HTMLVideoElement,
25 videoDuration: number,
26 videoFiles: VideoFile[],
27 enableHotkeys: boolean,
28 inactivityTimeout: number,
29 peertubeLink: boolean,
34 const videojsOptions = {
36 poster: options.poster,
38 inactivityTimeout: options.inactivityTimeout,
39 playbackRates: [ 0.5, 1, 1.5, 2 ],
42 autoplay: options.autoplay, // Use peertube plugin autoplay because we get the file by webtorrent
43 videoFiles: options.videoFiles,
44 playerElement: options.playerElement,
45 videoViewUrl: options.videoViewUrl,
46 videoDuration: options.videoDuration,
47 startTime: options.startTime
51 children: getControlBarChildren(options)
55 if (options.enableHotkeys === true) {
56 Object.assign(videojsOptions.plugins, {
58 enableVolumeScroll: false
66 function getControlBarChildren (options: {
72 'currentTimeDisplay': {},
74 'durationDisplay': {},
77 'flexibleWidthSpacer': {},
82 'peerTubeLoadProgressBar': {},
83 'mouseTimeDisplay': {},
90 'webTorrentButton': {},
100 'resolutionMenuButton',
101 'playbackRateMenuButton'
106 if (options.peertubeLink === true) {
107 Object.assign(children, {
108 'peerTubeLinkButton': {}
112 if (options.theaterMode === true) {
113 Object.assign(children, {
118 Object.assign(children, {
119 'fullscreenToggle': {}
125 function addContextMenu (player: any, videoEmbedUrl: string) {
126 player.contextmenuUI({
129 label: player.localize('Copy the video URL'),
130 listener: function () {
131 copyToClipboard(buildVideoLink())
135 label: player.localize('Copy the video URL at the current time'),
136 listener: function () {
138 copyToClipboard(buildVideoLink(player.currentTime()))
142 label: player.localize('Copy embed code'),
144 copyToClipboard(buildVideoEmbed(videoEmbedUrl))
148 label: player.localize('Copy magnet URI'),
149 listener: function () {
151 copyToClipboard(player.peertube().getCurrentVideoFile().magnetUri)
158 function loadLocale (serverUrl: string, videojs: any, locale: string) {
159 const completeLocale = getCompleteLocale(locale)
161 if (!is18nLocale(completeLocale) || isDefaultLocale(completeLocale)) return Promise.resolve(undefined)
163 return fetch(serverUrl + '/client/locales/' + completeLocale + '/player.json')
164 .then(res => res.json())
165 .then(json => videojs.addLanguage(getShortLocale(completeLocale), json))