diff options
Diffstat (limited to 'client/src/assets/player')
9 files changed, 115 insertions, 17 deletions
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 { | |||
129 | saveAverageBandwidth(data.bandwidthEstimate) | 129 | saveAverageBandwidth(data.bandwidthEstimate) |
130 | }) | 130 | }) |
131 | 131 | ||
132 | const offlineNotificationElem = document.createElement('div') | ||
133 | offlineNotificationElem.classList.add('vjs-peertube-offline-notification') | ||
134 | offlineNotificationElem.innerText = player.localize('You seem to be offline and the video may not work') | ||
135 | |||
136 | const handleOnline = () => { | ||
137 | player.el().removeChild(offlineNotificationElem) | ||
138 | logger.info('The browser is online') | ||
139 | } | ||
140 | |||
141 | const handleOffline = () => { | ||
142 | player.el().appendChild(offlineNotificationElem) | ||
143 | logger.info('The browser is offline') | ||
144 | } | ||
145 | |||
146 | window.addEventListener('online', handleOnline) | ||
147 | window.addEventListener('offline', handleOffline) | ||
148 | |||
149 | player.on('dispose', () => { | ||
150 | window.removeEventListener('online', handleOnline) | ||
151 | window.removeEventListener('offline', handleOffline) | ||
152 | }) | ||
153 | |||
132 | return res(player) | 154 | return res(player) |
133 | }) | 155 | }) |
134 | }) | 156 | }) |
diff --git a/client/src/assets/player/shared/manager-options/hls-options-builder.ts b/client/src/assets/player/shared/manager-options/hls-options-builder.ts index a572febc2..361c76f4b 100644 --- a/client/src/assets/player/shared/manager-options/hls-options-builder.ts +++ b/client/src/assets/player/shared/manager-options/hls-options-builder.ts | |||
@@ -19,12 +19,15 @@ export class HLSOptionsBuilder { | |||
19 | 19 | ||
20 | } | 20 | } |
21 | 21 | ||
22 | getPluginOptions () { | 22 | async getPluginOptions () { |
23 | const commonOptions = this.options.common | 23 | const commonOptions = this.options.common |
24 | 24 | ||
25 | const redundancyUrlManager = new RedundancyUrlManager(this.options.p2pMediaLoader.redundancyBaseUrls) | 25 | const redundancyUrlManager = new RedundancyUrlManager(this.options.p2pMediaLoader.redundancyBaseUrls) |
26 | 26 | ||
27 | const p2pMediaLoaderConfig = this.getP2PMediaLoaderOptions(redundancyUrlManager) | 27 | const p2pMediaLoaderConfig = await this.options.pluginsManager.runHook( |
28 | 'filter:internal.player.p2p-media-loader.options.result', | ||
29 | this.getP2PMediaLoaderOptions(redundancyUrlManager) | ||
30 | ) | ||
28 | const loader = new this.p2pMediaLoaderModule.Engine(p2pMediaLoaderConfig).createLoaderClass() as P2PMediaLoader | 31 | const loader = new this.p2pMediaLoaderModule.Engine(p2pMediaLoaderConfig).createLoaderClass() as P2PMediaLoader |
29 | 32 | ||
30 | const p2pMediaLoader: P2PMediaLoaderPluginOptions = { | 33 | const p2pMediaLoader: P2PMediaLoaderPluginOptions = { |
diff --git a/client/src/assets/player/shared/manager-options/manager-options-builder.ts b/client/src/assets/player/shared/manager-options/manager-options-builder.ts index 07678493d..2d96c9410 100644 --- a/client/src/assets/player/shared/manager-options/manager-options-builder.ts +++ b/client/src/assets/player/shared/manager-options/manager-options-builder.ts | |||
@@ -20,7 +20,7 @@ export class ManagerOptionsBuilder { | |||
20 | 20 | ||
21 | } | 21 | } |
22 | 22 | ||
23 | getVideojsOptions (alreadyPlayed: boolean): videojs.PlayerOptions { | 23 | async getVideojsOptions (alreadyPlayed: boolean): Promise<videojs.PlayerOptions> { |
24 | const commonOptions = this.options.common | 24 | const commonOptions = this.options.common |
25 | 25 | ||
26 | let autoplay = this.getAutoPlayValue(commonOptions.autoplay, alreadyPlayed) | 26 | let autoplay = this.getAutoPlayValue(commonOptions.autoplay, alreadyPlayed) |
@@ -61,7 +61,7 @@ export class ManagerOptionsBuilder { | |||
61 | 61 | ||
62 | if (this.mode === 'p2p-media-loader') { | 62 | if (this.mode === 'p2p-media-loader') { |
63 | const hlsOptionsBuilder = new HLSOptionsBuilder(this.options, this.p2pMediaLoaderModule) | 63 | const hlsOptionsBuilder = new HLSOptionsBuilder(this.options, this.p2pMediaLoaderModule) |
64 | const options = hlsOptionsBuilder.getPluginOptions() | 64 | const options = await hlsOptionsBuilder.getPluginOptions() |
65 | 65 | ||
66 | Object.assign(plugins, pick(options, [ 'hlsjs', 'p2pMediaLoader' ])) | 66 | Object.assign(plugins, pick(options, [ 'hlsjs', 'p2pMediaLoader' ])) |
67 | Object.assign(html5, options.html5) | 67 | Object.assign(html5, options.html5) |
diff --git a/client/src/assets/player/shared/p2p-media-loader/hls-plugin.ts b/client/src/assets/player/shared/p2p-media-loader/hls-plugin.ts index e49e5c694..a14beb347 100644 --- a/client/src/assets/player/shared/p2p-media-loader/hls-plugin.ts +++ b/client/src/assets/player/shared/p2p-media-loader/hls-plugin.ts | |||
@@ -211,6 +211,28 @@ class Html5Hlsjs { | |||
211 | } | 211 | } |
212 | } | 212 | } |
213 | 213 | ||
214 | private _getHumanErrorMsg (error: { message: string, code?: number }) { | ||
215 | switch (error.code) { | ||
216 | default: | ||
217 | return error.message | ||
218 | } | ||
219 | } | ||
220 | |||
221 | private _handleUnrecovarableError (error: any) { | ||
222 | if (this.hls.levels.filter(l => l.id > -1).length > 1) { | ||
223 | this._removeQuality(this.hls.loadLevel) | ||
224 | return | ||
225 | } | ||
226 | |||
227 | this.hls.destroy() | ||
228 | logger.info('bubbling error up to VIDEOJS') | ||
229 | this.tech.error = () => ({ | ||
230 | ...error, | ||
231 | message: this._getHumanErrorMsg(error) | ||
232 | }) | ||
233 | this.tech.trigger('error') | ||
234 | } | ||
235 | |||
214 | private _handleMediaError (error: any) { | 236 | private _handleMediaError (error: any) { |
215 | if (this.errorCounts[Hlsjs.ErrorTypes.MEDIA_ERROR] === 1) { | 237 | if (this.errorCounts[Hlsjs.ErrorTypes.MEDIA_ERROR] === 1) { |
216 | logger.info('trying to recover media error') | 238 | logger.info('trying to recover media error') |
@@ -226,14 +248,13 @@ class Html5Hlsjs { | |||
226 | } | 248 | } |
227 | 249 | ||
228 | if (this.errorCounts[Hlsjs.ErrorTypes.MEDIA_ERROR] > 2) { | 250 | if (this.errorCounts[Hlsjs.ErrorTypes.MEDIA_ERROR] > 2) { |
229 | logger.info('bubbling media error up to VIDEOJS') | 251 | this._handleUnrecovarableError(error) |
230 | this.hls.destroy() | ||
231 | this.tech.error = () => error | ||
232 | this.tech.trigger('error') | ||
233 | } | 252 | } |
234 | } | 253 | } |
235 | 254 | ||
236 | private _handleNetworkError (error: any) { | 255 | private _handleNetworkError (error: any) { |
256 | if (navigator.onLine === false) return | ||
257 | |||
237 | if (this.errorCounts[Hlsjs.ErrorTypes.NETWORK_ERROR] <= this.maxNetworkErrorRecovery) { | 258 | if (this.errorCounts[Hlsjs.ErrorTypes.NETWORK_ERROR] <= this.maxNetworkErrorRecovery) { |
238 | logger.info('trying to recover network error') | 259 | logger.info('trying to recover network error') |
239 | 260 | ||
@@ -248,10 +269,7 @@ class Html5Hlsjs { | |||
248 | return | 269 | return |
249 | } | 270 | } |
250 | 271 | ||
251 | logger.info('bubbling network error up to VIDEOJS') | 272 | this._handleUnrecovarableError(error) |
252 | this.hls.destroy() | ||
253 | this.tech.error = () => error | ||
254 | this.tech.trigger('error') | ||
255 | } | 273 | } |
256 | 274 | ||
257 | private _onError (_event: any, data: ErrorData) { | 275 | private _onError (_event: any, data: ErrorData) { |
@@ -273,10 +291,7 @@ class Html5Hlsjs { | |||
273 | error.code = 3 | 291 | error.code = 3 |
274 | this._handleMediaError(error) | 292 | this._handleMediaError(error) |
275 | } else if (data.fatal) { | 293 | } else if (data.fatal) { |
276 | this.hls.destroy() | 294 | this._handleUnrecovarableError(error) |
277 | logger.info('bubbling error up to VIDEOJS') | ||
278 | this.tech.error = () => error as any | ||
279 | this.tech.trigger('error') | ||
280 | } | 295 | } |
281 | } | 296 | } |
282 | 297 | ||
@@ -292,6 +307,12 @@ class Html5Hlsjs { | |||
292 | return '0' | 307 | return '0' |
293 | } | 308 | } |
294 | 309 | ||
310 | private _removeQuality (index: number) { | ||
311 | this.hls.removeLevel(index) | ||
312 | this.player.peertubeResolutions().remove(index) | ||
313 | this.hls.currentLevel = -1 | ||
314 | } | ||
315 | |||
295 | private _notifyVideoQualities () { | 316 | private _notifyVideoQualities () { |
296 | if (!this.metadata) return | 317 | if (!this.metadata) return |
297 | 318 | ||
diff --git a/client/src/assets/player/shared/p2p-media-loader/p2p-media-loader-plugin.ts b/client/src/assets/player/shared/p2p-media-loader/p2p-media-loader-plugin.ts index 56068e340..3c4482f2e 100644 --- a/client/src/assets/player/shared/p2p-media-loader/p2p-media-loader-plugin.ts +++ b/client/src/assets/player/shared/p2p-media-loader/p2p-media-loader-plugin.ts | |||
@@ -115,6 +115,8 @@ class P2pMediaLoaderPlugin extends Plugin { | |||
115 | this.p2pEngine = this.options.loader.getEngine() | 115 | this.p2pEngine = this.options.loader.getEngine() |
116 | 116 | ||
117 | this.p2pEngine.on(Events.SegmentError, (segment: Segment, err) => { | 117 | this.p2pEngine.on(Events.SegmentError, (segment: Segment, err) => { |
118 | if (navigator.onLine === false) return | ||
119 | |||
118 | logger.error(`Segment ${segment.id} error.`, err) | 120 | logger.error(`Segment ${segment.id} error.`, err) |
119 | 121 | ||
120 | this.options.redundancyUrlManager.removeBySegmentUrl(segment.requestUrl) | 122 | this.options.redundancyUrlManager.removeBySegmentUrl(segment.requestUrl) |
diff --git a/client/src/assets/player/shared/peertube/peertube-plugin.ts b/client/src/assets/player/shared/peertube/peertube-plugin.ts index 83c32415e..a5d712d70 100644 --- a/client/src/assets/player/shared/peertube/peertube-plugin.ts +++ b/client/src/assets/player/shared/peertube/peertube-plugin.ts | |||
@@ -125,6 +125,32 @@ class PeerTubePlugin extends Plugin { | |||
125 | } | 125 | } |
126 | 126 | ||
127 | displayFatalError () { | 127 | displayFatalError () { |
128 | this.player.loadingSpinner.hide() | ||
129 | |||
130 | const buildModal = (error: MediaError) => { | ||
131 | const localize = this.player.localize.bind(this.player) | ||
132 | |||
133 | const wrapper = document.createElement('div') | ||
134 | const header = document.createElement('h1') | ||
135 | header.innerText = localize('Failed to play video') | ||
136 | wrapper.appendChild(header) | ||
137 | const desc = document.createElement('div') | ||
138 | desc.innerText = localize('The video failed to play due to technical issues.') | ||
139 | wrapper.appendChild(desc) | ||
140 | const details = document.createElement('p') | ||
141 | details.classList.add('error-details') | ||
142 | details.innerText = error.message | ||
143 | wrapper.appendChild(details) | ||
144 | |||
145 | return wrapper | ||
146 | } | ||
147 | |||
148 | const modal = this.player.createModal(buildModal(this.player.error()), { | ||
149 | temporary: false, | ||
150 | uncloseable: true | ||
151 | }) | ||
152 | modal.addClass('vjs-custom-error-display') | ||
153 | |||
128 | this.player.addClass('vjs-error-display-enabled') | 154 | this.player.addClass('vjs-error-display-enabled') |
129 | } | 155 | } |
130 | 156 | ||
diff --git a/client/src/assets/player/shared/resolutions/peertube-resolutions-plugin.ts b/client/src/assets/player/shared/resolutions/peertube-resolutions-plugin.ts index e7899ac71..4fafd27b1 100644 --- a/client/src/assets/player/shared/resolutions/peertube-resolutions-plugin.ts +++ b/client/src/assets/player/shared/resolutions/peertube-resolutions-plugin.ts | |||
@@ -21,6 +21,11 @@ class PeerTubeResolutionsPlugin extends Plugin { | |||
21 | this.trigger('resolutionsAdded') | 21 | this.trigger('resolutionsAdded') |
22 | } | 22 | } |
23 | 23 | ||
24 | remove (resolutionIndex: number) { | ||
25 | this.resolutions = this.resolutions.filter(r => r.id !== resolutionIndex) | ||
26 | this.trigger('resolutionRemoved') | ||
27 | } | ||
28 | |||
24 | getResolutions () { | 29 | getResolutions () { |
25 | return this.resolutions | 30 | return this.resolutions |
26 | } | 31 | } |
diff --git a/client/src/assets/player/shared/settings/resolution-menu-button.ts b/client/src/assets/player/shared/settings/resolution-menu-button.ts index a0b349f67..672411c11 100644 --- a/client/src/assets/player/shared/settings/resolution-menu-button.ts +++ b/client/src/assets/player/shared/settings/resolution-menu-button.ts | |||
@@ -12,6 +12,7 @@ class ResolutionMenuButton extends MenuButton { | |||
12 | this.controlText('Quality') | 12 | this.controlText('Quality') |
13 | 13 | ||
14 | player.peertubeResolutions().on('resolutionsAdded', () => this.buildQualities()) | 14 | player.peertubeResolutions().on('resolutionsAdded', () => this.buildQualities()) |
15 | player.peertubeResolutions().on('resolutionRemoved', () => this.cleanupQualities()) | ||
15 | 16 | ||
16 | // For parent | 17 | // For parent |
17 | player.peertubeResolutions().on('resolutionChanged', () => { | 18 | player.peertubeResolutions().on('resolutionChanged', () => { |
@@ -82,6 +83,24 @@ class ResolutionMenuButton extends MenuButton { | |||
82 | 83 | ||
83 | this.trigger('menuChanged') | 84 | this.trigger('menuChanged') |
84 | } | 85 | } |
86 | |||
87 | private cleanupQualities () { | ||
88 | const resolutions = this.player().peertubeResolutions().getResolutions() | ||
89 | |||
90 | this.menu.children().forEach((children: ResolutionMenuItem) => { | ||
91 | if (children.resolutionId === undefined) { | ||
92 | return | ||
93 | } | ||
94 | |||
95 | if (resolutions.find(r => r.id === children.resolutionId)) { | ||
96 | return | ||
97 | } | ||
98 | |||
99 | this.menu.removeChild(children) | ||
100 | }) | ||
101 | |||
102 | this.trigger('menuChanged') | ||
103 | } | ||
85 | } | 104 | } |
86 | 105 | ||
87 | videojs.registerComponent('ResolutionMenuButton', ResolutionMenuButton) | 106 | videojs.registerComponent('ResolutionMenuButton', ResolutionMenuButton) |
diff --git a/client/src/assets/player/shared/settings/resolution-menu-item.ts b/client/src/assets/player/shared/settings/resolution-menu-item.ts index 678eb368b..c59b8b891 100644 --- a/client/src/assets/player/shared/settings/resolution-menu-item.ts +++ b/client/src/assets/player/shared/settings/resolution-menu-item.ts | |||
@@ -7,7 +7,7 @@ export interface ResolutionMenuItemOptions extends videojs.MenuItemOptions { | |||
7 | } | 7 | } |
8 | 8 | ||
9 | class ResolutionMenuItem extends MenuItem { | 9 | class ResolutionMenuItem extends MenuItem { |
10 | private readonly resolutionId: number | 10 | readonly resolutionId: number |
11 | private readonly label: string | 11 | private readonly label: string |
12 | 12 | ||
13 | private autoResolutionEnabled: boolean | 13 | private autoResolutionEnabled: boolean |