aboutsummaryrefslogtreecommitdiffhomepage
path: root/client
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-18 09:28:08 +0200
committerChocobozzz <me@florianbigard.com>2018-06-18 10:26:18 +0200
commitb7f1747dc75171368df6ea2ab298971a33af56ed (patch)
treea217c842c6b5502d1d14e5c10eed916820de304f /client
parent80d7cf3a15c533d43e7e7f7a240d0eb89640e1c3 (diff)
downloadPeerTube-b7f1747dc75171368df6ea2ab298971a33af56ed.tar.gz
PeerTube-b7f1747dc75171368df6ea2ab298971a33af56ed.tar.zst
PeerTube-b7f1747dc75171368df6ea2ab298971a33af56ed.zip
Create webtorrent client on player load
So we don't run Angular change detection every 250ms on webtorrent import, when https://github.com/mafintosh/speedometer/pull/7 will be merged
Diffstat (limited to 'client')
-rw-r--r--client/src/app/app.module.ts2
-rw-r--r--client/src/assets/player/peertube-videojs-plugin.ts47
2 files changed, 25 insertions, 24 deletions
diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts
index 51e354378..003c91009 100644
--- a/client/src/app/app.module.ts
+++ b/client/src/app/app.module.ts
@@ -16,7 +16,7 @@ import { MenuComponent } from './menu'
16import { SharedModule } from './shared' 16import { SharedModule } from './shared'
17import { SignupModule } from './signup' 17import { SignupModule } from './signup'
18import { VideosModule } from './videos' 18import { VideosModule } from './videos'
19import { buildFileLocale, getCompleteLocale, getDefaultLocale, isDefaultLocale } from '../../../shared/models/i18n' 19import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '../../../shared/models/i18n'
20import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' 20import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils'
21 21
22export function metaFactory (serverService: ServerService): MetaLoader { 22export function metaFactory (serverService: ServerService): MetaLoader {
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts
index d3ae7b137..fe9fc1a69 100644
--- a/client/src/assets/player/peertube-videojs-plugin.ts
+++ b/client/src/assets/player/peertube-videojs-plugin.ts
@@ -17,23 +17,7 @@ import {
17import * as CacheChunkStore from 'cache-chunk-store' 17import * as CacheChunkStore from 'cache-chunk-store'
18import { PeertubeChunkStore } from './peertube-chunk-store' 18import { PeertubeChunkStore } from './peertube-chunk-store'
19 19
20const webtorrent = new WebTorrent({ 20const Plugin: VideoJSComponentInterface = videojs.getPlugin('plugin')
21 tracker: {
22 rtcConfig: {
23 iceServers: [
24 {
25 urls: 'stun:stun.stunprotocol.org'
26 },
27 {
28 urls: 'stun:stun.framasoft.org'
29 }
30 ]
31 }
32 },
33 dht: false
34})
35
36const Plugin: VideoJSComponentInterface = videojsUntyped.getPlugin('plugin')
37class PeerTubePlugin extends Plugin { 21class PeerTubePlugin extends Plugin {
38 private readonly playerElement: HTMLVideoElement 22 private readonly playerElement: HTMLVideoElement
39 23
@@ -52,9 +36,26 @@ class PeerTubePlugin extends Plugin {
52 BANDWIDTH_AVERAGE_NUMBER_OF_VALUES: 5 // Last 5 seconds to build average bandwidth 36 BANDWIDTH_AVERAGE_NUMBER_OF_VALUES: 5 // Last 5 seconds to build average bandwidth
53 } 37 }
54 38
39 private readonly webtorrent = new WebTorrent({
40 tracker: {
41 rtcConfig: {
42 iceServers: [
43 {
44 urls: 'stun:stun.stunprotocol.org'
45 },
46 {
47 urls: 'stun:stun.framasoft.org'
48 }
49 ]
50 }
51 },
52 dht: false
53 })
54
55 private player: any 55 private player: any
56 private currentVideoFile: VideoFile 56 private currentVideoFile: VideoFile
57 private torrent: WebTorrent.Torrent 57 private torrent: WebTorrent.Torrent
58 private renderer
58 private fakeRenderer 59 private fakeRenderer
59 private autoResolution = true 60 private autoResolution = true
60 private isAutoResolutionObservation = false 61 private isAutoResolutionObservation = false
@@ -194,7 +195,7 @@ class PeerTubePlugin extends Plugin {
194 }) 195 })
195 } 196 }
196 197
197 this.torrent = webtorrent.add(magnetOrTorrentUrl, torrentOptions, torrent => { 198 this.torrent = this.webtorrent.add(magnetOrTorrentUrl, torrentOptions, torrent => {
198 console.log('Added ' + magnetOrTorrentUrl + '.') 199 console.log('Added ' + magnetOrTorrentUrl + '.')
199 200
200 if (oldTorrent) { 201 if (oldTorrent) {
@@ -287,10 +288,10 @@ class PeerTubePlugin extends Plugin {
287 } 288 }
288 289
289 flushVideoFile (videoFile: VideoFile, destroyRenderer = true) { 290 flushVideoFile (videoFile: VideoFile, destroyRenderer = true) {
290 if (videoFile !== undefined && webtorrent.get(videoFile.magnetUri)) { 291 if (videoFile !== undefined && this.webtorrent.get(videoFile.magnetUri)) {
291 if (destroyRenderer === true && this.renderer && this.renderer.destroy) this.renderer.destroy() 292 if (destroyRenderer === true && this.renderer && this.renderer.destroy) this.renderer.destroy()
292 293
293 webtorrent.remove(videoFile.magnetUri) 294 this.webtorrent.remove(videoFile.magnetUri)
294 console.log('Removed ' + videoFile.magnetUri) 295 console.log('Removed ' + videoFile.magnetUri)
295 } 296 }
296 } 297 }
@@ -460,8 +461,8 @@ class PeerTubePlugin extends Plugin {
460 // Http fallback 461 // Http fallback
461 if (this.torrent === null) return this.trigger('torrentInfo', false) 462 if (this.torrent === null) return this.trigger('torrentInfo', false)
462 463
463 // webtorrent.downloadSpeed because we need to take into account the potential old torrent too 464 // this.webtorrent.downloadSpeed because we need to take into account the potential old torrent too
464 if (webtorrent.downloadSpeed !== 0) this.downloadSpeeds.push(webtorrent.downloadSpeed) 465 if (this.webtorrent.downloadSpeed !== 0) this.downloadSpeeds.push(this.webtorrent.downloadSpeed)
465 466
466 return this.trigger('torrentInfo', { 467 return this.trigger('torrentInfo', {
467 downloadSpeed: this.torrent.downloadSpeed, 468 downloadSpeed: this.torrent.downloadSpeed,
@@ -596,5 +597,5 @@ class PeerTubePlugin extends Plugin {
596 } 597 }
597} 598}
598 599
599videojsUntyped.registerPlugin('peertube', PeerTubePlugin) 600videojs.registerPlugin('peertube', PeerTubePlugin)
600export { PeerTubePlugin } 601export { PeerTubePlugin }