diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-15 16:18:05 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-16 10:08:55 +0100 |
commit | bf1c3c78b0e2b70bb46168a9dec0d3fa0997ab14 (patch) | |
tree | f45c657bbff59f03df3cd547f65c8119f15fd6cb | |
parent | a9bfa85d2cdf13670aaced740da5b493fbeddfce (diff) | |
download | PeerTube-bf1c3c78b0e2b70bb46168a9dec0d3fa0997ab14.tar.gz PeerTube-bf1c3c78b0e2b70bb46168a9dec0d3fa0997ab14.tar.zst PeerTube-bf1c3c78b0e2b70bb46168a9dec0d3fa0997ab14.zip |
Hide P2P in player if disabled
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 { | |||
320 | controlBar: { | 320 | controlBar: { |
321 | children: this.getControlBarChildren(mode, { | 321 | children: this.getControlBarChildren(mode, { |
322 | videoShortUUID: commonOptions.videoShortUUID, | 322 | videoShortUUID: commonOptions.videoShortUUID, |
323 | p2pEnabled: commonOptions.p2pEnabled, | ||
323 | 324 | ||
324 | captions: commonOptions.captions, | 325 | captions: commonOptions.captions, |
325 | peertubeLink: commonOptions.peertubeLink, | 326 | peertubeLink: commonOptions.peertubeLink, |
@@ -452,6 +453,7 @@ export class PeertubePlayerManager { | |||
452 | } | 453 | } |
453 | 454 | ||
454 | private static getControlBarChildren (mode: PlayerMode, options: { | 455 | private static getControlBarChildren (mode: PlayerMode, options: { |
456 | p2pEnabled: boolean | ||
455 | videoShortUUID: string | 457 | videoShortUUID: string |
456 | 458 | ||
457 | peertubeLink: boolean | 459 | peertubeLink: boolean |
@@ -527,7 +529,9 @@ export class PeertubePlayerManager { | |||
527 | } | 529 | } |
528 | }, | 530 | }, |
529 | 531 | ||
530 | p2PInfoButton: {}, | 532 | p2PInfoButton: { |
533 | p2pEnabled: options.p2pEnabled | ||
534 | }, | ||
531 | 535 | ||
532 | muteToggle: {}, | 536 | muteToggle: {}, |
533 | volumeControl: {}, | 537 | 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 = { | |||
128 | shortUUID: string | 128 | shortUUID: string |
129 | } | 129 | } |
130 | 130 | ||
131 | type PeerTubeP2PInfoButtonOptions = { | ||
132 | p2pEnabled: boolean | ||
133 | } | ||
134 | |||
131 | type WebtorrentPluginOptions = { | 135 | type WebtorrentPluginOptions = { |
132 | playerElement: HTMLVideoElement | 136 | playerElement: HTMLVideoElement |
133 | 137 | ||
@@ -223,5 +227,6 @@ export { | |||
223 | PeerTubeResolution, | 227 | PeerTubeResolution, |
224 | VideoJSPluginOptions, | 228 | VideoJSPluginOptions, |
225 | LoadedQualityData, | 229 | LoadedQualityData, |
226 | PeerTubeLinkButtonOptions | 230 | PeerTubeLinkButtonOptions, |
231 | PeerTubeP2PInfoButtonOptions | ||
227 | } | 232 | } |
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 @@ | |||
1 | import { PlayerNetworkInfo } from '../peertube-videojs-typings' | ||
2 | import videojs from 'video.js' | 1 | import videojs from 'video.js' |
2 | import { PeerTubeP2PInfoButtonOptions, PlayerNetworkInfo } from '../peertube-videojs-typings' | ||
3 | import { bytes } from '../utils' | 3 | import { bytes } from '../utils' |
4 | 4 | ||
5 | const Button = videojs.getComponent('Button') | 5 | const Button = videojs.getComponent('Button') |
6 | class P2pInfoButton extends Button { | 6 | class P2pInfoButton extends Button { |
7 | 7 | ||
8 | constructor (player: videojs.Player, options?: PeerTubeP2PInfoButtonOptions) { | ||
9 | super(player, options as any) | ||
10 | } | ||
11 | |||
8 | createEl () { | 12 | createEl () { |
9 | const div = videojs.dom.createEl('div', { | 13 | const div = videojs.dom.createEl('div', { |
10 | className: 'vjs-peertube' | 14 | className: 'vjs-peertube' |
@@ -14,6 +18,10 @@ class P2pInfoButton extends Button { | |||
14 | }) as HTMLDivElement | 18 | }) as HTMLDivElement |
15 | div.appendChild(subDivWebtorrent) | 19 | div.appendChild(subDivWebtorrent) |
16 | 20 | ||
21 | // Stop here if P2P is not enabled | ||
22 | const p2pEnabled = (this.options_ as PeerTubeP2PInfoButtonOptions).p2pEnabled | ||
23 | if (!p2pEnabled) return div as HTMLButtonElement | ||
24 | |||
17 | const downloadIcon = videojs.dom.createEl('span', { | 25 | const downloadIcon = videojs.dom.createEl('span', { |
18 | className: 'icon icon-download' | 26 | className: 'icon icon-download' |
19 | }) | 27 | }) |