]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/standalone/videos/embed.ts
Fix typo in embed
[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,
3bcfff7f
C
34 videoViewUrl: getVideoUrl(videoId) + '/views',
35 videoDuration: videoInfo.duration
f2f1118f
F
36 },
37 hotkeys: {
38 enableVolumeScroll: false
39 }
3ec8dc09
C
40 },
41 controlBar: {
42 children: [
43 'playToggle',
44 'currentTimeDisplay',
45 'timeDivider',
46 'durationDisplay',
47 'liveDisplay',
48
49 'flexibleWidthSpacer',
50 'progressControl',
51
52 'webTorrentButton',
53
54 'muteToggle',
55 'volumeControl',
56
57 'resolutionMenuButton',
58 'peerTubeLinkButton',
59
60 'fullscreenToggle'
61 ]
234b535d 62 }
aa8b6df4 63 }
f2f1118f
F
64 videojs('video-container', videojsOptions, function () {
65 const player = this
202e7223 66
f2f1118f 67 player.dock({
22b59e80 68 title: videoInfo.name,
606ca5bc 69 description: 'Uses P2P, others may know you are watching this video.'
f2f1118f 70 })
202e7223 71 })
202e7223 72 })
a16aee73 73 .catch(err => console.error(err))