diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-18 09:28:08 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-18 10:26:18 +0200 |
commit | b7f1747dc75171368df6ea2ab298971a33af56ed (patch) | |
tree | a217c842c6b5502d1d14e5c10eed916820de304f | |
parent | 80d7cf3a15c533d43e7e7f7a240d0eb89640e1c3 (diff) | |
download | PeerTube-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
-rw-r--r-- | client/src/app/app.module.ts | 2 | ||||
-rw-r--r-- | client/src/assets/player/peertube-videojs-plugin.ts | 47 | ||||
-rw-r--r-- | server/lib/schedulers/update-videos-scheduler.ts | 2 |
3 files changed, 25 insertions, 26 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' | |||
16 | import { SharedModule } from './shared' | 16 | import { SharedModule } from './shared' |
17 | import { SignupModule } from './signup' | 17 | import { SignupModule } from './signup' |
18 | import { VideosModule } from './videos' | 18 | import { VideosModule } from './videos' |
19 | import { buildFileLocale, getCompleteLocale, getDefaultLocale, isDefaultLocale } from '../../../shared/models/i18n' | 19 | import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '../../../shared/models/i18n' |
20 | import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' | 20 | import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' |
21 | 21 | ||
22 | export function metaFactory (serverService: ServerService): MetaLoader { | 22 | export 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 { | |||
17 | import * as CacheChunkStore from 'cache-chunk-store' | 17 | import * as CacheChunkStore from 'cache-chunk-store' |
18 | import { PeertubeChunkStore } from './peertube-chunk-store' | 18 | import { PeertubeChunkStore } from './peertube-chunk-store' |
19 | 19 | ||
20 | const webtorrent = new WebTorrent({ | 20 | const 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 | |||
36 | const Plugin: VideoJSComponentInterface = videojsUntyped.getPlugin('plugin') | ||
37 | class PeerTubePlugin extends Plugin { | 21 | class 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 | ||
599 | videojsUntyped.registerPlugin('peertube', PeerTubePlugin) | 600 | videojs.registerPlugin('peertube', PeerTubePlugin) |
600 | export { PeerTubePlugin } | 601 | export { PeerTubePlugin } |
diff --git a/server/lib/schedulers/update-videos-scheduler.ts b/server/lib/schedulers/update-videos-scheduler.ts index a964648fd..760475af9 100644 --- a/server/lib/schedulers/update-videos-scheduler.ts +++ b/server/lib/schedulers/update-videos-scheduler.ts | |||
@@ -1,6 +1,4 @@ | |||
1 | import { isTestInstance } from '../../helpers/core-utils' | ||
2 | import { logger } from '../../helpers/logger' | 1 | import { logger } from '../../helpers/logger' |
3 | import { JobQueue } from '../job-queue' | ||
4 | import { AbstractScheduler } from './abstract-scheduler' | 2 | import { AbstractScheduler } from './abstract-scheduler' |
5 | import { ScheduleVideoUpdateModel } from '../../models/video/schedule-video-update' | 3 | import { ScheduleVideoUpdateModel } from '../../models/video/schedule-video-update' |
6 | import { retryTransactionWrapper } from '../../helpers/database-utils' | 4 | import { retryTransactionWrapper } from '../../helpers/database-utils' |