element.parentElement.removeChild(element)
}
- displayError (videoElement: HTMLVideoElement, text: string) {
+ displayError (text: string) {
// Remove video element
- this.removeElement(videoElement)
+ if (this.videoElement) this.removeElement(this.videoElement)
document.title = 'Sorry - ' + text
errorText.innerHTML = text
}
- videoNotFound (videoElement: HTMLVideoElement) {
+ videoNotFound () {
const text = 'This video does not exist.'
- this.displayError(videoElement, text)
+ this.displayError(text)
}
- videoFetchError (videoElement: HTMLVideoElement) {
+ videoFetchError () {
const text = 'We cannot fetch the video. Please try again later.'
- this.displayError(videoElement, text)
+ this.displayError(text)
}
getParamToggle (params: URLSearchParams, name: string, defaultValue: boolean) {
])
if (!videoResponse.ok) {
- if (videoResponse.status === 404) return this.videoNotFound(this.videoElement)
+ if (videoResponse.status === 404) return this.videoNotFound()
- return this.videoFetchError(this.videoElement)
+ return this.videoFetchError()
}
const videoInfo: VideoDetails = await videoResponse.json()
this.playerOptions = videojsOptions
this.player = vjs(this.videoContainerId, videojsOptions, () => {
+ this.player.on('customError', (event, data) => this.handleError(data.err))
window[ 'videojsPlayer' ] = this.player
this.initializeApi()
})
}
+
+ private handleError (err: Error) {
+ if (err.message.indexOf('http error') !== -1) {
+ this.player.dispose()
+ this.videoElement = null
+ this.displayError('This video is not available because the remote instance is not responding.')
+ return
+ }
+ }
}
PeerTubeEmbed.main()