diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-15 15:30:14 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-07-18 11:37:18 +0200 |
commit | 42b40636991b97fe818007fab19091764fc5db73 (patch) | |
tree | db431787c06ce898d22e91ff771f795219274fc6 /client/src/assets/player/shared/p2p-media-loader | |
parent | 654d4ede7fa4d0faa71e49bcfab6b65a686397b2 (diff) | |
download | PeerTube-42b40636991b97fe818007fab19091764fc5db73.tar.gz PeerTube-42b40636991b97fe818007fab19091764fc5db73.tar.zst PeerTube-42b40636991b97fe818007fab19091764fc5db73.zip |
Add ability for client to create server logs
Diffstat (limited to 'client/src/assets/player/shared/p2p-media-loader')
4 files changed, 24 insertions, 20 deletions
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 d0105fa36..e49e5c694 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 | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | import Hlsjs, { ErrorData, HlsConfig, Level, LevelSwitchingData, ManifestParsedData } from 'hls.js' | 4 | import Hlsjs, { ErrorData, HlsConfig, Level, LevelSwitchingData, ManifestParsedData } from 'hls.js' |
5 | import videojs from 'video.js' | 5 | import videojs from 'video.js' |
6 | import { logger } from '@root-helpers/logger' | ||
6 | import { HlsjsConfigHandlerOptions, PeerTubeResolution, VideoJSTechHLS } from '../../types' | 7 | import { HlsjsConfigHandlerOptions, PeerTubeResolution, VideoJSTechHLS } from '../../types' |
7 | 8 | ||
8 | type ErrorCounts = { | 9 | type ErrorCounts = { |
@@ -17,14 +18,14 @@ type HookFn = (player: videojs.Player, hljs: Hlsjs) => void | |||
17 | 18 | ||
18 | const registerSourceHandler = function (vjs: typeof videojs) { | 19 | const registerSourceHandler = function (vjs: typeof videojs) { |
19 | if (!Hlsjs.isSupported()) { | 20 | if (!Hlsjs.isSupported()) { |
20 | console.warn('Hls.js is not supported in this browser!') | 21 | logger.warn('Hls.js is not supported in this browser!') |
21 | return | 22 | return |
22 | } | 23 | } |
23 | 24 | ||
24 | const html5 = vjs.getTech('Html5') | 25 | const html5 = vjs.getTech('Html5') |
25 | 26 | ||
26 | if (!html5) { | 27 | if (!html5) { |
27 | console.error('No Hml5 tech found in videojs') | 28 | logger.error('No Hml5 tech found in videojs') |
28 | return | 29 | return |
29 | } | 30 | } |
30 | 31 | ||
@@ -120,7 +121,7 @@ class Html5Hlsjs { | |||
120 | 121 | ||
121 | if (!mediaError) return | 122 | if (!mediaError) return |
122 | 123 | ||
123 | console.log(mediaError) | 124 | logger.info(mediaError) |
124 | switch (mediaError.code) { | 125 | switch (mediaError.code) { |
125 | case mediaError.MEDIA_ERR_ABORTED: | 126 | case mediaError.MEDIA_ERR_ABORTED: |
126 | errorTxt = 'You aborted the video playback' | 127 | errorTxt = 'You aborted the video playback' |
@@ -141,7 +142,7 @@ class Html5Hlsjs { | |||
141 | errorTxt = mediaError.message | 142 | errorTxt = mediaError.message |
142 | } | 143 | } |
143 | 144 | ||
144 | console.error('MEDIA_ERROR: ', errorTxt) | 145 | logger.error(`MEDIA_ERROR: ${errorTxt}`) |
145 | }) | 146 | }) |
146 | 147 | ||
147 | this.initialize() | 148 | this.initialize() |
@@ -212,20 +213,20 @@ class Html5Hlsjs { | |||
212 | 213 | ||
213 | private _handleMediaError (error: any) { | 214 | private _handleMediaError (error: any) { |
214 | if (this.errorCounts[Hlsjs.ErrorTypes.MEDIA_ERROR] === 1) { | 215 | if (this.errorCounts[Hlsjs.ErrorTypes.MEDIA_ERROR] === 1) { |
215 | console.info('trying to recover media error') | 216 | logger.info('trying to recover media error') |
216 | this.hls.recoverMediaError() | 217 | this.hls.recoverMediaError() |
217 | return | 218 | return |
218 | } | 219 | } |
219 | 220 | ||
220 | if (this.errorCounts[Hlsjs.ErrorTypes.MEDIA_ERROR] === 2) { | 221 | if (this.errorCounts[Hlsjs.ErrorTypes.MEDIA_ERROR] === 2) { |
221 | console.info('2nd try to recover media error (by swapping audio codec') | 222 | logger.info('2nd try to recover media error (by swapping audio codec') |
222 | this.hls.swapAudioCodec() | 223 | this.hls.swapAudioCodec() |
223 | this.hls.recoverMediaError() | 224 | this.hls.recoverMediaError() |
224 | return | 225 | return |
225 | } | 226 | } |
226 | 227 | ||
227 | if (this.errorCounts[Hlsjs.ErrorTypes.MEDIA_ERROR] > 2) { | 228 | if (this.errorCounts[Hlsjs.ErrorTypes.MEDIA_ERROR] > 2) { |
228 | console.info('bubbling media error up to VIDEOJS') | 229 | logger.info('bubbling media error up to VIDEOJS') |
229 | this.hls.destroy() | 230 | this.hls.destroy() |
230 | this.tech.error = () => error | 231 | this.tech.error = () => error |
231 | this.tech.trigger('error') | 232 | this.tech.trigger('error') |
@@ -234,7 +235,7 @@ class Html5Hlsjs { | |||
234 | 235 | ||
235 | private _handleNetworkError (error: any) { | 236 | private _handleNetworkError (error: any) { |
236 | if (this.errorCounts[Hlsjs.ErrorTypes.NETWORK_ERROR] <= this.maxNetworkErrorRecovery) { | 237 | if (this.errorCounts[Hlsjs.ErrorTypes.NETWORK_ERROR] <= this.maxNetworkErrorRecovery) { |
237 | console.info('trying to recover network error') | 238 | logger.info('trying to recover network error') |
238 | 239 | ||
239 | // Wait 1 second and retry | 240 | // Wait 1 second and retry |
240 | setTimeout(() => this.hls.startLoad(), 1000) | 241 | setTimeout(() => this.hls.startLoad(), 1000) |
@@ -247,7 +248,7 @@ class Html5Hlsjs { | |||
247 | return | 248 | return |
248 | } | 249 | } |
249 | 250 | ||
250 | console.info('bubbling network error up to VIDEOJS') | 251 | logger.info('bubbling network error up to VIDEOJS') |
251 | this.hls.destroy() | 252 | this.hls.destroy() |
252 | this.tech.error = () => error | 253 | this.tech.error = () => error |
253 | this.tech.trigger('error') | 254 | this.tech.trigger('error') |
@@ -262,8 +263,8 @@ class Html5Hlsjs { | |||
262 | if (this.errorCounts[data.type]) this.errorCounts[data.type] += 1 | 263 | if (this.errorCounts[data.type]) this.errorCounts[data.type] += 1 |
263 | else this.errorCounts[data.type] = 1 | 264 | else this.errorCounts[data.type] = 1 |
264 | 265 | ||
265 | if (data.fatal) console.warn(error.message) | 266 | if (data.fatal) logger.warn(error.message) |
266 | else console.error(error.message, data) | 267 | else logger.error(error.message, { data }) |
267 | 268 | ||
268 | if (data.type === Hlsjs.ErrorTypes.NETWORK_ERROR) { | 269 | if (data.type === Hlsjs.ErrorTypes.NETWORK_ERROR) { |
269 | error.code = 2 | 270 | error.code = 2 |
@@ -273,7 +274,7 @@ class Html5Hlsjs { | |||
273 | this._handleMediaError(error) | 274 | this._handleMediaError(error) |
274 | } else if (data.fatal) { | 275 | } else if (data.fatal) { |
275 | this.hls.destroy() | 276 | this.hls.destroy() |
276 | console.info('bubbling error up to VIDEOJS') | 277 | logger.info('bubbling error up to VIDEOJS') |
277 | this.tech.error = () => error as any | 278 | this.tech.error = () => error as any |
278 | this.tech.trigger('error') | 279 | this.tech.trigger('error') |
279 | } | 280 | } |
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 5c0f0021f..e5f099dea 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 | |||
@@ -5,6 +5,7 @@ import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from '@peertub | |||
5 | import { timeToInt } from '@shared/core-utils' | 5 | import { timeToInt } from '@shared/core-utils' |
6 | import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../../types' | 6 | import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../../types' |
7 | import { registerConfigPlugin, registerSourceHandler } from './hls-plugin' | 7 | import { registerConfigPlugin, registerSourceHandler } from './hls-plugin' |
8 | import { logger } from '@root-helpers/logger' | ||
8 | 9 | ||
9 | registerConfigPlugin(videojs) | 10 | registerConfigPlugin(videojs) |
10 | registerSourceHandler(videojs) | 11 | registerSourceHandler(videojs) |
@@ -43,11 +44,11 @@ class P2pMediaLoaderPlugin extends Plugin { | |||
43 | 44 | ||
44 | // FIXME: typings https://github.com/Microsoft/TypeScript/issues/14080 | 45 | // FIXME: typings https://github.com/Microsoft/TypeScript/issues/14080 |
45 | if (!(videojs as any).Html5Hlsjs) { | 46 | if (!(videojs as any).Html5Hlsjs) { |
46 | console.warn('HLS.js does not seem to be supported. Try to fallback to built in HLS.') | 47 | logger.warn('HLS.js does not seem to be supported. Try to fallback to built in HLS.') |
47 | 48 | ||
48 | if (!player.canPlayType('application/vnd.apple.mpegurl')) { | 49 | if (!player.canPlayType('application/vnd.apple.mpegurl')) { |
49 | const message = 'Cannot fallback to built-in HLS' | 50 | const message = 'Cannot fallback to built-in HLS' |
50 | console.warn(message) | 51 | logger.warn(message) |
51 | 52 | ||
52 | player.ready(() => player.trigger('error', new Error(message))) | 53 | player.ready(() => player.trigger('error', new Error(message))) |
53 | return | 54 | return |
@@ -114,7 +115,7 @@ class P2pMediaLoaderPlugin extends Plugin { | |||
114 | this.p2pEngine = this.options.loader.getEngine() | 115 | this.p2pEngine = this.options.loader.getEngine() |
115 | 116 | ||
116 | this.p2pEngine.on(Events.SegmentError, (segment: Segment, err) => { | 117 | this.p2pEngine.on(Events.SegmentError, (segment: Segment, err) => { |
117 | console.error('Segment error.', segment, err) | 118 | logger.error(`Segment ${segment.id} error.`, err) |
118 | 119 | ||
119 | this.options.redundancyUrlManager.removeBySegmentUrl(segment.requestUrl) | 120 | this.options.redundancyUrlManager.removeBySegmentUrl(segment.requestUrl) |
120 | }) | 121 | }) |
diff --git a/client/src/assets/player/shared/p2p-media-loader/redundancy-url-manager.ts b/client/src/assets/player/shared/p2p-media-loader/redundancy-url-manager.ts index abab8aa99..376efb835 100644 --- a/client/src/assets/player/shared/p2p-media-loader/redundancy-url-manager.ts +++ b/client/src/assets/player/shared/p2p-media-loader/redundancy-url-manager.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { basename, dirname } from 'path' | 1 | import { basename, dirname } from 'path' |
2 | import { logger } from '@root-helpers/logger' | ||
2 | 3 | ||
3 | class RedundancyUrlManager { | 4 | class RedundancyUrlManager { |
4 | 5 | ||
@@ -7,7 +8,7 @@ class RedundancyUrlManager { | |||
7 | } | 8 | } |
8 | 9 | ||
9 | removeBySegmentUrl (segmentUrl: string) { | 10 | removeBySegmentUrl (segmentUrl: string) { |
10 | console.log('Removing redundancy of segment URL %s.', segmentUrl) | 11 | logger.info(`Removing redundancy of segment URL ${segmentUrl}.`) |
11 | 12 | ||
12 | const baseUrl = dirname(segmentUrl) | 13 | const baseUrl = dirname(segmentUrl) |
13 | 14 | ||
diff --git a/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts b/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts index f7f83a8a4..18cb6750f 100644 --- a/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts +++ b/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { wait } from '@root-helpers/utils' | ||
2 | import { Segment } from '@peertube/p2p-media-loader-core' | ||
3 | import { basename } from 'path' | 1 | import { basename } from 'path' |
2 | import { Segment } from '@peertube/p2p-media-loader-core' | ||
3 | import { logger } from '@root-helpers/logger' | ||
4 | import { wait } from '@root-helpers/utils' | ||
4 | 5 | ||
5 | type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } } | 6 | type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } } |
6 | 7 | ||
@@ -23,7 +24,7 @@ function segmentValidatorFactory (segmentsSha256Url: string, isLive: boolean) { | |||
23 | } | 24 | } |
24 | 25 | ||
25 | if (!segmentValue) { | 26 | if (!segmentValue) { |
26 | console.log('Refetching sha segments for %s.', filename) | 27 | logger.info(`Refetching sha segments for ${filename}`) |
27 | 28 | ||
28 | await wait(1000) | 29 | await wait(1000) |
29 | 30 | ||
@@ -71,7 +72,7 @@ function fetchSha256Segments (url: string) { | |||
71 | return fetch(url) | 72 | return fetch(url) |
72 | .then(res => res.json() as Promise<SegmentsJSON>) | 73 | .then(res => res.json() as Promise<SegmentsJSON>) |
73 | .catch(err => { | 74 | .catch(err => { |
74 | console.error('Cannot get sha256 segments', err) | 75 | logger.error('Cannot get sha256 segments', err) |
75 | return {} | 76 | return {} |
76 | }) | 77 | }) |
77 | } | 78 | } |