3 import * as videojs from 'video.js'
5 import { VideoDetails } from '../../../../shared'
6 import { getVideojsOptions } from '../../assets/player/peertube-player'
8 function getVideoUrl (id: string) {
9 return window.location.origin + '/api/v1/videos/' + id
12 async function loadVideoInfo (videoId: string): Promise<VideoDetails> {
13 const response = await fetch(getVideoUrl(videoId))
14 return response.json()
17 const urlParts = window.location.href.split('/')
18 const videoId = urlParts[urlParts.length - 1]
20 loadVideoInfo(videoId)
22 const videoContainerId = 'video-container'
24 const videoElement = document.getElementById(videoContainerId) as HTMLVideoElement
28 let params = new URL(window.location.toString()).searchParams
29 autoplay = params.has('autoplay') && (params.get('autoplay') === '1' || params.get('autoplay') === 'true')
31 console.error('Cannot get params from URL.', err)
34 const videojsOptions = getVideojsOptions({
36 inactivityTimeout: 1500,
37 videoViewUrl: getVideoUrl(videoId) + '/views',
38 playerElement: videoElement,
39 videoFiles: videoInfo.files,
40 videoDuration: videoInfo.duration,
43 poster: window.location.origin + videoInfo.previewPath
45 videojs(videoContainerId, videojsOptions, function () {
49 title: videoInfo.name,
50 description: 'Uses P2P, others may know you are watching this video.'
54 .catch(err => console.error(err))