aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/shared/webtorrent
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets/player/shared/webtorrent')
-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
3 files changed, 24 insertions, 21 deletions
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