]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/webtorrent/webtorrent-plugin.ts
Add ability to disable webtorrent
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / webtorrent / webtorrent-plugin.ts
index c69bf31fa8d5f56b1cf9473cce45d114c11d0f65..4a0b38703050f0d13db698ee7b7bf234b64f59e1 100644 (file)
@@ -3,10 +3,9 @@
 import * as videojs from 'video.js'
 
 import * as WebTorrent from 'webtorrent'
-import { VideoFile } from '../../../../../shared/models/videos/video.model'
 import { renderVideo } from './video-renderer'
 import { LoadedQualityData, PlayerNetworkInfo, VideoJSComponentInterface, WebtorrentPluginOptions } from '../peertube-videojs-typings'
-import { getRtcConfig, videoFileMaxByResolution, videoFileMinByResolution } from '../utils'
+import { getRtcConfig, timeToInt, videoFileMaxByResolution, videoFileMinByResolution } from '../utils'
 import { PeertubeChunkStore } from './peertube-chunk-store'
 import {
   getAverageBandwidthInStore,
@@ -15,6 +14,7 @@ import {
   getStoredWebTorrentEnabled,
   saveAverageBandwidth
 } from '../peertube-player-local-storage'
+import { VideoFile } from '@shared/models'
 
 const CacheChunkStore = require('cache-chunk-store')
 
@@ -73,6 +73,8 @@ class WebTorrentPlugin extends Plugin {
   constructor (player: videojs.Player, options: WebtorrentPluginOptions) {
     super(player, options)
 
+    this.startTime = timeToInt(options.startTime)
+
     // Disable auto play on iOS
     this.autoplay = options.autoplay && this.isIOS() === false
     this.playerRefusedP2P = !getStoredWebTorrentEnabled()
@@ -232,9 +234,12 @@ class WebTorrentPlugin extends Plugin {
 
     const oldTorrent = this.torrent
     const torrentOptions = {
-      store: (chunkLength: number, storeOpts: any) => new CacheChunkStore(new PeertubeChunkStore(chunkLength, storeOpts), {
-        max: 100
-      })
+      // Don't use arrow function: it breaks webtorrent (that uses `new` keyword)
+      store: function (chunkLength: number, storeOpts: any) {
+        return new CacheChunkStore(new PeertubeChunkStore(chunkLength, storeOpts), {
+          max: 100
+        })
+      }
     }
 
     this.torrent = this.webtorrent.add(magnetOrTorrentUrl, torrentOptions, torrent => {
@@ -345,7 +350,7 @@ class WebTorrentPlugin extends Plugin {
     if (!averageDownloadSpeed) averageDownloadSpeed = this.getAndSaveActualDownloadSpeed()
 
     // Limit resolution according to player height
-    const playerHeight = this.playerElement.offsetHeight as number
+    const playerHeight = this.playerElement.offsetHeight
 
     // We take the first resolution just above the player height
     // Example: player height is 530px, we want the 720p file instead of 480p