aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/standalone
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-16 19:15:20 +0200
committerChocobozzz <me@florianbigard.com>2018-07-16 19:15:20 +0200
commit6d88de725321e77486788f64a2e2537f5e6ef0cd (patch)
treee91a165da9a434c6855f7b39663ee2d1e888909b /client/src/standalone
parent30eac84e71eeb99e70861e5ab75c60fd39dac03c (diff)
downloadPeerTube-6d88de725321e77486788f64a2e2537f5e6ef0cd.tar.gz
PeerTube-6d88de725321e77486788f64a2e2537f5e6ef0cd.tar.zst
PeerTube-6d88de725321e77486788f64a2e2537f5e6ef0cd.zip
Correctly handle error when remote instance is down
Diffstat (limited to 'client/src/standalone')
-rw-r--r--client/src/standalone/videos/embed.scss1
-rw-r--r--client/src/standalone/videos/embed.ts26
2 files changed, 18 insertions, 9 deletions
diff --git a/client/src/standalone/videos/embed.scss b/client/src/standalone/videos/embed.scss
index f92a1f54a..30650538f 100644
--- a/client/src/standalone/videos/embed.scss
+++ b/client/src/standalone/videos/embed.scss
@@ -63,7 +63,6 @@ html, body {
63 align-content: center; 63 align-content: center;
64 justify-content: center; 64 justify-content: center;
65 text-align: center; 65 text-align: center;
66 background-color: #141313;
67 width: 100%; 66 width: 100%;
68 height: 100%; 67 height: 100%;
69 color: white; 68 color: white;
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts
index b2809467d..cb05ec2b5 100644
--- a/client/src/standalone/videos/embed.ts
+++ b/client/src/standalone/videos/embed.ts
@@ -188,9 +188,9 @@ class PeerTubeEmbed {
188 element.parentElement.removeChild(element) 188 element.parentElement.removeChild(element)
189 } 189 }
190 190
191 displayError (videoElement: HTMLVideoElement, text: string) { 191 displayError (text: string) {
192 // Remove video element 192 // Remove video element
193 this.removeElement(videoElement) 193 if (this.videoElement) this.removeElement(this.videoElement)
194 194
195 document.title = 'Sorry - ' + text 195 document.title = 'Sorry - ' + text
196 196
@@ -201,14 +201,14 @@ class PeerTubeEmbed {
201 errorText.innerHTML = text 201 errorText.innerHTML = text
202 } 202 }
203 203
204 videoNotFound (videoElement: HTMLVideoElement) { 204 videoNotFound () {
205 const text = 'This video does not exist.' 205 const text = 'This video does not exist.'
206 this.displayError(videoElement, text) 206 this.displayError(text)
207 } 207 }
208 208
209 videoFetchError (videoElement: HTMLVideoElement) { 209 videoFetchError () {
210 const text = 'We cannot fetch the video. Please try again later.' 210 const text = 'We cannot fetch the video. Please try again later.'
211 this.displayError(videoElement, text) 211 this.displayError(text)
212 } 212 }
213 213
214 getParamToggle (params: URLSearchParams, name: string, defaultValue: boolean) { 214 getParamToggle (params: URLSearchParams, name: string, defaultValue: boolean) {
@@ -264,9 +264,9 @@ class PeerTubeEmbed {
264 ]) 264 ])
265 265
266 if (!videoResponse.ok) { 266 if (!videoResponse.ok) {
267 if (videoResponse.status === 404) return this.videoNotFound(this.videoElement) 267 if (videoResponse.status === 404) return this.videoNotFound()
268 268
269 return this.videoFetchError(this.videoElement) 269 return this.videoFetchError()
270 } 270 }
271 271
272 const videoInfo: VideoDetails = await videoResponse.json() 272 const videoInfo: VideoDetails = await videoResponse.json()
@@ -303,6 +303,7 @@ class PeerTubeEmbed {
303 303
304 this.playerOptions = videojsOptions 304 this.playerOptions = videojsOptions
305 this.player = vjs(this.videoContainerId, videojsOptions, () => { 305 this.player = vjs(this.videoContainerId, videojsOptions, () => {
306 this.player.on('customError', (event, data) => this.handleError(data.err))
306 307
307 window[ 'videojsPlayer' ] = this.player 308 window[ 'videojsPlayer' ] = this.player
308 309
@@ -318,6 +319,15 @@ class PeerTubeEmbed {
318 this.initializeApi() 319 this.initializeApi()
319 }) 320 })
320 } 321 }
322
323 private handleError (err: Error) {
324 if (err.message.indexOf('http error') !== -1) {
325 this.player.dispose()
326 this.videoElement = null
327 this.displayError('This video is not available because the remote instance is not responding.')
328 return
329 }
330 }
321} 331}
322 332
323PeerTubeEmbed.main() 333PeerTubeEmbed.main()