aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts')
-rw-r--r--client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts34
1 files changed, 11 insertions, 23 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 2eb849d2b..093795e48 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,7 +1,7 @@
1import * as Hlsjs from 'hls.js/dist/hls.light.js' 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'
4import videojs from 'video.js' 2import videojs from 'video.js'
3import { Events, Segment } from '@peertube/p2p-media-loader-core'
4import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from '@peertube/p2p-media-loader-hlsjs'
5import { timeToInt } from '@shared/core-utils' 5import { timeToInt } from '@shared/core-utils'
6import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../peertube-videojs-typings' 6import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../peertube-videojs-typings'
7import { registerConfigPlugin, registerSourceHandler } from './hls-plugin' 7import { registerConfigPlugin, registerSourceHandler } from './hls-plugin'
@@ -36,9 +36,6 @@ 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
42 constructor (player: videojs.Player, options?: P2PMediaLoaderPluginOptions) { 39 constructor (player: videojs.Player, options?: P2PMediaLoaderPluginOptions) {
43 super(player) 40 super(player)
44 41
@@ -88,13 +85,12 @@ class P2pMediaLoaderPlugin extends Plugin {
88 } 85 }
89 86
90 getCurrentLevel () { 87 getCurrentLevel () {
91 return this.hlsjsLevels.find(l => l.level === this.hlsjsCurrentLevel) 88 return this.hlsjs.levels[this.hlsjs.currentLevel]
92 } 89 }
93 90
94 getLiveLatency () { 91 getLiveLatency () {
95 return undefined as number 92 // FIXME: typings
96 // FIXME: Use latency when hls >= V1 93 return Math.round((this.hlsjs as any).latency)
97 // return this.hlsjs.latency
98 } 94 }
99 95
100 getHLSJS () { 96 getHLSJS () {
@@ -140,31 +136,23 @@ class P2pMediaLoaderPlugin extends Plugin {
140 } 136 }
141 137
142 private runStats () { 138 private runStats () {
143 this.p2pEngine.on(Events.PieceBytesDownloaded, (method: string, size: number) => { 139 this.p2pEngine.on(Events.PieceBytesDownloaded, (method: string, _segment, bytes: number) => {
144 const elem = method === 'p2p' ? this.statsP2PBytes : this.statsHTTPBytes 140 const elem = method === 'p2p' ? this.statsP2PBytes : this.statsHTTPBytes
145 141
146 elem.pendingDownload.push(size) 142 elem.pendingDownload.push(bytes)
147 elem.totalDownload += size 143 elem.totalDownload += bytes
148 }) 144 })
149 145
150 this.p2pEngine.on(Events.PieceBytesUploaded, (method: string, size: number) => { 146 this.p2pEngine.on(Events.PieceBytesUploaded, (method: string, _segment, bytes: number) => {
151 const elem = method === 'p2p' ? this.statsP2PBytes : this.statsHTTPBytes 147 const elem = method === 'p2p' ? this.statsP2PBytes : this.statsHTTPBytes
152 148
153 elem.pendingUpload.push(size) 149 elem.pendingUpload.push(bytes)
154 elem.totalUpload += size 150 elem.totalUpload += bytes
155 }) 151 })
156 152
157 this.p2pEngine.on(Events.PeerConnect, () => this.statsP2PBytes.numPeers++) 153 this.p2pEngine.on(Events.PeerConnect, () => this.statsP2PBytes.numPeers++)
158 this.p2pEngine.on(Events.PeerClose, () => this.statsP2PBytes.numPeers--) 154 this.p2pEngine.on(Events.PeerClose, () => this.statsP2PBytes.numPeers--)
159 155
160 this.hlsjs.on(Hlsjs.Events.MANIFEST_PARSED, (_e, manifest) => {
161 this.hlsjsCurrentLevel = manifest.firstLevel
162 this.hlsjsLevels = manifest.levels
163 })
164 this.hlsjs.on(Hlsjs.Events.LEVEL_LOADED, (_e, level) => {
165 this.hlsjsCurrentLevel = level.levelId || (level as any).id
166 })
167
168 this.networkInfoInterval = setInterval(() => { 156 this.networkInfoInterval = setInterval(() => {
169 const p2pDownloadSpeed = this.arraySum(this.statsP2PBytes.pendingDownload) 157 const p2pDownloadSpeed = this.arraySum(this.statsP2PBytes.pendingDownload)
170 const p2pUploadSpeed = this.arraySum(this.statsP2PBytes.pendingUpload) 158 const p2pUploadSpeed = this.arraySum(this.statsP2PBytes.pendingUpload)