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 { videojsUntyped } from './peertube-videojs-typings'
14 import { buildVideoEmbed, buildVideoLink, copyToClipboard } from './utils'
15 import { getCompleteLocale, getShortLocale, is18nLocale, isDefaultLocale } from '../../../../shared/models/i18n/i18n'
17 // Change 'Playback Rate' to 'Speed' (smaller for our settings menu)
18 videojsUntyped.getComponent('PlaybackRateMenuButton').prototype.controlText_ = 'Speed'
20 function getVideojsOptions (options: {
22 playerElement: HTMLVideoElement,
24 videoDuration: number,
25 videoFiles: VideoFile[],
26 enableHotkeys: boolean,
27 inactivityTimeout: number,
28 peertubeLink: boolean,
32 const videojsOptions = {
34 poster: options.poster,
36 inactivityTimeout: options.inactivityTimeout,
37 playbackRates: [ 0.5, 1, 1.5, 2 ],
40 autoplay: options.autoplay, // Use peertube plugin autoplay because we get the file by webtorrent
41 videoFiles: options.videoFiles,
42 playerElement: options.playerElement,
43 videoViewUrl: options.videoViewUrl,
44 videoDuration: options.videoDuration,
45 startTime: options.startTime
49 children: getControlBarChildren(options)
53 if (options.enableHotkeys === true) {
54 Object.assign(videojsOptions.plugins, {
56 enableVolumeScroll: false
64 function getControlBarChildren (options: {
69 'currentTimeDisplay': {},
71 'durationDisplay': {},
74 'flexibleWidthSpacer': {},
79 'peerTubeLoadProgressBar': {},
86 'webTorrentButton': {},
96 'resolutionMenuButton',
97 'playbackRateMenuButton'
102 if (options.peertubeLink === true) {
103 Object.assign(children, {
104 'peerTubeLinkButton': {}
108 Object.assign(children, {
109 'fullscreenToggle': {}
115 function addContextMenu (player: any, videoEmbedUrl: string) {
116 player.contextmenuUI({
119 label: player.localize('Copy the video URL'),
120 listener: function () {
121 copyToClipboard(buildVideoLink())
125 label: player.localize('Copy the video URL at the current time'),
126 listener: function () {
128 copyToClipboard(buildVideoLink(player.currentTime()))
132 label: player.localize('Copy embed code'),
134 copyToClipboard(buildVideoEmbed(videoEmbedUrl))
141 function loadLocale (serverUrl: string, videojs: any, locale: string) {
142 const completeLocale = getCompleteLocale(locale)
144 if (!is18nLocale(completeLocale) || isDefaultLocale(completeLocale)) return Promise.resolve(undefined)
146 return fetch(serverUrl + '/client/locales/' + completeLocale + '/player.json')
147 .then(res => res.json())
148 .then(json => videojs.addLanguage(getShortLocale(completeLocale), json))