]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/standalone/videos/embed.ts
Fix deleting a video with comments
[github/Chocobozzz/PeerTube.git] / client / src / standalone / videos / embed.ts
1 import './embed.scss'
2
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'
8
9 function loadVideoInfo (videoId: string, callback: (err: Error, res?: VideoDetails) => void) {
10 const xhttp = new XMLHttpRequest()
11 xhttp.onreadystatechange = function () {
12 if (this.readyState === 4 && this.status === 200) {
13 const json = JSON.parse(this.responseText)
14 return callback(null, json)
15 }
16 }
17
18 xhttp.onerror = err => callback(err.error)
19
20 const url = window.location.origin + '/api/v1/videos/' + videoId
21 xhttp.open('GET', url, true)
22 xhttp.send()
23 }
24
25 const urlParts = window.location.href.split('/')
26 const videoId = urlParts[urlParts.length - 1]
27
28 loadVideoInfo(videoId, (err, videoInfo) => {
29 if (err) {
30 console.error(err)
31 return
32 }
33
34 const videoElement = document.getElementById('video-container') as HTMLVideoElement
35 const previewUrl = window.location.origin + videoInfo.previewPath
36 videoElement.poster = previewUrl
37
38 const videojsOptions = {
39 controls: true,
40 autoplay: false,
41 plugins: {
42 peertube: {
43 videoFiles: videoInfo.files,
44 playerElement: videoElement,
45 peerTubeLink: true
46 },
47 hotkeys: {
48 enableVolumeScroll: false
49 }
50 }
51 }
52 videojs('video-container', videojsOptions, function () {
53 const player = this
54
55 player.dock({
56 title: videoInfo.name
57 })
58 })
59 })