aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/standalone/videos/embed.ts
diff options
context:
space:
mode:
authorGérald Niel <gerald.niel@gegeweb.org>2018-04-19 19:28:55 +0200
committerGérald Niel <gerald.niel@gegeweb.org>2018-04-19 19:28:55 +0200
commit0db1a226507a39b0a663e3e63f04851836a44d5a (patch)
tree8c8dad658ea5608afaae238cfb6fe803292f908f /client/src/standalone/videos/embed.ts
parent0030284b0df2983914291d6fe83675e2aa892e6a (diff)
parentd4f3fea659163749f9ea879a5e1dd313106353c6 (diff)
downloadPeerTube-0db1a226507a39b0a663e3e63f04851836a44d5a.tar.gz
PeerTube-0db1a226507a39b0a663e3e63f04851836a44d5a.tar.zst
PeerTube-0db1a226507a39b0a663e3e63f04851836a44d5a.zip
Merge branch 'develop' of framagit.org:chocobozzz/PeerTube into develop
Diffstat (limited to 'client/src/standalone/videos/embed.ts')
-rw-r--r--client/src/standalone/videos/embed.ts44
1 files changed, 39 insertions, 5 deletions
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts
index a99bc586f..aa418d2d4 100644
--- a/client/src/standalone/videos/embed.ts
+++ b/client/src/standalone/videos/embed.ts
@@ -9,19 +9,53 @@ function getVideoUrl (id: string) {
9 return window.location.origin + '/api/v1/videos/' + id 9 return window.location.origin + '/api/v1/videos/' + id
10} 10}
11 11
12async function loadVideoInfo (videoId: string): Promise<VideoDetails> { 12function loadVideoInfo (videoId: string): Promise<Response> {
13 const response = await fetch(getVideoUrl(videoId)) 13 return fetch(getVideoUrl(videoId))
14 return response.json() 14}
15
16function removeElement (element: HTMLElement) {
17 element.parentElement.removeChild(element)
18}
19
20function displayError (videoElement: HTMLVideoElement, text: string) {
21 // Remove video element
22 removeElement(videoElement)
23
24 document.title = 'Sorry - ' + text
25
26 const errorBlock = document.getElementById('error-block')
27 errorBlock.style.display = 'flex'
28
29 const errorText = document.getElementById('error-content')
30 errorText.innerHTML = text
31}
32
33function videoNotFound (videoElement: HTMLVideoElement) {
34 const text = 'This video does not exist.'
35 displayError(videoElement, text)
36}
37
38function videoFetchError (videoElement: HTMLVideoElement) {
39 const text = 'We cannot fetch the video. Please try again later.'
40 displayError(videoElement, text)
15} 41}
16 42
17const urlParts = window.location.href.split('/') 43const urlParts = window.location.href.split('/')
18const videoId = urlParts[urlParts.length - 1] 44const videoId = urlParts[urlParts.length - 1]
19 45
20loadVideoInfo(videoId) 46loadVideoInfo(videoId)
21 .then(videoInfo => { 47 .then(async response => {
22 const videoContainerId = 'video-container' 48 const videoContainerId = 'video-container'
23
24 const videoElement = document.getElementById(videoContainerId) as HTMLVideoElement 49 const videoElement = document.getElementById(videoContainerId) as HTMLVideoElement
50
51 if (!response.ok) {
52 if (response.status === 404) return videoNotFound(videoElement)
53
54 return videoFetchError(videoElement)
55 }
56
57 const videoInfo: VideoDetails = await response.json()
58
25 let autoplay = false 59 let autoplay = false
26 let startTime = 0 60 let startTime = 0
27 61