3 import * as videojs from 'video.js'
4 import '../../assets/player/peertube-videojs-plugin'
5 import 'videojs-dock/dist/videojs-dock.es.js'
6 import { VideoDetails } from '../../../../shared'
8 function loadVideoInfo (videoId: string, callback: (err: Error, res?: VideoDetails) => void) {
9 const xhttp = new XMLHttpRequest()
10 xhttp.onreadystatechange = function () {
11 if (this.readyState === 4 && this.status === 200) {
12 const json = JSON.parse(this.responseText)
13 return callback(null, json)
17 xhttp.onerror = err => callback(err.error)
19 const url = window.location.origin + '/api/v1/videos/' + videoId
20 xhttp.open('GET', url, true)
24 const urlParts = window.location.href.split('/')
25 const videoId = urlParts[urlParts.length - 1]
27 loadVideoInfo(videoId, (err, videoInfo) => {
33 const videoElement = document.getElementById('video-container') as HTMLVideoElement
34 const previewUrl = window.location.origin + videoInfo.previewPath
35 videoElement.poster = previewUrl
37 const videojsOptions = {
42 videoFiles: videoInfo.files,
43 playerElement: videoElement,
48 videojs('video-container', videojsOptions, function () {