Hide P2P in player if disabled

This commit is contained in:
Chocobozzz 2021-12-15 16:18:05 +01:00
parent a9bfa85d2c
commit bf1c3c78b0
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 20 additions and 3 deletions

View File

@ -320,6 +320,7 @@ export class PeertubePlayerManager {
controlBar: {
children: this.getControlBarChildren(mode, {
videoShortUUID: commonOptions.videoShortUUID,
p2pEnabled: commonOptions.p2pEnabled,
captions: commonOptions.captions,
peertubeLink: commonOptions.peertubeLink,
@ -452,6 +453,7 @@ export class PeertubePlayerManager {
}
private static getControlBarChildren (mode: PlayerMode, options: {
p2pEnabled: boolean
videoShortUUID: string
peertubeLink: boolean
@ -527,7 +529,9 @@ export class PeertubePlayerManager {
}
},
p2PInfoButton: {},
p2PInfoButton: {
p2pEnabled: options.p2pEnabled
},
muteToggle: {},
volumeControl: {},

View File

@ -128,6 +128,10 @@ type PeerTubeLinkButtonOptions = {
shortUUID: string
}
type PeerTubeP2PInfoButtonOptions = {
p2pEnabled: boolean
}
type WebtorrentPluginOptions = {
playerElement: HTMLVideoElement
@ -223,5 +227,6 @@ export {
PeerTubeResolution,
VideoJSPluginOptions,
LoadedQualityData,
PeerTubeLinkButtonOptions
PeerTubeLinkButtonOptions,
PeerTubeP2PInfoButtonOptions
}

View File

@ -1,10 +1,14 @@
import { PlayerNetworkInfo } from '../peertube-videojs-typings'
import videojs from 'video.js'
import { PeerTubeP2PInfoButtonOptions, PlayerNetworkInfo } from '../peertube-videojs-typings'
import { bytes } from '../utils'
const Button = videojs.getComponent('Button')
class P2pInfoButton extends Button {
constructor (player: videojs.Player, options?: PeerTubeP2PInfoButtonOptions) {
super(player, options as any)
}
createEl () {
const div = videojs.dom.createEl('div', {
className: 'vjs-peertube'
@ -14,6 +18,10 @@ class P2pInfoButton extends Button {
}) as HTMLDivElement
div.appendChild(subDivWebtorrent)
// Stop here if P2P is not enabled
const p2pEnabled = (this.options_ as PeerTubeP2PInfoButtonOptions).p2pEnabled
if (!p2pEnabled) return div as HTMLButtonElement
const downloadIcon = videojs.dom.createEl('span', {
className: 'icon icon-download'
})