self.player = this
})
- this.errorsSub = this.webTorrentService.errors.subscribe(err => {
- const message = typeof err === 'string' ? err : err.message
- this.notificationsService.error('Error', message)
- })
+ this.errorsSub = this.webTorrentService.errors.subscribe(err => this.handleError(err))
}
ngOnDestroy () {
window.clearInterval(this.torrentInfosInterval)
window.clearTimeout(this.errorTimer)
- if (this.video !== null && this.webTorrentService.has(this.video.magnetUri)) {
- this.webTorrentService.remove(this.video.magnetUri)
+ if (this.video !== null && this.webTorrentService.has(this.video.getDefaultMagnetUri())) {
+ this.webTorrentService.remove(this.video.getDefaultMagnetUri())
}
// Remove player
// We are loading the video
this.loading = true
- console.log('Adding ' + this.video.magnetUri + '.')
+ console.log('Adding ' + this.video.getDefaultMagnetUri() + '.')
// The callback might never return if there are network issues
// So we create a timer to inform the user the load is abnormally long
this.errorTimer = window.setTimeout(() => this.loadTooLong(), VideoWatchComponent.LOADTIME_TOO_LONG)
- this.webTorrentService.add(this.video.magnetUri, torrent => {
+ const torrent = this.webTorrentService.add(this.video.getDefaultMagnetUri(), torrent => {
// Clear the error timer
window.clearTimeout(this.errorTimer)
// Maybe the error was fired by the timer, so reset it
// We are not loading the video anymore
this.loading = false
- console.log('Added ' + this.video.magnetUri + '.')
+ console.log('Added ' + this.video.getDefaultMagnetUri() + '.')
torrent.files[0].renderTo(this.playerElement, (err) => {
if (err) {
this.notificationsService.error('Error', 'Cannot append the file in the video element.')
this.runInProgress(torrent)
})
+
+ torrent.on('error', err => this.handleError(err))
+ torrent.on('warning', err => this.handleError(err))
}
setLike () {
this.userRating = 'like'
},
- err => this.notificationsService.error('Error', err.text)
+ err => this.notificationsService.error('Error', err.message)
)
}
this.userRating = 'dislike'
},
- err => this.notificationsService.error('Error', err.text)
+ err => this.notificationsService.error('Error', err.message)
)
}
return this.video.isBlackistableBy(this.authService.getUser())
}
+ private handleError (err: any) {
+ const errorMessage: string = typeof err === 'string' ? err : err.message
+ let message = ''
+
+ if (errorMessage.indexOf('http error') !== -1) {
+ message = 'Cannot fetch video from server, maybe down.'
+ } else {
+ message = errorMessage
+ }
+
+ this.notificationsService.error('Error', message)
+ }
+
private checkUserRating () {
// Unlogged users do not have ratings
if (this.isUserLoggedIn() === false) return
}
},
- err => this.notificationsService.error('Error', err.text)
+ err => this.notificationsService.error('Error', err.message)
)
}