aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/p2p-media-loader
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-04-27 15:50:29 +0200
committerChocobozzz <chocobozzz@cpy.re>2021-04-28 09:05:44 +0200
commit4e11d8f3ca65bb1ffd0f42fa1521eabc5f3d7713 (patch)
tree3867f59d312d10de25d76f8be3c18eeca5bcebf3 /client/src/assets/player/p2p-media-loader
parentff563914bb10728301a24fb9e548c9efb62387eb (diff)
downloadPeerTube-4e11d8f3ca65bb1ffd0f42fa1521eabc5f3d7713.tar.gz
PeerTube-4e11d8f3ca65bb1ffd0f42fa1521eabc5f3d7713.tar.zst
PeerTube-4e11d8f3ca65bb1ffd0f42fa1521eabc5f3d7713.zip
Cleanup stats for nerds
Diffstat (limited to 'client/src/assets/player/p2p-media-loader')
-rw-r--r--client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts30
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 @@
1import * as Hlsjs from 'hls.js/dist/hls.light.js'
2import { Events, Segment } from 'p2p-media-loader-core'
3import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from 'p2p-media-loader-hlsjs'
1import videojs from 'video.js' 4import videojs from 'video.js'
2import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../peertube-videojs-typings' 5import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../peertube-videojs-typings'
3import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from 'p2p-media-loader-hlsjs'
4import { Events, Segment } from 'p2p-media-loader-core'
5import { timeToInt } from '../utils' 6import { timeToInt } from '../utils'
6import { registerConfigPlugin, registerSourceHandler } from './hls-plugin' 7import { registerConfigPlugin, registerSourceHandler } from './hls-plugin'
7import * as Hlsjs from 'hls.js/dist/hls.light.js'
8 8
9registerConfigPlugin(videojs) 9registerConfigPlugin(videojs)
10registerSourceHandler(videojs) 10registerSourceHandler(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 }