Skip to content

Commit

Permalink
feat(client/player): handle network offline
Browse files Browse the repository at this point in the history
  • Loading branch information
kontrollanten committed Jul 21, 2022
1 parent 7fd28c9 commit 142d36a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions client/src/assets/player/peertube-player-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,28 @@ export class PeertubePlayerManager {
saveAverageBandwidth(data.bandwidthEstimate)
})

const offlineNotificationElem = document.createElement('div')
offlineNotificationElem.classList.add('vjs-peertube-offline-notification')
offlineNotificationElem.innerText = '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)
})
})
Expand Down
1 change: 1 addition & 0 deletions client/src/sass/player/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
@use './bezels';
@use './playlist';
@use './stats';
@use './offline-notification';
22 changes: 22 additions & 0 deletions client/src/sass/player/offline-notification.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$height: 40px;

.vjs-peertube-offline-notification {
position: absolute;
top: 0;
left: 0;
right: 0;
height: $height;
color: #000;
background-color: var(--mainColorLightest);
text-align: center;
z-index: 1;
display: flex;
justify-content: center;
align-items: center;
}

.vjs-modal-dialog
.vjs-modal-dialog-content,
.video-js .vjs-modal-dialog {
top: $height;
}

0 comments on commit 142d36a

Please sign in to comment.