From 3e254de8bef59e4e25b74d1b0fde07de29654ada Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 3 Aug 2021 11:51:49 +0200 Subject: HLS v1 support --- .../p2p-media-loader/p2p-media-loader-plugin.ts | 34 +++++++--------------- 1 file changed, 11 insertions(+), 23 deletions(-) (limited to 'client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts') 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 @@ import * as Hlsjs from 'hls.js/dist/hls.light.js' -import { Events, Segment } from 'p2p-media-loader-core' -import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from 'p2p-media-loader-hlsjs' import videojs from 'video.js' +import { Events, Segment } from '@peertube/p2p-media-loader-core' +import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from '@peertube/p2p-media-loader-hlsjs' import { timeToInt } from '@shared/core-utils' import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../peertube-videojs-typings' import { registerConfigPlugin, registerSourceHandler } from './hls-plugin' @@ -36,9 +36,6 @@ class P2pMediaLoaderPlugin extends Plugin { private networkInfoInterval: any - private hlsjsCurrentLevel: number - private hlsjsLevels: Hlsjs.Level[] - constructor (player: videojs.Player, options?: P2PMediaLoaderPluginOptions) { super(player) @@ -88,13 +85,12 @@ class P2pMediaLoaderPlugin extends Plugin { } getCurrentLevel () { - return this.hlsjsLevels.find(l => l.level === this.hlsjsCurrentLevel) + return this.hlsjs.levels[this.hlsjs.currentLevel] } getLiveLatency () { - return undefined as number - // FIXME: Use latency when hls >= V1 - // return this.hlsjs.latency + // FIXME: typings + return Math.round((this.hlsjs as any).latency) } getHLSJS () { @@ -140,31 +136,23 @@ class P2pMediaLoaderPlugin extends Plugin { } private runStats () { - this.p2pEngine.on(Events.PieceBytesDownloaded, (method: string, size: number) => { + this.p2pEngine.on(Events.PieceBytesDownloaded, (method: string, _segment, bytes: number) => { const elem = method === 'p2p' ? this.statsP2PBytes : this.statsHTTPBytes - elem.pendingDownload.push(size) - elem.totalDownload += size + elem.pendingDownload.push(bytes) + elem.totalDownload += bytes }) - this.p2pEngine.on(Events.PieceBytesUploaded, (method: string, size: number) => { + this.p2pEngine.on(Events.PieceBytesUploaded, (method: string, _segment, bytes: number) => { const elem = method === 'p2p' ? this.statsP2PBytes : this.statsHTTPBytes - elem.pendingUpload.push(size) - elem.totalUpload += size + elem.pendingUpload.push(bytes) + elem.totalUpload += bytes }) this.p2pEngine.on(Events.PeerConnect, () => this.statsP2PBytes.numPeers++) this.p2pEngine.on(Events.PeerClose, () => this.statsP2PBytes.numPeers--) - this.hlsjs.on(Hlsjs.Events.MANIFEST_PARSED, (_e, manifest) => { - this.hlsjsCurrentLevel = manifest.firstLevel - this.hlsjsLevels = manifest.levels - }) - this.hlsjs.on(Hlsjs.Events.LEVEL_LOADED, (_e, level) => { - this.hlsjsCurrentLevel = level.levelId || (level as any).id - }) - this.networkInfoInterval = setInterval(() => { const p2pDownloadSpeed = this.arraySum(this.statsP2PBytes.pendingDownload) const p2pUploadSpeed = this.arraySum(this.statsP2PBytes.pendingUpload) -- cgit v1.2.3