diff options
author | Chocobozzz <me@florianbigard.com> | 2019-01-24 13:43:44 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-02-11 09:13:02 +0100 |
commit | 4348a27d252a3349bafa7ef4859c0e2cf060c255 (patch) | |
tree | ab3d60118ebb31c84050c3d544dbd600006491d1 /client/src/assets/player/p2p-media-loader-plugin.ts | |
parent | 3b6f205c34bb931de0323581edf991ca33256e6b (diff) | |
download | PeerTube-4348a27d252a3349bafa7ef4859c0e2cf060c255.tar.gz PeerTube-4348a27d252a3349bafa7ef4859c0e2cf060c255.tar.zst PeerTube-4348a27d252a3349bafa7ef4859c0e2cf060c255.zip |
Add lazy loading in player
Diffstat (limited to 'client/src/assets/player/p2p-media-loader-plugin.ts')
-rw-r--r-- | client/src/assets/player/p2p-media-loader-plugin.ts | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/client/src/assets/player/p2p-media-loader-plugin.ts b/client/src/assets/player/p2p-media-loader-plugin.ts index 25117e51e..a5b20219f 100644 --- a/client/src/assets/player/p2p-media-loader-plugin.ts +++ b/client/src/assets/player/p2p-media-loader-plugin.ts | |||
@@ -5,10 +5,9 @@ import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo, VideoJSComponentInterfa | |||
5 | 5 | ||
6 | // videojs-hlsjs-plugin needs videojs in window | 6 | // videojs-hlsjs-plugin needs videojs in window |
7 | window['videojs'] = videojs | 7 | window['videojs'] = videojs |
8 | import '@streamroot/videojs-hlsjs-plugin' | 8 | require('@streamroot/videojs-hlsjs-plugin') |
9 | 9 | ||
10 | import { Engine, initVideoJsContribHlsJsPlayer } from 'p2p-media-loader-hlsjs' | 10 | import { Engine, initVideoJsContribHlsJsPlayer } from 'p2p-media-loader-hlsjs' |
11 | import * as Hls from 'hls.js' | ||
12 | import { Events } from 'p2p-media-loader-core' | 11 | import { Events } from 'p2p-media-loader-core' |
13 | 12 | ||
14 | const Plugin: VideoJSComponentInterface = videojs.getPlugin('plugin') | 13 | const Plugin: VideoJSComponentInterface = videojs.getPlugin('plugin') |
@@ -18,7 +17,7 @@ class P2pMediaLoaderPlugin extends Plugin { | |||
18 | INFO_SCHEDULER: 1000 // Don't change this | 17 | INFO_SCHEDULER: 1000 // Don't change this |
19 | } | 18 | } |
20 | 19 | ||
21 | private hlsjs: Hls | 20 | private hlsjs: any // Don't type hlsjs to not bundle the module |
22 | private p2pEngine: Engine | 21 | private p2pEngine: Engine |
23 | private statsP2PBytes = { | 22 | private statsP2PBytes = { |
24 | pendingDownload: [] as number[], | 23 | pendingDownload: [] as number[], |
@@ -33,7 +32,7 @@ class P2pMediaLoaderPlugin extends Plugin { | |||
33 | constructor (player: videojs.Player, options: P2PMediaLoaderPluginOptions) { | 32 | constructor (player: videojs.Player, options: P2PMediaLoaderPluginOptions) { |
34 | super(player, options) | 33 | super(player, options) |
35 | 34 | ||
36 | videojs.Html5Hlsjs.addHook('beforeinitialize', (videojsPlayer: any, hlsjs: Hls) => { | 35 | videojs.Html5Hlsjs.addHook('beforeinitialize', (videojsPlayer: any, hlsjs: any) => { |
37 | this.hlsjs = hlsjs | 36 | this.hlsjs = hlsjs |
38 | 37 | ||
39 | this.initialize() | 38 | this.initialize() |
@@ -54,7 +53,9 @@ class P2pMediaLoaderPlugin extends Plugin { | |||
54 | private initialize () { | 53 | private initialize () { |
55 | this.p2pEngine = this.player.tech_.options_.hlsjsConfig.loader.getEngine() | 54 | this.p2pEngine = this.player.tech_.options_.hlsjsConfig.loader.getEngine() |
56 | 55 | ||
57 | this.hlsjs.on(Hls.Events.LEVEL_SWITCHING, (_, data: Hls.levelSwitchingData) => { | 56 | // Avoid using constants to not import hls.hs |
57 | // https://github.com/video-dev/hls.js/blob/master/src/events.js#L37 | ||
58 | this.hlsjs.on('hlsLevelSwitching', (_: any, data: any) => { | ||
58 | this.trigger('resolutionChange', { auto: this.hlsjs.autoLevelEnabled, resolutionId: data.height }) | 59 | this.trigger('resolutionChange', { auto: this.hlsjs.autoLevelEnabled, resolutionId: data.height }) |
59 | }) | 60 | }) |
60 | 61 | ||