diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-15 15:58:10 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-16 10:08:55 +0100 |
commit | a9bfa85d2cdf13670aaced740da5b493fbeddfce (patch) | |
tree | 3781c9218d4cc7786b6589365c0efbed2151703d /client/src/assets/player | |
parent | c77fdc605b3ccc1ab6890f889d8200fbe9372949 (diff) | |
download | PeerTube-a9bfa85d2cdf13670aaced740da5b493fbeddfce.tar.gz PeerTube-a9bfa85d2cdf13670aaced740da5b493fbeddfce.tar.zst PeerTube-a9bfa85d2cdf13670aaced740da5b493fbeddfce.zip |
Add ability for admins to set default p2p policy
Diffstat (limited to 'client/src/assets/player')
5 files changed, 19 insertions, 21 deletions
diff --git a/client/src/assets/player/peertube-player-local-storage.ts b/client/src/assets/player/peertube-player-local-storage.ts index d4cbda3a9..d9dacfba5 100644 --- a/client/src/assets/player/peertube-player-local-storage.ts +++ b/client/src/assets/player/peertube-player-local-storage.ts | |||
@@ -10,14 +10,6 @@ function getStoredVolume () { | |||
10 | return undefined | 10 | return undefined |
11 | } | 11 | } |
12 | 12 | ||
13 | function getStoredP2PEnabled (): boolean { | ||
14 | const value = getLocalStorage('webtorrent_enabled') | ||
15 | if (value !== null && value !== undefined) return value === 'true' | ||
16 | |||
17 | // By default webtorrent is enabled | ||
18 | return true | ||
19 | } | ||
20 | |||
21 | function getStoredMute () { | 13 | function getStoredMute () { |
22 | const value = getLocalStorage('mute') | 14 | const value = getLocalStorage('mute') |
23 | if (value !== null && value !== undefined) return value === 'true' | 15 | if (value !== null && value !== undefined) return value === 'true' |
@@ -123,7 +115,6 @@ function cleanupVideoWatch () { | |||
123 | 115 | ||
124 | export { | 116 | export { |
125 | getStoredVolume, | 117 | getStoredVolume, |
126 | getStoredP2PEnabled, | ||
127 | getStoredMute, | 118 | getStoredMute, |
128 | getStoredTheater, | 119 | getStoredTheater, |
129 | saveVolumeInStore, | 120 | saveVolumeInStore, |
diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts index 3e6398f50..c27024beb 100644 --- a/client/src/assets/player/peertube-player-manager.ts +++ b/client/src/assets/player/peertube-player-manager.ts | |||
@@ -31,7 +31,7 @@ import { copyToClipboard } from '../../root-helpers/utils' | |||
31 | import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager' | 31 | import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager' |
32 | import { segmentUrlBuilderFactory } from './p2p-media-loader/segment-url-builder' | 32 | import { segmentUrlBuilderFactory } from './p2p-media-loader/segment-url-builder' |
33 | import { segmentValidatorFactory } from './p2p-media-loader/segment-validator' | 33 | import { segmentValidatorFactory } from './p2p-media-loader/segment-validator' |
34 | import { getAverageBandwidthInStore, getStoredP2PEnabled, saveAverageBandwidth } from './peertube-player-local-storage' | 34 | import { getAverageBandwidthInStore, saveAverageBandwidth } from './peertube-player-local-storage' |
35 | import { | 35 | import { |
36 | NextPreviousVideoButtonOptions, | 36 | NextPreviousVideoButtonOptions, |
37 | P2PMediaLoaderPluginOptions, | 37 | P2PMediaLoaderPluginOptions, |
@@ -86,6 +86,7 @@ export interface CommonOptions extends CustomizationOptions { | |||
86 | onPlayerElementChange: (element: HTMLVideoElement) => void | 86 | onPlayerElementChange: (element: HTMLVideoElement) => void |
87 | 87 | ||
88 | autoplay: boolean | 88 | autoplay: boolean |
89 | p2pEnabled: boolean | ||
89 | 90 | ||
90 | nextVideo?: () => void | 91 | nextVideo?: () => void |
91 | hasNextVideo?: () => boolean | 92 | hasNextVideo?: () => boolean |
@@ -374,7 +375,7 @@ export class PeertubePlayerManager { | |||
374 | requiredSegmentsPriority: 1, | 375 | requiredSegmentsPriority: 1, |
375 | simultaneousHttpDownloads: 1, | 376 | simultaneousHttpDownloads: 1, |
376 | segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager, 1), | 377 | segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager, 1), |
377 | useP2P: getStoredP2PEnabled(), | 378 | useP2P: commonOptions.p2pEnabled, |
378 | consumeOnly | 379 | consumeOnly |
379 | }, | 380 | }, |
380 | segments: { | 381 | segments: { |
@@ -437,6 +438,7 @@ export class PeertubePlayerManager { | |||
437 | 438 | ||
438 | const webtorrent = { | 439 | const webtorrent = { |
439 | autoplay, | 440 | autoplay, |
441 | playerRefusedP2P: commonOptions.p2pEnabled === false, | ||
440 | videoDuration: commonOptions.videoDuration, | 442 | videoDuration: commonOptions.videoDuration, |
441 | playerElement: commonOptions.playerElement, | 443 | playerElement: commonOptions.playerElement, |
442 | videoFiles: webtorrentOptions.videoFiles.length !== 0 | 444 | videoFiles: webtorrentOptions.videoFiles.length !== 0 |
diff --git a/client/src/assets/player/peertube-videojs-typings.ts b/client/src/assets/player/peertube-videojs-typings.ts index ea39ac44d..824ea058b 100644 --- a/client/src/assets/player/peertube-videojs-typings.ts +++ b/client/src/assets/player/peertube-videojs-typings.ts | |||
@@ -137,6 +137,8 @@ type WebtorrentPluginOptions = { | |||
137 | videoFiles: VideoFile[] | 137 | videoFiles: VideoFile[] |
138 | 138 | ||
139 | startTime: number | string | 139 | startTime: number | string |
140 | |||
141 | playerRefusedP2P: boolean | ||
140 | } | 142 | } |
141 | 143 | ||
142 | type P2PMediaLoaderPluginOptions = { | 144 | type P2PMediaLoaderPluginOptions = { |
diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts index 18380d950..7e25e3067 100644 --- a/client/src/assets/player/utils.ts +++ b/client/src/assets/player/utils.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { VideoFile } from '@shared/models' | 1 | import { HTMLServerConfig, Video, VideoFile } from '@shared/models' |
2 | 2 | ||
3 | function toTitleCase (str: string) { | 3 | function toTitleCase (str: string) { |
4 | return str.charAt(0).toUpperCase() + str.slice(1) | 4 | return str.charAt(0).toUpperCase() + str.slice(1) |
@@ -8,6 +8,13 @@ function isWebRTCDisabled () { | |||
8 | return !!((window as any).RTCPeerConnection || (window as any).mozRTCPeerConnection || (window as any).webkitRTCPeerConnection) === false | 8 | return !!((window as any).RTCPeerConnection || (window as any).mozRTCPeerConnection || (window as any).webkitRTCPeerConnection) === false |
9 | } | 9 | } |
10 | 10 | ||
11 | function isP2PEnabled (video: Video, config: HTMLServerConfig, userP2PEnabled: boolean) { | ||
12 | if (video.isLocal && config.tracker.enabled === false) return false | ||
13 | if (isWebRTCDisabled()) return false | ||
14 | |||
15 | return userP2PEnabled | ||
16 | } | ||
17 | |||
11 | function isIOS () { | 18 | function isIOS () { |
12 | if (/iPad|iPhone|iPod/.test(navigator.platform)) { | 19 | if (/iPad|iPhone|iPod/.test(navigator.platform)) { |
13 | return true | 20 | return true |
@@ -97,6 +104,7 @@ export { | |||
97 | getRtcConfig, | 104 | getRtcConfig, |
98 | toTitleCase, | 105 | toTitleCase, |
99 | isWebRTCDisabled, | 106 | isWebRTCDisabled, |
107 | isP2PEnabled, | ||
100 | 108 | ||
101 | buildVideoOrPlaylistEmbed, | 109 | buildVideoOrPlaylistEmbed, |
102 | videoFileMaxByResolution, | 110 | videoFileMaxByResolution, |
diff --git a/client/src/assets/player/webtorrent/webtorrent-plugin.ts b/client/src/assets/player/webtorrent/webtorrent-plugin.ts index 1a1cd7f1a..2b9390206 100644 --- a/client/src/assets/player/webtorrent/webtorrent-plugin.ts +++ b/client/src/assets/player/webtorrent/webtorrent-plugin.ts | |||
@@ -2,13 +2,7 @@ import videojs from 'video.js' | |||
2 | import * as WebTorrent from 'webtorrent' | 2 | import * as WebTorrent from 'webtorrent' |
3 | import { timeToInt } from '@shared/core-utils' | 3 | import { timeToInt } from '@shared/core-utils' |
4 | import { VideoFile } from '@shared/models' | 4 | import { VideoFile } from '@shared/models' |
5 | import { | 5 | import { getAverageBandwidthInStore, getStoredMute, getStoredVolume, saveAverageBandwidth } from '../peertube-player-local-storage' |
6 | getAverageBandwidthInStore, | ||
7 | getStoredMute, | ||
8 | getStoredP2PEnabled, | ||
9 | getStoredVolume, | ||
10 | saveAverageBandwidth | ||
11 | } from '../peertube-player-local-storage' | ||
12 | import { PeerTubeResolution, PlayerNetworkInfo, WebtorrentPluginOptions } from '../peertube-videojs-typings' | 6 | import { PeerTubeResolution, PlayerNetworkInfo, WebtorrentPluginOptions } from '../peertube-videojs-typings' |
13 | import { getRtcConfig, isIOS, videoFileMaxByResolution, videoFileMinByResolution } from '../utils' | 7 | import { getRtcConfig, isIOS, videoFileMaxByResolution, videoFileMinByResolution } from '../utils' |
14 | import { PeertubeChunkStore } from './peertube-chunk-store' | 8 | import { PeertubeChunkStore } from './peertube-chunk-store' |
@@ -74,9 +68,10 @@ class WebTorrentPlugin extends Plugin { | |||
74 | 68 | ||
75 | this.startTime = timeToInt(options.startTime) | 69 | this.startTime = timeToInt(options.startTime) |
76 | 70 | ||
77 | // Disable auto play on iOS | 71 | // Custom autoplay handled by webtorrent because we lazy play the video |
78 | this.autoplay = options.autoplay | 72 | this.autoplay = options.autoplay |
79 | this.playerRefusedP2P = !getStoredP2PEnabled() | 73 | |
74 | this.playerRefusedP2P = options.playerRefusedP2P | ||
80 | 75 | ||
81 | this.videoFiles = options.videoFiles | 76 | this.videoFiles = options.videoFiles |
82 | this.videoDuration = options.videoDuration | 77 | this.videoDuration = options.videoDuration |