class PeerTubePlugin extends Plugin {
private readonly videoViewUrl: string
- private readonly authorizationHeader: string
+ private readonly authorizationHeader: () => string
private readonly videoUUID: string
private readonly startTime: number
this.videoCaptions = options.videoCaptions
this.initialInactivityTimeout = this.player.options_.inactivityTimeout
- if (options.autoplay) this.player.addClass('vjs-has-autoplay')
+ if (options.autoplay !== false) this.player.addClass('vjs-has-autoplay')
this.player.on('autoplay-failure', () => {
this.player.removeClass('vjs-has-autoplay')
}
displayFatalError () {
+ this.player.loadingSpinner.hide()
+
+ const buildModal = (error: MediaError) => {
+ const localize = this.player.localize.bind(this.player)
+
+ const wrapper = document.createElement('div')
+ const header = document.createElement('h1')
+ header.innerText = localize('Failed to play video')
+ wrapper.appendChild(header)
+ const desc = document.createElement('div')
+ desc.innerText = localize('The video failed to play due to technical issues.')
+ wrapper.appendChild(desc)
+ const details = document.createElement('p')
+ details.classList.add('error-details')
+ details.innerText = error.message
+ wrapper.appendChild(details)
+
+ return wrapper
+ }
+
+ const modal = this.player.createModal(buildModal(this.player.error()), {
+ temporary: false,
+ uncloseable: true
+ })
+ modal.addClass('vjs-custom-error-display')
+
this.player.addClass('vjs-error-display-enabled')
}
lastViewEvent = undefined
// Server won't save history, so save the video position in local storage
- if (!this.authorizationHeader) {
+ if (!this.authorizationHeader()) {
saveVideoWatchHistory(this.videoUUID, currentTime)
}
}, this.CONSTANTS.USER_VIEW_VIDEO_INTERVAL)
'Content-type': 'application/json; charset=UTF-8'
})
- if (this.authorizationHeader) headers.set('Authorization', this.authorizationHeader)
+ if (this.authorizationHeader()) headers.set('Authorization', this.authorizationHeader())
return fetch(this.videoViewUrl, { method: 'POST', body: JSON.stringify(body), headers })
}