aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets/player')
-rw-r--r--client/src/assets/player/peertube-videojs-plugin.ts47
1 files changed, 24 insertions, 23 deletions
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 }