aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/peertube-videojs-plugin.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets/player/peertube-videojs-plugin.ts')
-rw-r--r--client/src/assets/player/peertube-videojs-plugin.ts20
1 files changed, 12 insertions, 8 deletions
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts
index 03def186e..40da5f1f7 100644
--- a/client/src/assets/player/peertube-videojs-plugin.ts
+++ b/client/src/assets/player/peertube-videojs-plugin.ts
@@ -1,11 +1,13 @@
1const videojs = require('video.js') 1// FIXME: something weird with our path definition in tsconfig and typings
2// @ts-ignore
3import * as videojs from 'video.js'
4
2import * as WebTorrent from 'webtorrent' 5import * as WebTorrent from 'webtorrent'
3import { VideoFile } from '../../../../shared/models/videos/video.model' 6import { VideoFile } from '../../../../shared/models/videos/video.model'
4import { renderVideo } from './video-renderer' 7import { renderVideo } from './video-renderer'
5import './settings-menu-button' 8import './settings-menu-button'
6import { PeertubePluginOptions, UserWatching, VideoJSCaption, VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' 9import { PeertubePluginOptions, UserWatching, VideoJSCaption, VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
7import { isMobile, timeToInt, videoFileMaxByResolution, videoFileMinByResolution } from './utils' 10import { isMobile, timeToInt, videoFileMaxByResolution, videoFileMinByResolution } from './utils'
8const CacheChunkStore = require('cache-chunk-store')
9import { PeertubeChunkStore } from './peertube-chunk-store' 11import { PeertubeChunkStore } from './peertube-chunk-store'
10import { 12import {
11 getAverageBandwidthInStore, 13 getAverageBandwidthInStore,
@@ -17,6 +19,8 @@ import {
17 saveVolumeInStore 19 saveVolumeInStore
18} from './peertube-player-local-storage' 20} from './peertube-player-local-storage'
19 21
22const CacheChunkStore = require('cache-chunk-store')
23
20type PlayOptions = { 24type PlayOptions = {
21 forcePlay?: boolean, 25 forcePlay?: boolean,
22 seek?: number, 26 seek?: number,
@@ -61,7 +65,7 @@ class PeerTubePlugin extends Plugin {
61 65
62 private player: any 66 private player: any
63 private currentVideoFile: VideoFile 67 private currentVideoFile: VideoFile
64 private torrent: any 68 private torrent: WebTorrent.Torrent
65 private videoCaptions: VideoJSCaption[] 69 private videoCaptions: VideoJSCaption[]
66 70
67 private renderer: any 71 private renderer: any
@@ -83,7 +87,7 @@ class PeerTubePlugin extends Plugin {
83 87
84 private downloadSpeeds: number[] = [] 88 private downloadSpeeds: number[] = []
85 89
86 constructor (player: any, options: PeertubePluginOptions) { 90 constructor (player: videojs.Player, options: PeertubePluginOptions) {
87 super(player, options) 91 super(player, options)
88 92
89 // Disable auto play on iOS 93 // Disable auto play on iOS
@@ -273,7 +277,7 @@ class PeerTubePlugin extends Plugin {
273 277
274 const oldTorrent = this.torrent 278 const oldTorrent = this.torrent
275 const torrentOptions = { 279 const torrentOptions = {
276 store: (chunkLength: any, storeOpts: any) => new CacheChunkStore(new PeertubeChunkStore(chunkLength, storeOpts), { 280 store: (chunkLength: number, storeOpts: any) => new CacheChunkStore(new PeertubeChunkStore(chunkLength, storeOpts), {
277 max: 100 281 max: 100
278 }) 282 })
279 } 283 }
@@ -304,7 +308,7 @@ class PeerTubePlugin extends Plugin {
304 308
305 if (err) return this.fallbackToHttp(options, done) 309 if (err) return this.fallbackToHttp(options, done)
306 310
307 return this.tryToPlay((err: Error) => { 311 return this.tryToPlay(err => {
308 if (err) return done(err) 312 if (err) return done(err)
309 313
310 if (options.seek) this.seek(options.seek) 314 if (options.seek) this.seek(options.seek)
@@ -344,7 +348,7 @@ class PeerTubePlugin extends Plugin {
344 }) 348 })
345 } 349 }
346 350
347 private tryToPlay (done?: Function) { 351 private tryToPlay (done?: (err?: Error) => void) {
348 if (!done) done = function () { /* empty */ } 352 if (!done) done = function () { /* empty */ }
349 353
350 const playPromise = this.player.play() 354 const playPromise = this.player.play()
@@ -641,7 +645,7 @@ class PeerTubePlugin extends Plugin {
641 return this.videoFiles[Math.floor(this.videoFiles.length / 2)] 645 return this.videoFiles[Math.floor(this.videoFiles.length / 2)]
642 } 646 }
643 647
644 private stopTorrent (torrent: any) { 648 private stopTorrent (torrent: WebTorrent.Torrent) {
645 torrent.pause() 649 torrent.pause()
646 // Pause does not remove actual peers (in particular the webseed peer) 650 // Pause does not remove actual peers (in particular the webseed peer)
647 torrent.removePeer(torrent[ 'ws' ]) 651 torrent.removePeer(torrent[ 'ws' ])