From f2a16d93b476aff16d5353e4d44350298ec7e01c Mon Sep 17 00:00:00 2001 From: kontrollanten <6680299+kontrollanten@users.noreply.github.com> Date: Wed, 28 Sep 2022 11:52:23 +0200 Subject: Handle network issues in video player (#5138) * feat(client/player): handle network offline * feat(client/player): human friendly err msg * feat(client/player): handle broken resolutions When an error occurs for a resolution, remove the resolution and try with another resolution. * fix(client/player): prevent err handl when offline * fix(client/player): localize offline text --- .../src/assets/player/peertube-player-manager.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'client/src/assets/player/peertube-player-manager.ts') diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts index 0d4acc3d9..533ee1bb8 100644 --- a/client/src/assets/player/peertube-player-manager.ts +++ b/client/src/assets/player/peertube-player-manager.ts @@ -129,6 +129,28 @@ export class PeertubePlayerManager { saveAverageBandwidth(data.bandwidthEstimate) }) + const offlineNotificationElem = document.createElement('div') + offlineNotificationElem.classList.add('vjs-peertube-offline-notification') + offlineNotificationElem.innerText = player.localize('You seem to be offline and the video may not work') + + const handleOnline = () => { + player.el().removeChild(offlineNotificationElem) + logger.info('The browser is online') + } + + const handleOffline = () => { + player.el().appendChild(offlineNotificationElem) + logger.info('The browser is offline') + } + + window.addEventListener('online', handleOnline) + window.addEventListener('offline', handleOffline) + + player.on('dispose', () => { + window.removeEventListener('online', handleOnline) + window.removeEventListener('offline', handleOffline) + }) + return res(player) }) }) -- cgit v1.2.3