+import Hlsjs from 'hls.js'
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 { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from 'p2p-media-loader-hlsjs'
-import { Events, Segment } from 'p2p-media-loader-core'
-import { timeToInt } from '../utils'
import { registerConfigPlugin, registerSourceHandler } from './hls-plugin'
-import * as Hlsjs from 'hls.js/dist/hls.light.js'
registerConfigPlugin(videojs)
registerSourceHandler(videojs)
clearInterval(this.networkInfoInterval)
}
+ getCurrentLevel () {
+ return this.hlsjs.levels[this.hlsjs.currentLevel]
+ }
+
+ getLiveLatency () {
+ // FIXME: typings
+ return Math.round((this.hlsjs as any).latency)
+ }
+
getHLSJS () {
return this.hlsjs
}
const options = this.player.tech(true).options_ as any
this.p2pEngine = options.hlsjsConfig.loader.getEngine()
- this.hlsjs.on(Hlsjs.Events.LEVEL_SWITCHING, (_: any, data: any) => {
- this.trigger('resolutionChange', { auto: this.hlsjs.autoLevelEnabled, resolutionId: data.height })
- })
-
this.p2pEngine.on(Events.SegmentError, (segment: Segment, err) => {
console.error('Segment error.', segment, err)
}
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.statsHTTPBytes.pendingUpload = []
return this.player.trigger('p2pInfo', {
+ source: 'p2p-media-loader',
http: {
downloadSpeed: httpDownloadSpeed,
uploadSpeed: httpUploadSpeed,
numPeers: this.statsP2PBytes.numPeers,
downloaded: this.statsP2PBytes.totalDownload,
uploaded: this.statsP2PBytes.totalUpload
- }
+ },
+ bandwidthEstimate: (this.hlsjs as any).bandwidthEstimate / 8
} as PlayerNetworkInfo)
}, this.CONSTANTS.INFO_SCHEDULER)
}