]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/standalone/videos/embed.ts
Fix homagepage redirection
[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 9function getVideoUrl (id: string) {
7b0956ec 10 return window.location.origin + '/api/v1/videos/' + id
8cac1b64
C
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 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 46 player.dock({
22b59e80
C
47 title: videoInfo.name,
48 description: 'Use P2P, other may know you are watching that video.'
f2f1118f 49 })
202e7223 50 })
202e7223 51 })
a16aee73 52 .catch(err => console.error(err))