]>
Commit | Line | Data |
---|---|---|
202e7223 C |
1 | import './embed.scss' |
2 | ||
63c4db6d | 3 | import * as videojs from 'video.js' |
2ccaeeb3 | 4 | import 'videojs-hotkeys' |
aa8b6df4 | 5 | import '../../assets/player/peertube-videojs-plugin' |
202e7223 | 6 | import 'videojs-dock/dist/videojs-dock.es.js' |
404b54e1 | 7 | import { VideoDetails } from '../../../../shared' |
202e7223 | 8 | |
8cac1b64 | 9 | function getVideoUrl (id: string) { |
7b0956ec | 10 | return window.location.origin + '/api/v1/videos/' + id |
8cac1b64 C |
11 | } |
12 | ||
a16aee73 | 13 | async function loadVideoInfo (videoId: string): Promise<VideoDetails> { |
8cac1b64 | 14 | const response = await fetch(getVideoUrl(videoId)) |
a16aee73 | 15 | return response.json() |
202e7223 C |
16 | } |
17 | ||
202e7223 C |
18 | const urlParts = window.location.href.split('/') |
19 | const videoId = urlParts[urlParts.length - 1] | |
20 | ||
f2f1118f F |
21 | loadVideoInfo(videoId) |
22 | .then(videoInfo => { | |
23 | const videoElement = document.getElementById('video-container') as HTMLVideoElement | |
24 | const previewUrl = window.location.origin + videoInfo.previewPath | |
25 | videoElement.poster = previewUrl | |
26 | ||
27 | const videojsOptions = { | |
28 | controls: true, | |
29 | autoplay: false, | |
30 | plugins: { | |
31 | peertube: { | |
32 | videoFiles: videoInfo.files, | |
33 | playerElement: videoElement, | |
8cac1b64 | 34 | peerTubeLink: true, |
3bcfff7f C |
35 | videoViewUrl: getVideoUrl(videoId) + '/views', |
36 | videoDuration: videoInfo.duration | |
f2f1118f F |
37 | }, |
38 | hotkeys: { | |
39 | enableVolumeScroll: false | |
40 | } | |
234b535d | 41 | } |
aa8b6df4 | 42 | } |
f2f1118f F |
43 | videojs('video-container', videojsOptions, function () { |
44 | const player = this | |
202e7223 | 45 | |
f2f1118f F |
46 | player.dock({ |
47 | title: videoInfo.name | |
48 | }) | |
202e7223 | 49 | }) |
202e7223 | 50 | }) |
a16aee73 | 51 | .catch(err => console.error(err)) |