From bf1c3c78b0e2b70bb46168a9dec0d3fa0997ab14 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 Dec 2021 16:18:05 +0100 Subject: [PATCH] Hide P2P in player if disabled --- client/src/assets/player/peertube-player-manager.ts | 6 +++++- client/src/assets/player/peertube-videojs-typings.ts | 7 ++++++- .../player/videojs-components/p2p-info-button.ts | 10 +++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts index c27024beb..57cdfca28 100644 --- a/client/src/assets/player/peertube-player-manager.ts +++ b/client/src/assets/player/peertube-player-manager.ts @@ -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: {}, diff --git a/client/src/assets/player/peertube-videojs-typings.ts b/client/src/assets/player/peertube-videojs-typings.ts index 824ea058b..f97d7a208 100644 --- a/client/src/assets/player/peertube-videojs-typings.ts +++ b/client/src/assets/player/peertube-videojs-typings.ts @@ -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 } diff --git a/client/src/assets/player/videojs-components/p2p-info-button.ts b/client/src/assets/player/videojs-components/p2p-info-button.ts index 07ed18989..081dee1d3 100644 --- a/client/src/assets/player/videojs-components/p2p-info-button.ts +++ b/client/src/assets/player/videojs-components/p2p-info-button.ts @@ -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' })