diff options
author | Chocobozzz <me@florianbigard.com> | 2018-10-18 14:35:31 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-18 14:35:31 +0200 |
commit | c199c427d4ae586339822320f20f512a7a19dc3f (patch) | |
tree | 9cbe8bebc25e97d2e8086c41bcd7180dd752dbac /client/src/assets/player/peertube-videojs-plugin.ts | |
parent | cdf4cb9eaf5f6bc71f7c1e1963c07575f1d2593d (diff) | |
download | PeerTube-c199c427d4ae586339822320f20f512a7a19dc3f.tar.gz PeerTube-c199c427d4ae586339822320f20f512a7a19dc3f.tar.zst PeerTube-c199c427d4ae586339822320f20f512a7a19dc3f.zip |
Better typings
Diffstat (limited to 'client/src/assets/player/peertube-videojs-plugin.ts')
-rw-r--r-- | client/src/assets/player/peertube-videojs-plugin.ts | 20 |
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 @@ | |||
1 | const videojs = require('video.js') | 1 | // FIXME: something weird with our path definition in tsconfig and typings |
2 | // @ts-ignore | ||
3 | import * as videojs from 'video.js' | ||
4 | |||
2 | import * as WebTorrent from 'webtorrent' | 5 | import * as WebTorrent from 'webtorrent' |
3 | import { VideoFile } from '../../../../shared/models/videos/video.model' | 6 | import { VideoFile } from '../../../../shared/models/videos/video.model' |
4 | import { renderVideo } from './video-renderer' | 7 | import { renderVideo } from './video-renderer' |
5 | import './settings-menu-button' | 8 | import './settings-menu-button' |
6 | import { PeertubePluginOptions, UserWatching, VideoJSCaption, VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' | 9 | import { PeertubePluginOptions, UserWatching, VideoJSCaption, VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' |
7 | import { isMobile, timeToInt, videoFileMaxByResolution, videoFileMinByResolution } from './utils' | 10 | import { isMobile, timeToInt, videoFileMaxByResolution, videoFileMinByResolution } from './utils' |
8 | const CacheChunkStore = require('cache-chunk-store') | ||
9 | import { PeertubeChunkStore } from './peertube-chunk-store' | 11 | import { PeertubeChunkStore } from './peertube-chunk-store' |
10 | import { | 12 | import { |
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 | ||
22 | const CacheChunkStore = require('cache-chunk-store') | ||
23 | |||
20 | type PlayOptions = { | 24 | type 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' ]) |