aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-07-15 15:30:14 +0200
committerChocobozzz <me@florianbigard.com>2022-07-18 11:37:18 +0200
commit42b40636991b97fe818007fab19091764fc5db73 (patch)
treedb431787c06ce898d22e91ff771f795219274fc6 /client/src/assets
parent654d4ede7fa4d0faa71e49bcfab6b65a686397b2 (diff)
downloadPeerTube-42b40636991b97fe818007fab19091764fc5db73.tar.gz
PeerTube-42b40636991b97fe818007fab19091764fc5db73.tar.zst
PeerTube-42b40636991b97fe818007fab19091764fc5db73.zip
Add ability for client to create server logs
Diffstat (limited to 'client/src/assets')
-rw-r--r--client/src/assets/player/peertube-player-local-storage.ts4
-rw-r--r--client/src/assets/player/peertube-player-manager.ts5
-rw-r--r--client/src/assets/player/shared/manager-options/hls-options-builder.ts3
-rw-r--r--client/src/assets/player/shared/mobile/peertube-mobile-plugin.ts19
-rw-r--r--client/src/assets/player/shared/p2p-media-loader/hls-plugin.ts25
-rw-r--r--client/src/assets/player/shared/p2p-media-loader/p2p-media-loader-plugin.ts7
-rw-r--r--client/src/assets/player/shared/p2p-media-loader/redundancy-url-manager.ts3
-rw-r--r--client/src/assets/player/shared/p2p-media-loader/segment-validator.ts9
-rw-r--r--client/src/assets/player/shared/peertube/peertube-plugin.ts7
-rw-r--r--client/src/assets/player/shared/stats/stats-card.ts3
-rw-r--r--client/src/assets/player/shared/webtorrent/peertube-chunk-store.ts15
-rw-r--r--client/src/assets/player/shared/webtorrent/video-renderer.ts5
-rw-r--r--client/src/assets/player/shared/webtorrent/webtorrent-plugin.ts25
-rw-r--r--client/src/assets/player/translations-manager.ts5
14 files changed, 75 insertions, 60 deletions
diff --git a/client/src/assets/player/peertube-player-local-storage.ts b/client/src/assets/player/peertube-player-local-storage.ts
index d9dacfba5..64040abf1 100644
--- a/client/src/assets/player/peertube-player-local-storage.ts
+++ b/client/src/assets/player/peertube-player-local-storage.ts
@@ -1,3 +1,5 @@
1import { logger } from '@root-helpers/logger'
2
1function getStoredVolume () { 3function getStoredVolume () {
2 const value = getLocalStorage('volume') 4 const value = getLocalStorage('volume')
3 if (value !== null && value !== undefined) { 5 if (value !== null && value !== undefined) {
@@ -81,7 +83,7 @@ function getStoredVideoWatchHistory (videoUUID?: string) {
81 83
82 data = JSON.parse(value) 84 data = JSON.parse(value)
83 } catch (error) { 85 } catch (error) {
84 console.error('Cannot parse video watch history from local storage: ', error) 86 logger.error('Cannot parse video watch history from local storage/', error)
85 } 87 }
86 88
87 data = data || {} 89 data = data || {}
diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts
index b24b6966e..b9077dcae 100644
--- a/client/src/assets/player/peertube-player-manager.ts
+++ b/client/src/assets/player/peertube-player-manager.ts
@@ -23,6 +23,7 @@ import './shared/mobile/peertube-mobile-plugin'
23import './shared/mobile/peertube-mobile-buttons' 23import './shared/mobile/peertube-mobile-buttons'
24import './shared/hotkeys/peertube-hotkeys-plugin' 24import './shared/hotkeys/peertube-hotkeys-plugin'
25import videojs from 'video.js' 25import videojs from 'video.js'
26import { logger } from '@root-helpers/logger'
26import { PluginsManager } from '@root-helpers/plugins-manager' 27import { PluginsManager } from '@root-helpers/plugins-manager'
27import { isMobile } from '@root-helpers/web-browser' 28import { isMobile } from '@root-helpers/web-browser'
28import { saveAverageBandwidth } from './peertube-player-local-storage' 29import { saveAverageBandwidth } from './peertube-player-local-storage'
@@ -145,7 +146,7 @@ export class PeertubePlayerManager {
145 return 146 return
146 } 147 }
147 148
148 console.log('Fast forwarding HLS to recover from an error.') 149 logger.info('Fast forwarding HLS to recover from an error.')
149 150
150 this.videojsDecodeErrors++ 151 this.videojsDecodeErrors++
151 152
@@ -170,7 +171,7 @@ export class PeertubePlayerManager {
170 return 171 return
171 } 172 }
172 173
173 console.log('Fallback to webtorrent.') 174 logger.info('Fallback to webtorrent.')
174 175
175 this.rebuildAndUpdateVideoElement(currentPlayer, options.common) 176 this.rebuildAndUpdateVideoElement(currentPlayer, options.common)
176 177
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 cdfad0f4c..ed12f6e8b 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
@@ -1,5 +1,6 @@
1import { HybridLoaderSettings } from '@peertube/p2p-media-loader-core' 1import { HybridLoaderSettings } from '@peertube/p2p-media-loader-core'
2import { HlsJsEngineSettings } from '@peertube/p2p-media-loader-hlsjs' 2import { HlsJsEngineSettings } from '@peertube/p2p-media-loader-hlsjs'
3import { logger } from '@root-helpers/logger'
3import { LiveVideoLatencyMode } from '@shared/models' 4import { LiveVideoLatencyMode } from '@shared/models'
4import { getAverageBandwidthInStore } from '../../peertube-player-local-storage' 5import { getAverageBandwidthInStore } from '../../peertube-player-local-storage'
5import { P2PMediaLoader, P2PMediaLoaderPluginOptions } from '../../types' 6import { P2PMediaLoader, P2PMediaLoaderPluginOptions } from '../../types'
@@ -61,7 +62,7 @@ export class HLSOptionsBuilder {
61 private getP2PMediaLoaderOptions (redundancyUrlManager: RedundancyUrlManager): HlsJsEngineSettings { 62 private getP2PMediaLoaderOptions (redundancyUrlManager: RedundancyUrlManager): HlsJsEngineSettings {
62 let consumeOnly = false 63 let consumeOnly = false
63 if ((navigator as any)?.connection?.type === 'cellular') { 64 if ((navigator as any)?.connection?.type === 'cellular') {
64 console.log('We are on a cellular connection: disabling seeding.') 65 logger.info('We are on a cellular connection: disabling seeding.')
65 consumeOnly = true 66 consumeOnly = true
66 } 67 }
67 68
diff --git a/client/src/assets/player/shared/mobile/peertube-mobile-plugin.ts b/client/src/assets/player/shared/mobile/peertube-mobile-plugin.ts
index 91dda7f94..646e9f8c6 100644
--- a/client/src/assets/player/shared/mobile/peertube-mobile-plugin.ts
+++ b/client/src/assets/player/shared/mobile/peertube-mobile-plugin.ts
@@ -1,8 +1,9 @@
1import { PeerTubeMobileButtons } from './peertube-mobile-buttons'
2import videojs from 'video.js'
3import debug from 'debug' 1import debug from 'debug'
2import videojs from 'video.js'
3import { logger } from '@root-helpers/logger'
4import { PeerTubeMobileButtons } from './peertube-mobile-buttons'
4 5
5const logger = debug('peertube:player:mobile') 6const debugLogger = debug('peertube:player:mobile')
6 7
7const Plugin = videojs.getPlugin('plugin') 8const Plugin = videojs.getPlugin('plugin')
8 9
@@ -45,7 +46,7 @@ class PeerTubeMobilePlugin extends Plugin {
45 if (!this.player.isFullscreen() || this.isPortraitVideo()) return 46 if (!this.player.isFullscreen() || this.isPortraitVideo()) return
46 47
47 screen.orientation.lock('landscape') 48 screen.orientation.lock('landscape')
48 .catch(err => console.error('Cannot lock screen to landscape.', err)) 49 .catch(err => logger.error('Cannot lock screen to landscape.', err))
49 }) 50 })
50 } 51 }
51 52
@@ -61,7 +62,7 @@ class PeerTubeMobilePlugin extends Plugin {
61 } 62 }
62 63
63 if (this.lastTapEvent && event.timeStamp - this.lastTapEvent.timeStamp < PeerTubeMobilePlugin.DOUBLE_TAP_DELAY_MS) { 64 if (this.lastTapEvent && event.timeStamp - this.lastTapEvent.timeStamp < PeerTubeMobilePlugin.DOUBLE_TAP_DELAY_MS) {
64 logger('Detected double tap') 65 debugLogger('Detected double tap')
65 66
66 this.lastTapEvent = undefined 67 this.lastTapEvent = undefined
67 this.onDoubleTap(event) 68 this.onDoubleTap(event)
@@ -71,7 +72,7 @@ class PeerTubeMobilePlugin extends Plugin {
71 this.newActiveState = !this.player.userActive() 72 this.newActiveState = !this.player.userActive()
72 73
73 this.tapTimeout = setTimeout(() => { 74 this.tapTimeout = setTimeout(() => {
74 logger('No double tap detected, set user active state to %s.', this.newActiveState) 75 debugLogger('No double tap detected, set user active state to %s.', this.newActiveState)
75 76
76 this.player.userActive(this.newActiveState) 77 this.player.userActive(this.newActiveState)
77 }, PeerTubeMobilePlugin.DOUBLE_TAP_DELAY_MS) 78 }, PeerTubeMobilePlugin.DOUBLE_TAP_DELAY_MS)
@@ -100,19 +101,19 @@ class PeerTubeMobilePlugin extends Plugin {
100 const rect = this.findPlayerTarget((event.target as HTMLElement)).getBoundingClientRect() 101 const rect = this.findPlayerTarget((event.target as HTMLElement)).getBoundingClientRect()
101 const offsetX = event.targetTouches[0].pageX - rect.left 102 const offsetX = event.targetTouches[0].pageX - rect.left
102 103
103 logger('Calculating double tap zone (player width: %d, offset X: %d)', playerWidth, offsetX) 104 debugLogger('Calculating double tap zone (player width: %d, offset X: %d)', playerWidth, offsetX)
104 105
105 if (offsetX > 0.66 * playerWidth) { 106 if (offsetX > 0.66 * playerWidth) {
106 if (this.seekAmount < 0) this.seekAmount = 0 107 if (this.seekAmount < 0) this.seekAmount = 0
107 108
108 this.seekAmount += 10 109 this.seekAmount += 10
109 110
110 logger('Will forward %d seconds', this.seekAmount) 111 debugLogger('Will forward %d seconds', this.seekAmount)
111 } else if (offsetX < 0.33 * playerWidth) { 112 } else if (offsetX < 0.33 * playerWidth) {
112 if (this.seekAmount > 0) this.seekAmount = 0 113 if (this.seekAmount > 0) this.seekAmount = 0
113 114
114 this.seekAmount -= 10 115 this.seekAmount -= 10
115 logger('Will rewind %d seconds', this.seekAmount) 116 debugLogger('Will rewind %d seconds', this.seekAmount)
116 } 117 }
117 118
118 this.peerTubeMobileButtons.displayFastSeek(this.seekAmount) 119 this.peerTubeMobileButtons.displayFastSeek(this.seekAmount)
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
4import Hlsjs, { ErrorData, HlsConfig, Level, LevelSwitchingData, ManifestParsedData } from 'hls.js' 4import Hlsjs, { ErrorData, HlsConfig, Level, LevelSwitchingData, ManifestParsedData } from 'hls.js'
5import videojs from 'video.js' 5import videojs from 'video.js'
6import { logger } from '@root-helpers/logger'
6import { HlsjsConfigHandlerOptions, PeerTubeResolution, VideoJSTechHLS } from '../../types' 7import { HlsjsConfigHandlerOptions, PeerTubeResolution, VideoJSTechHLS } from '../../types'
7 8
8type ErrorCounts = { 9type ErrorCounts = {
@@ -17,14 +18,14 @@ type HookFn = (player: videojs.Player, hljs: Hlsjs) => void
17 18
18const registerSourceHandler = function (vjs: typeof videojs) { 19const 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
5import { timeToInt } from '@shared/core-utils' 5import { timeToInt } from '@shared/core-utils'
6import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../../types' 6import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../../types'
7import { registerConfigPlugin, registerSourceHandler } from './hls-plugin' 7import { registerConfigPlugin, registerSourceHandler } from './hls-plugin'
8import { logger } from '@root-helpers/logger'
8 9
9registerConfigPlugin(videojs) 10registerConfigPlugin(videojs)
10registerSourceHandler(videojs) 11registerSourceHandler(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 @@
1import { basename, dirname } from 'path' 1import { basename, dirname } from 'path'
2import { logger } from '@root-helpers/logger'
2 3
3class RedundancyUrlManager { 4class 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 @@
1import { wait } from '@root-helpers/utils'
2import { Segment } from '@peertube/p2p-media-loader-core'
3import { basename } from 'path' 1import { basename } from 'path'
2import { Segment } from '@peertube/p2p-media-loader-core'
3import { logger } from '@root-helpers/logger'
4import { wait } from '@root-helpers/utils'
4 5
5type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } } 6type 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}
diff --git a/client/src/assets/player/shared/peertube/peertube-plugin.ts b/client/src/assets/player/shared/peertube/peertube-plugin.ts
index a29a0921f..69a7b2d65 100644
--- a/client/src/assets/player/shared/peertube/peertube-plugin.ts
+++ b/client/src/assets/player/shared/peertube/peertube-plugin.ts
@@ -1,5 +1,6 @@
1import debug from 'debug' 1import debug from 'debug'
2import videojs from 'video.js' 2import videojs from 'video.js'
3import { logger } from '@root-helpers/logger'
3import { isMobile } from '@root-helpers/web-browser' 4import { isMobile } from '@root-helpers/web-browser'
4import { timeToInt } from '@shared/core-utils' 5import { timeToInt } from '@shared/core-utils'
5import { VideoView, VideoViewEvent } from '@shared/models/videos' 6import { VideoView, VideoViewEvent } from '@shared/models/videos'
@@ -15,7 +16,7 @@ import {
15import { PeerTubePluginOptions, VideoJSCaption } from '../../types' 16import { PeerTubePluginOptions, VideoJSCaption } from '../../types'
16import { SettingsButton } from '../settings/settings-menu-button' 17import { SettingsButton } from '../settings/settings-menu-button'
17 18
18const logger = debug('peertube:player:peertube') 19const debugLogger = debug('peertube:player:peertube')
19 20
20const Plugin = videojs.getPlugin('plugin') 21const Plugin = videojs.getPlugin('plugin')
21 22
@@ -176,7 +177,7 @@ class PeerTubePlugin extends Plugin {
176 lastCurrentTime = currentTime 177 lastCurrentTime = currentTime
177 178
178 this.notifyUserIsWatching(currentTime, lastViewEvent) 179 this.notifyUserIsWatching(currentTime, lastViewEvent)
179 .catch(err => console.error('Cannot notify user is watching.', err)) 180 .catch(err => logger.error('Cannot notify user is watching.', err))
180 181
181 lastViewEvent = undefined 182 lastViewEvent = undefined
182 183
@@ -249,7 +250,7 @@ class PeerTubePlugin extends Plugin {
249 (this.player as any).cache_.inactivityTimeout = timeout 250 (this.player as any).cache_.inactivityTimeout = timeout
250 this.player.options_.inactivityTimeout = timeout 251 this.player.options_.inactivityTimeout = timeout
251 252
252 logger('Set player inactivity to ' + timeout) 253 debugLogger('Set player inactivity to ' + timeout)
253 } 254 }
254 255
255 private initCaptions () { 256 private initCaptions () {
diff --git a/client/src/assets/player/shared/stats/stats-card.ts b/client/src/assets/player/shared/stats/stats-card.ts
index e9f9b6bd2..b65adcfca 100644
--- a/client/src/assets/player/shared/stats/stats-card.ts
+++ b/client/src/assets/player/shared/stats/stats-card.ts
@@ -1,4 +1,5 @@
1import videojs from 'video.js' 1import videojs from 'video.js'
2import { logger } from '@root-helpers/logger'
2import { secondsToTime } from '@shared/core-utils' 3import { secondsToTime } from '@shared/core-utils'
3import { PlayerNetworkInfo as EventPlayerNetworkInfo } from '../../types' 4import { PlayerNetworkInfo as EventPlayerNetworkInfo } from '../../types'
4import { bytes } from '../common' 5import { bytes } from '../common'
@@ -125,7 +126,7 @@ class StatsCard extends Component {
125 126
126 this.populateInfoValues(options) 127 this.populateInfoValues(options)
127 } catch (err) { 128 } catch (err) {
128 console.error('Cannot update stats.', err) 129 logger.error('Cannot update stats.', err)
129 clearInterval(this.updateInterval) 130 clearInterval(this.updateInterval)
130 } 131 }
131 }, this.intervalMs) 132 }, this.intervalMs)
diff --git a/client/src/assets/player/shared/webtorrent/peertube-chunk-store.ts b/client/src/assets/player/shared/webtorrent/peertube-chunk-store.ts
index 81378c277..74ae17704 100644
--- a/client/src/assets/player/shared/webtorrent/peertube-chunk-store.ts
+++ b/client/src/assets/player/shared/webtorrent/peertube-chunk-store.ts
@@ -2,8 +2,9 @@
2// We use temporary IndexDB (all data are removed on destroy) to avoid RAM issues 2// We use temporary IndexDB (all data are removed on destroy) to avoid RAM issues
3// Thanks @santiagogil and @Feross 3// Thanks @santiagogil and @Feross
4 4
5import { EventEmitter } from 'events'
6import Dexie from 'dexie' 5import Dexie from 'dexie'
6import { EventEmitter } from 'events'
7import { logger } from '@root-helpers/logger'
7 8
8class ChunkDatabase extends Dexie { 9class ChunkDatabase extends Dexie {
9 chunks: Dexie.Table<{ id: number, buf: Buffer }, number> 10 chunks: Dexie.Table<{ id: number, buf: Buffer }, number>
@@ -104,7 +105,7 @@ export class PeertubeChunkStore extends EventEmitter {
104 return this.db.chunks.bulkPut(processing.map(p => ({ id: p.id, buf: p.buf }))) 105 return this.db.chunks.bulkPut(processing.map(p => ({ id: p.id, buf: p.buf })))
105 }) 106 })
106 } catch (err) { 107 } catch (err) {
107 console.log('Cannot bulk insert chunks. Store them in memory.', { err }) 108 logger.info('Cannot bulk insert chunks. Store them in memory.', err)
108 109
109 processing.forEach(p => { 110 processing.forEach(p => {
110 this.memoryChunks[p.id] = p.buf 111 this.memoryChunks[p.id] = p.buf
@@ -143,7 +144,7 @@ export class PeertubeChunkStore extends EventEmitter {
143 return cb(null, buf.slice(offset, len + offset)) 144 return cb(null, buf.slice(offset, len + offset))
144 }) 145 })
145 .catch(err => { 146 .catch(err => {
146 console.error(err) 147 logger.error(err)
147 return cb(err) 148 return cb(err)
148 }) 149 })
149 } 150 }
@@ -176,7 +177,7 @@ export class PeertubeChunkStore extends EventEmitter {
176 177
177 return cb() 178 return cb()
178 } catch (err) { 179 } catch (err) {
179 console.error('Cannot destroy peertube chunk store.', err) 180 logger.error('Cannot destroy peertube chunk store.', err)
180 return cb(err) 181 return cb(err)
181 } 182 }
182 } 183 }
@@ -204,7 +205,7 @@ export class PeertubeChunkStore extends EventEmitter {
204 databasesToDeleteInfo = await this.expirationDB.databases.where('expiration').below(now).toArray() 205 databasesToDeleteInfo = await this.expirationDB.databases.where('expiration').below(now).toArray()
205 }) 206 })
206 } catch (err) { 207 } catch (err) {
207 console.error('Cannot update expiration of fetch expired databases.', err) 208 logger.error('Cannot update expiration of fetch expired databases.', err)
208 } 209 }
209 210
210 for (const databaseToDeleteInfo of databasesToDeleteInfo) { 211 for (const databaseToDeleteInfo of databasesToDeleteInfo) {
@@ -214,7 +215,7 @@ export class PeertubeChunkStore extends EventEmitter {
214 215
215 private async dropDatabase (databaseName: string) { 216 private async dropDatabase (databaseName: string) {
216 const dbToDelete = new ChunkDatabase(databaseName) 217 const dbToDelete = new ChunkDatabase(databaseName)
217 console.log('Destroying IndexDB database %s.', databaseName) 218 logger.info(`Destroying IndexDB database ${databaseName}`)
218 219
219 try { 220 try {
220 await dbToDelete.delete() 221 await dbToDelete.delete()
@@ -223,7 +224,7 @@ export class PeertubeChunkStore extends EventEmitter {
223 return this.expirationDB.databases.where({ name: databaseName }).delete() 224 return this.expirationDB.databases.where({ name: databaseName }).delete()
224 }) 225 })
225 } catch (err) { 226 } catch (err) {
226 console.error('Cannot delete %s.', databaseName, err) 227 logger.error(`Cannot delete ${databaseName}.`, err)
227 } 228 }
228 } 229 }
229 230
diff --git a/client/src/assets/player/shared/webtorrent/video-renderer.ts b/client/src/assets/player/shared/webtorrent/video-renderer.ts
index 9b80fea2c..a85d7a838 100644
--- a/client/src/assets/player/shared/webtorrent/video-renderer.ts
+++ b/client/src/assets/player/shared/webtorrent/video-renderer.ts
@@ -1,6 +1,7 @@
1// Thanks: https://github.com/feross/render-media 1// Thanks: https://github.com/feross/render-media
2 2
3const MediaElementWrapper = require('mediasource') 3const MediaElementWrapper = require('mediasource')
4import { logger } from '@root-helpers/logger'
4import { extname } from 'path' 5import { extname } from 'path'
5const Videostream = require('videostream') 6const Videostream = require('videostream')
6 7
@@ -77,8 +78,8 @@ function renderMedia (file: any, elem: HTMLVideoElement, opts: RenderMediaOption
77 } 78 }
78 79
79 function fallbackToMediaSource (useVP9 = false) { 80 function fallbackToMediaSource (useVP9 = false) {
80 if (useVP9 === true) console.log('Falling back to media source with VP9 enabled.') 81 if (useVP9 === true) logger.info('Falling back to media source with VP9 enabled.')
81 else console.log('Falling back to media source..') 82 else logger.info('Falling back to media source..')
82 83
83 useMediaSource(useVP9) 84 useMediaSource(useVP9)
84 } 85 }
diff --git a/client/src/assets/player/shared/webtorrent/webtorrent-plugin.ts b/client/src/assets/player/shared/webtorrent/webtorrent-plugin.ts
index 83b483d87..ab9ab56ac 100644
--- a/client/src/assets/player/shared/webtorrent/webtorrent-plugin.ts
+++ b/client/src/assets/player/shared/webtorrent/webtorrent-plugin.ts
@@ -1,5 +1,6 @@
1import videojs from 'video.js' 1import videojs from 'video.js'
2import * as WebTorrent from 'webtorrent' 2import * as WebTorrent from 'webtorrent'
3import { logger } from '@root-helpers/logger'
3import { isIOS } from '@root-helpers/web-browser' 4import { isIOS } from '@root-helpers/web-browser'
4import { timeToInt } from '@shared/core-utils' 5import { timeToInt } from '@shared/core-utils'
5import { VideoFile } from '@shared/models' 6import { VideoFile } from '@shared/models'
@@ -210,7 +211,7 @@ class WebTorrentPlugin extends Plugin {
210 if (destroyRenderer === true && this.renderer && this.renderer.destroy) this.renderer.destroy() 211 if (destroyRenderer === true && this.renderer && this.renderer.destroy) this.renderer.destroy()
211 212
212 this.webtorrent.remove(videoFile.magnetUri) 213 this.webtorrent.remove(videoFile.magnetUri)
213 console.log('Removed ' + videoFile.magnetUri) 214 logger.info(`Removed ${videoFile.magnetUri}`)
214 } 215 }
215 } 216 }
216 217
@@ -256,7 +257,7 @@ class WebTorrentPlugin extends Plugin {
256 ) { 257 ) {
257 if (!magnetOrTorrentUrl) return this.fallbackToHttp(options, done) 258 if (!magnetOrTorrentUrl) return this.fallbackToHttp(options, done)
258 259
259 console.log('Adding ' + magnetOrTorrentUrl + '.') 260 logger.info(`Adding ${magnetOrTorrentUrl}.`)
260 261
261 const oldTorrent = this.torrent 262 const oldTorrent = this.torrent
262 const torrentOptions = { 263 const torrentOptions = {
@@ -269,7 +270,7 @@ class WebTorrentPlugin extends Plugin {
269 } 270 }
270 271
271 this.torrent = this.webtorrent.add(magnetOrTorrentUrl, torrentOptions, torrent => { 272 this.torrent = this.webtorrent.add(magnetOrTorrentUrl, torrentOptions, torrent => {
272 console.log('Added ' + magnetOrTorrentUrl + '.') 273 logger.info(`Added ${magnetOrTorrentUrl}.`)
273 274
274 if (oldTorrent) { 275 if (oldTorrent) {
275 // Pause the old torrent 276 // Pause the old torrent
@@ -309,7 +310,7 @@ class WebTorrentPlugin extends Plugin {
309 }, options.delay || 0) 310 }, options.delay || 0)
310 }) 311 })
311 312
312 this.torrent.on('error', (err: any) => console.error(err)) 313 this.torrent.on('error', (err: any) => logger.error(err))
313 314
314 this.torrent.on('warning', (err: any) => { 315 this.torrent.on('warning', (err: any) => {
315 // We don't support HTTP tracker but we don't care -> we use the web socket tracker 316 // We don't support HTTP tracker but we don't care -> we use the web socket tracker
@@ -317,13 +318,13 @@ class WebTorrentPlugin extends Plugin {
317 318
318 // Users don't care about issues with WebRTC, but developers do so log it in the console 319 // Users don't care about issues with WebRTC, but developers do so log it in the console
319 if (err.message.indexOf('Ice connection failed') !== -1) { 320 if (err.message.indexOf('Ice connection failed') !== -1) {
320 console.log(err) 321 logger.info(err)
321 return 322 return
322 } 323 }
323 324
324 // Magnet hash is not up to date with the torrent file, add directly the torrent file 325 // Magnet hash is not up to date with the torrent file, add directly the torrent file
325 if (err.message.indexOf('incorrect info hash') !== -1) { 326 if (err.message.indexOf('incorrect info hash') !== -1) {
326 console.error('Incorrect info hash detected, falling back to torrent file.') 327 logger.error('Incorrect info hash detected, falling back to torrent file.')
327 const newOptions = { forcePlay: true, seek: options.seek } 328 const newOptions = { forcePlay: true, seek: options.seek }
328 return this.addTorrent(this.torrent['xs'], previousVideoFile, newOptions, done) 329 return this.addTorrent(this.torrent['xs'], previousVideoFile, newOptions, done)
329 } 330 }
@@ -333,7 +334,7 @@ class WebTorrentPlugin extends Plugin {
333 this.handleError(err) 334 this.handleError(err)
334 } 335 }
335 336
336 console.warn(err) 337 logger.warn(err)
337 }) 338 })
338 } 339 }
339 340
@@ -348,7 +349,7 @@ class WebTorrentPlugin extends Plugin {
348 return 349 return
349 } 350 }
350 351
351 console.error(err) 352 logger.error(err)
352 this.player.pause() 353 this.player.pause()
353 this.player.posterImage.show() 354 this.player.posterImage.show()
354 this.player.removeClass('vjs-has-autoplay') 355 this.player.removeClass('vjs-has-autoplay')
@@ -465,10 +466,10 @@ class WebTorrentPlugin extends Plugin {
465 466
466 // Lower resolution 467 // Lower resolution
467 if (this.isPlayerWaiting() && file.resolution.id < this.currentVideoFile.resolution.id) { 468 if (this.isPlayerWaiting() && file.resolution.id < this.currentVideoFile.resolution.id) {
468 console.log('Downgrading automatically the resolution to: %s', file.resolution.label) 469 logger.info(`Downgrading automatically the resolution to: ${file.resolution.label}`)
469 changeResolution = true 470 changeResolution = true
470 } else if (file.resolution.id > this.currentVideoFile.resolution.id) { // Higher resolution 471 } else if (file.resolution.id > this.currentVideoFile.resolution.id) { // Higher resolution
471 console.log('Upgrading automatically the resolution to: %s', file.resolution.label) 472 logger.info(`Upgrading automatically the resolution to: ${file.resolution.label}`)
472 changeResolution = true 473 changeResolution = true
473 changeResolutionDelay = this.CONSTANTS.AUTO_QUALITY_HIGHER_RESOLUTION_DELAY 474 changeResolutionDelay = this.CONSTANTS.AUTO_QUALITY_HIGHER_RESOLUTION_DELAY
474 } 475 }
@@ -577,7 +578,7 @@ class WebTorrentPlugin extends Plugin {
577 578
578 // The renderer returns an error when we destroy it, so skip them 579 // The renderer returns an error when we destroy it, so skip them
579 if (this.destroyingFakeRenderer === false && err) { 580 if (this.destroyingFakeRenderer === false && err) {
580 console.error('Cannot render new torrent in fake video element.', err) 581 logger.error('Cannot render new torrent in fake video element.', err)
581 } 582 }
582 583
583 // Load the future file at the correct time (in delay MS - 2 seconds) 584 // Load the future file at the correct time (in delay MS - 2 seconds)
@@ -593,7 +594,7 @@ class WebTorrentPlugin extends Plugin {
593 try { 594 try {
594 this.fakeRenderer.destroy() 595 this.fakeRenderer.destroy()
595 } catch (err) { 596 } catch (err) {
596 console.log('Cannot destroy correctly fake renderer.', err) 597 logger.info('Cannot destroy correctly fake renderer.', err)
597 } 598 }
598 } 599 }
599 this.fakeRenderer = undefined 600 this.fakeRenderer = undefined
diff --git a/client/src/assets/player/translations-manager.ts b/client/src/assets/player/translations-manager.ts
index 8a6e67dda..bf9c2d471 100644
--- a/client/src/assets/player/translations-manager.ts
+++ b/client/src/assets/player/translations-manager.ts
@@ -1,3 +1,4 @@
1import { logger } from '@root-helpers/logger'
1import { getCompleteLocale, getShortLocale, is18nLocale, isDefaultLocale } from '@shared/core-utils/i18n' 2import { getCompleteLocale, getShortLocale, is18nLocale, isDefaultLocale } from '@shared/core-utils/i18n'
2 3
3export class TranslationsManager { 4export class TranslationsManager {
@@ -11,7 +12,7 @@ export class TranslationsManager {
11 return fetch(path + '/server.json') 12 return fetch(path + '/server.json')
12 .then(res => res.json()) 13 .then(res => res.json())
13 .catch(err => { 14 .catch(err => {
14 console.error('Cannot get server translations', err) 15 logger.error('Cannot get server translations', err)
15 return undefined 16 return undefined
16 }) 17 })
17 } 18 }
@@ -33,7 +34,7 @@ export class TranslationsManager {
33 return json 34 return json
34 }) 35 })
35 .catch(err => { 36 .catch(err => {
36 console.error('Cannot get player translations', err) 37 logger.error('Cannot get player translations', err)
37 return undefined 38 return undefined
38 }) 39 })
39 } 40 }