diff options
Diffstat (limited to 'client/src/assets/player/p2p-media-loader')
-rw-r--r-- | client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts b/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts index e97925ab5..4275a5e5e 100644 --- a/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts +++ b/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import * as Hlsjs from 'hls.js/dist/hls.light.js' | ||
2 | import { Events, Segment } from 'p2p-media-loader-core' | ||
3 | import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from 'p2p-media-loader-hlsjs' | ||
1 | import videojs from 'video.js' | 4 | import videojs from 'video.js' |
2 | import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../peertube-videojs-typings' | 5 | import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../peertube-videojs-typings' |
3 | import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from 'p2p-media-loader-hlsjs' | ||
4 | import { Events, Segment } from 'p2p-media-loader-core' | ||
5 | import { timeToInt } from '../utils' | 6 | import { timeToInt } from '../utils' |
6 | import { registerConfigPlugin, registerSourceHandler } from './hls-plugin' | 7 | import { registerConfigPlugin, registerSourceHandler } from './hls-plugin' |
7 | import * as Hlsjs from 'hls.js/dist/hls.light.js' | ||
8 | 8 | ||
9 | registerConfigPlugin(videojs) | 9 | registerConfigPlugin(videojs) |
10 | registerSourceHandler(videojs) | 10 | registerSourceHandler(videojs) |
@@ -36,6 +36,9 @@ class P2pMediaLoaderPlugin extends Plugin { | |||
36 | 36 | ||
37 | private networkInfoInterval: any | 37 | private networkInfoInterval: any |
38 | 38 | ||
39 | private hlsjsCurrentLevel: number | ||
40 | private hlsjsLevels: Hlsjs.Level[] | ||
41 | |||
39 | constructor (player: videojs.Player, options?: P2PMediaLoaderPluginOptions) { | 42 | constructor (player: videojs.Player, options?: P2PMediaLoaderPluginOptions) { |
40 | super(player) | 43 | super(player) |
41 | 44 | ||
@@ -84,6 +87,16 @@ class P2pMediaLoaderPlugin extends Plugin { | |||
84 | clearInterval(this.networkInfoInterval) | 87 | clearInterval(this.networkInfoInterval) |
85 | } | 88 | } |
86 | 89 | ||
90 | getCurrentLevel () { | ||
91 | return this.hlsjsLevels.find(l => l.level === this.hlsjsCurrentLevel) | ||
92 | } | ||
93 | |||
94 | getLiveLatency () { | ||
95 | return undefined as number | ||
96 | // FIXME: Use latency when hls >= V1 | ||
97 | // return this.hlsjs.latency | ||
98 | } | ||
99 | |||
87 | getHLSJS () { | 100 | getHLSJS () { |
88 | return this.hlsjs | 101 | return this.hlsjs |
89 | } | 102 | } |
@@ -140,6 +153,14 @@ class P2pMediaLoaderPlugin extends Plugin { | |||
140 | this.p2pEngine.on(Events.PeerConnect, () => this.statsP2PBytes.numPeers++) | 153 | this.p2pEngine.on(Events.PeerConnect, () => this.statsP2PBytes.numPeers++) |
141 | this.p2pEngine.on(Events.PeerClose, () => this.statsP2PBytes.numPeers--) | 154 | this.p2pEngine.on(Events.PeerClose, () => this.statsP2PBytes.numPeers--) |
142 | 155 | ||
156 | this.hlsjs.on(Hlsjs.Events.MANIFEST_PARSED, (_e, manifest) => { | ||
157 | this.hlsjsCurrentLevel = manifest.firstLevel | ||
158 | this.hlsjsLevels = manifest.levels | ||
159 | }) | ||
160 | this.hlsjs.on(Hlsjs.Events.LEVEL_LOADED, (_e, level) => { | ||
161 | this.hlsjsCurrentLevel = level.levelId || (level as any).id | ||
162 | }) | ||
163 | |||
143 | this.networkInfoInterval = setInterval(() => { | 164 | this.networkInfoInterval = setInterval(() => { |
144 | const p2pDownloadSpeed = this.arraySum(this.statsP2PBytes.pendingDownload) | 165 | const p2pDownloadSpeed = this.arraySum(this.statsP2PBytes.pendingDownload) |
145 | const p2pUploadSpeed = this.arraySum(this.statsP2PBytes.pendingUpload) | 166 | const p2pUploadSpeed = this.arraySum(this.statsP2PBytes.pendingUpload) |
@@ -166,7 +187,8 @@ class P2pMediaLoaderPlugin extends Plugin { | |||
166 | numPeers: this.statsP2PBytes.numPeers, | 187 | numPeers: this.statsP2PBytes.numPeers, |
167 | downloaded: this.statsP2PBytes.totalDownload, | 188 | downloaded: this.statsP2PBytes.totalDownload, |
168 | uploaded: this.statsP2PBytes.totalUpload | 189 | uploaded: this.statsP2PBytes.totalUpload |
169 | } | 190 | }, |
191 | bandwidthEstimate: (this.hlsjs as any).bandwidthEstimate / 8 | ||
170 | } as PlayerNetworkInfo) | 192 | } as PlayerNetworkInfo) |
171 | }, this.CONSTANTS.INFO_SCHEDULER) | 193 | }, this.CONSTANTS.INFO_SCHEDULER) |
172 | } | 194 | } |