]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/standalone/videos/embed.ts
Move adding a video view videojs peertube plugin
[github/Chocobozzz/PeerTube.git] / client / src / standalone / videos / embed.ts
CommitLineData
202e7223
C
1import './embed.scss'
2
63c4db6d 3import * as videojs from 'video.js'
2ccaeeb3 4import 'videojs-hotkeys'
aa8b6df4 5import '../../assets/player/peertube-videojs-plugin'
202e7223 6import 'videojs-dock/dist/videojs-dock.es.js'
404b54e1 7import { VideoDetails } from '../../../../shared'
202e7223 8
8cac1b64
C
9function getVideoUrl (id: string) {
10 return window.location.origin + '/api/v1/videos/' + videoId
11}
12
a16aee73 13async 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
18const urlParts = window.location.href.split('/')
19const videoId = urlParts[urlParts.length - 1]
20
f2f1118f
F
21loadVideoInfo(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
C
34 peerTubeLink: true,
35 videoViewUrl: getVideoUrl(videoId) + '/views'
f2f1118f
F
36 },
37 hotkeys: {
38 enableVolumeScroll: false
39 }
234b535d 40 }
aa8b6df4 41 }
f2f1118f
F
42 videojs('video-container', videojsOptions, function () {
43 const player = this
202e7223 44
f2f1118f
F
45 player.dock({
46 title: videoInfo.name
47 })
202e7223 48 })
202e7223 49 })
a16aee73 50 .catch(err => console.error(err))