1
0
Fork 0

Add more live latency info in stats for nerds

This commit is contained in:
Chocobozzz 2023-10-30 11:08:09 +01:00
parent a12d94f30d
commit 04bd31bc18
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 22 additions and 5 deletions

View File

@ -87,16 +87,26 @@ class P2pMediaLoaderPlugin extends Plugin {
super.dispose()
}
// ---------------------------------------------------------------------------
getCurrentLevel () {
if (!this.hlsjs) return undefined
return this.hlsjs.levels[this.hlsjs.currentLevel]
}
// ---------------------------------------------------------------------------
getLiveLatency () {
return Math.round(this.hlsjs.latency)
}
getLiveLatencyFromEdge () {
return Math.round(this.hlsjs.latency - this.hlsjs.targetLatency)
}
// ---------------------------------------------------------------------------
getHLSJS () {
return this.hlsjs
}

View File

@ -1,6 +1,6 @@
import { PeerTubePlayerLoadOptions, WebVideoPluginOptions } from '../../types'
type ConstructorOptions = Pick<PeerTubePlayerLoadOptions, 'videoFileToken' | 'webVideo' | 'hls' | 'startTime'>
type ConstructorOptions = Pick<PeerTubePlayerLoadOptions, 'videoFileToken' | 'webVideo' | 'hls'>
export class WebVideoOptionsBuilder {

View File

@ -163,9 +163,11 @@ class StatsCard extends Component {
let progress: number
let latency: string
let latencyFromEdge: string
if (this.options_.videoIsLive) {
latency = secondsToTime(p2pMediaLoader.getLiveLatency())
latencyFromEdge = secondsToTime(p2pMediaLoader.getLiveLatencyFromEdge())
} else {
progress = this.player().bufferedPercent()
}
@ -176,6 +178,7 @@ class StatsCard extends Component {
codecs,
buffer,
latency,
latencyFromEdge,
progress
}
}
@ -261,9 +264,10 @@ class StatsCard extends Component {
buffer: string
latency?: string
latencyFromEdge?: string
colorSpace?: string
}) {
const { playerNetworkInfo, progress, colorSpace, codecs, resolution, buffer, latency } = options
const { playerNetworkInfo, progress, colorSpace, codecs, resolution, buffer, latency, latencyFromEdge } = options
const { downloadedFromServer, downloadedFromPeers } = playerNetworkInfo
const player = this.player()
@ -311,16 +315,18 @@ class StatsCard extends Component {
this.setInfoValue(this.volume, volume)
this.setInfoValue(this.codecs, codecs)
this.setInfoValue(this.color, colorSpace)
this.setInfoValue(this.transferred, totalTransferred)
this.setInfoValue(this.connection, playerNetworkInfo.averageBandwidth)
this.setInfoValue(this.network, networkActivity)
this.setInfoValue(this.transferred, totalTransferred)
this.setInfoValue(this.download, downloadBreakdown)
this.setInfoValue(this.bufferProgress, bufferProgress)
this.setInfoValue(this.bufferState, buffer)
this.setInfoValue(this.liveLatency, latency)
if (latency && latencyFromEdge) {
this.setInfoValue(this.liveLatency, player.localize('{1} (from edge: {2})', [ latency, latencyFromEdge ]))
}
}
private setInfoValue (el: InfoElement, value: string) {

View File

@ -75,7 +75,8 @@ const playerKeys = {
'Incorrect password, please enter a correct password': 'Incorrect password, please enter a correct password',
'Cancel': 'Cancel',
'Up Next': 'Up Next',
'Autoplay is suspended': 'Autoplay is suspended'
'Autoplay is suspended': 'Autoplay is suspended',
'{1} (from edge: {2})': '{1} (from edge: {2})'
}
Object.assign(playerKeys, videojs)