aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/standalone/videos/embed.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-19 18:06:59 +0200
committerChocobozzz <me@florianbigard.com>2018-04-19 18:06:59 +0200
commitd4f3fea659163749f9ea879a5e1dd313106353c6 (patch)
tree354cc82693d16cdbd2c033e99109a49470ef565a /client/src/standalone/videos/embed.ts
parent76434ec8e3877a62eae5bb1c26a26d2a2d619a51 (diff)
downloadPeerTube-d4f3fea659163749f9ea879a5e1dd313106353c6.tar.gz
PeerTube-d4f3fea659163749f9ea879a5e1dd313106353c6.tar.zst
PeerTube-d4f3fea659163749f9ea879a5e1dd313106353c6.zip
Handle errors in embed
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