]>
Commit | Line | Data |
---|---|---|
202e7223 C |
1 | import './embed.scss' |
2 | ||
63c4db6d | 3 | import * as videojs from 'video.js' |
aa8b6df4 | 4 | import '../../assets/player/peertube-videojs-plugin' |
202e7223 | 5 | import 'videojs-dock/dist/videojs-dock.es.js' |
404b54e1 | 6 | import { VideoDetails } from '../../../../shared' |
202e7223 | 7 | |
404b54e1 | 8 | function loadVideoInfo (videoId: string, callback: (err: Error, res?: VideoDetails) => void) { |
202e7223 C |
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) | |
14 | } | |
15 | } | |
16 | ||
17 | xhttp.onerror = err => callback(err.error) | |
18 | ||
19 | const url = window.location.origin + '/api/v1/videos/' + videoId | |
20 | xhttp.open('GET', url, true) | |
21 | xhttp.send() | |
22 | } | |
23 | ||
202e7223 C |
24 | const urlParts = window.location.href.split('/') |
25 | const videoId = urlParts[urlParts.length - 1] | |
26 | ||
aa8b6df4 | 27 | loadVideoInfo(videoId, (err, videoInfo) => { |
202e7223 C |
28 | if (err) { |
29 | console.error(err) | |
30 | return | |
31 | } | |
32 | ||
aa8b6df4 C |
33 | const videoElement = document.getElementById('video-container') as HTMLVideoElement |
34 | const previewUrl = window.location.origin + videoInfo.previewPath | |
35 | videoElement.poster = previewUrl | |
36 | ||
37 | const videojsOptions = { | |
38 | controls: true, | |
39 | autoplay: false, | |
40 | plugins: { | |
41 | peertube: { | |
42 | videoFiles: videoInfo.files, | |
43 | playerElement: videoElement, | |
aa8b6df4 | 44 | peerTubeLink: true |
d7701449 | 45 | }, |
234b535d C |
46 | hotkeys: { |
47 | enableVolumeScroll: false | |
48 | } | |
aa8b6df4 | 49 | } |
93e1258c | 50 | } |
aa8b6df4 | 51 | videojs('video-container', videojsOptions, function () { |
202e7223 C |
52 | const player = this |
53 | ||
202e7223 | 54 | player.dock({ |
aa8b6df4 | 55 | title: videoInfo.name |
202e7223 | 56 | }) |
202e7223 C |
57 | }) |
58 | }) |