3 import * as videojs from 'video.js'
4 import 'videojs-hotkeys'
5 import '../../assets/player/peertube-videojs-plugin'
6 import 'videojs-dock/dist/videojs-dock.es.js'
7 import { VideoDetails } from '../../../../shared'
9 function getVideoUrl (id: string) {
10 return window.location.origin + '/api/v1/videos/' + id
13 async function loadVideoInfo (videoId: string): Promise<VideoDetails> {
14 const response = await fetch(getVideoUrl(videoId))
15 return response.json()
18 const urlParts = window.location.href.split('/')
19 const videoId = urlParts[urlParts.length - 1]
21 loadVideoInfo(videoId)
23 const videoElement = document.getElementById('video-container') as HTMLVideoElement
24 const previewUrl = window.location.origin + videoInfo.previewPath
25 videoElement.poster = previewUrl
30 let params = new URL(window.location.toString()).searchParams
31 autoplay = params.has('autoplay') && (params.get('autoplay') === '1' || params.get('autoplay') === 'true')
33 console.error('Cannot get params from URL.', err)
36 const videojsOptions = {
39 inactivityTimeout: 500,
42 videoFiles: videoInfo.files,
43 playerElement: videoElement,
44 videoViewUrl: getVideoUrl(videoId) + '/views',
45 videoDuration: videoInfo.duration
48 enableVolumeScroll: false
59 'flexibleWidthSpacer',
67 'resolutionMenuButton',
74 videojs('video-container', videojsOptions, function () {
78 title: videoInfo.name,
79 description: 'Uses P2P, others may know you are watching this video.'
83 .catch(err => console.error(err))