aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-02-22 13:48:09 +0100
committerChocobozzz <me@florianbigard.com>2022-02-22 13:48:09 +0100
commitf7298d0dcc247fe3be94ec1e00351942a079a44b (patch)
tree6bcb9935ab00101115be003c988a8211fc260d8c /client/src/assets
parent0d9a327df33e42a0f34caaf2cbff5f74e4d78426 (diff)
parentac5f679ad60fc48db6d9a9534a8ac5fd20eda36f (diff)
downloadPeerTube-f7298d0dcc247fe3be94ec1e00351942a079a44b.tar.gz
PeerTube-f7298d0dcc247fe3be94ec1e00351942a079a44b.tar.zst
PeerTube-f7298d0dcc247fe3be94ec1e00351942a079a44b.zip
Merge branch 'release/4.1.0' into develop
Diffstat (limited to 'client/src/assets')
-rw-r--r--client/src/assets/player/p2p-media-loader/segment-url-builder.ts4
-rw-r--r--client/src/assets/player/peertube-player-options-builder.ts61
2 files changed, 44 insertions, 21 deletions
diff --git a/client/src/assets/player/p2p-media-loader/segment-url-builder.ts b/client/src/assets/player/p2p-media-loader/segment-url-builder.ts
index 5ddc81ff6..9d324078a 100644
--- a/client/src/assets/player/p2p-media-loader/segment-url-builder.ts
+++ b/client/src/assets/player/p2p-media-loader/segment-url-builder.ts
@@ -1,10 +1,10 @@
1import { Segment } from '@peertube/p2p-media-loader-core' 1import { Segment } from '@peertube/p2p-media-loader-core'
2import { RedundancyUrlManager } from './redundancy-url-manager' 2import { RedundancyUrlManager } from './redundancy-url-manager'
3 3
4function segmentUrlBuilderFactory (redundancyUrlManager: RedundancyUrlManager, requiredSegmentsPriority: number) { 4function segmentUrlBuilderFactory (redundancyUrlManager: RedundancyUrlManager, useOriginPriority: number) {
5 return function segmentBuilder (segment: Segment) { 5 return function segmentBuilder (segment: Segment) {
6 // Don't use redundancy for high priority segments 6 // Don't use redundancy for high priority segments
7 if (segment.priority <= requiredSegmentsPriority) return segment.url 7 if (segment.priority <= useOriginPriority) return segment.url
8 8
9 return redundancyUrlManager.buildUrl(segment.url) 9 return redundancyUrlManager.buildUrl(segment.url)
10 } 10 }
diff --git a/client/src/assets/player/peertube-player-options-builder.ts b/client/src/assets/player/peertube-player-options-builder.ts
index 901f6cd3b..71be5ccff 100644
--- a/client/src/assets/player/peertube-player-options-builder.ts
+++ b/client/src/assets/player/peertube-player-options-builder.ts
@@ -19,6 +19,7 @@ import {
19 VideoJSPluginOptions 19 VideoJSPluginOptions
20} from './peertube-videojs-typings' 20} from './peertube-videojs-typings'
21import { buildVideoOrPlaylistEmbed, getRtcConfig, isIOS, isSafari } from './utils' 21import { buildVideoOrPlaylistEmbed, getRtcConfig, isIOS, isSafari } from './utils'
22import { HybridLoaderSettings } from '@peertube/p2p-media-loader-core'
22 23
23export type PlayerMode = 'webtorrent' | 'p2p-media-loader' 24export type PlayerMode = 'webtorrent' | 'p2p-media-loader'
24 25
@@ -198,9 +199,6 @@ export class PeertubePlayerOptionsBuilder {
198 const p2pMediaLoaderOptions = this.options.p2pMediaLoader 199 const p2pMediaLoaderOptions = this.options.p2pMediaLoader
199 const commonOptions = this.options.common 200 const commonOptions = this.options.common
200 201
201 const trackerAnnounce = p2pMediaLoaderOptions.trackerAnnounce
202 .filter(t => t.startsWith('ws'))
203
204 const redundancyUrlManager = new RedundancyUrlManager(this.options.p2pMediaLoader.redundancyBaseUrls) 202 const redundancyUrlManager = new RedundancyUrlManager(this.options.p2pMediaLoader.redundancyBaseUrls)
205 203
206 const p2pMediaLoader: P2PMediaLoaderPluginOptions = { 204 const p2pMediaLoader: P2PMediaLoaderPluginOptions = {
@@ -210,23 +208,8 @@ export class PeertubePlayerOptionsBuilder {
210 src: p2pMediaLoaderOptions.playlistUrl 208 src: p2pMediaLoaderOptions.playlistUrl
211 } 209 }
212 210
213 let consumeOnly = false
214 if ((navigator as any)?.connection?.type === 'cellular') {
215 console.log('We are on a cellular connection: disabling seeding.')
216 consumeOnly = true
217 }
218
219 const p2pMediaLoaderConfig: HlsJsEngineSettings = { 211 const p2pMediaLoaderConfig: HlsJsEngineSettings = {
220 loader: { 212 loader: this.getP2PMediaLoaderOptions(redundancyUrlManager),
221 trackerAnnounce,
222 segmentValidator: segmentValidatorFactory(this.options.p2pMediaLoader.segmentsSha256Url, this.options.common.isLive),
223 rtcConfig: getRtcConfig(),
224 requiredSegmentsPriority: 1,
225 simultaneousHttpDownloads: 1,
226 segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager, 1),
227 useP2P: commonOptions.p2pEnabled,
228 consumeOnly
229 },
230 segments: { 213 segments: {
231 swarmId: p2pMediaLoaderOptions.playlistUrl 214 swarmId: p2pMediaLoaderOptions.playlistUrl
232 } 215 }
@@ -256,6 +239,46 @@ export class PeertubePlayerOptionsBuilder {
256 return toAssign 239 return toAssign
257 } 240 }
258 241
242 private getP2PMediaLoaderOptions (redundancyUrlManager: RedundancyUrlManager): Partial<HybridLoaderSettings> {
243 let consumeOnly = false
244 if ((navigator as any)?.connection?.type === 'cellular') {
245 console.log('We are on a cellular connection: disabling seeding.')
246 consumeOnly = true
247 }
248
249 const trackerAnnounce = this.options.p2pMediaLoader.trackerAnnounce
250 .filter(t => t.startsWith('ws'))
251
252 const specificLiveOrVODOptions = this.options.common.isLive
253 ? { // Live
254 requiredSegmentsPriority: 1
255 }
256 : { // VOD
257 requiredSegmentsPriority: 3,
258
259 cachedSegmentExpiration: 86400000,
260 cachedSegmentsCount: 100,
261
262 httpDownloadMaxPriority: 9,
263 httpDownloadProbability: 0.06,
264 httpDownloadProbabilitySkipIfNoPeers: true,
265
266 p2pDownloadMaxPriority: 50
267 }
268
269 return {
270 trackerAnnounce,
271 segmentValidator: segmentValidatorFactory(this.options.p2pMediaLoader.segmentsSha256Url, this.options.common.isLive),
272 rtcConfig: getRtcConfig(),
273 simultaneousHttpDownloads: 1,
274 segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager, 1),
275 useP2P: this.options.common.p2pEnabled,
276 consumeOnly,
277
278 ...specificLiveOrVODOptions
279 }
280 }
281
259 private getHLSOptions (p2pMediaLoaderConfig: HlsJsEngineSettings) { 282 private getHLSOptions (p2pMediaLoaderConfig: HlsJsEngineSettings) {
260 const base = { 283 const base = {
261 capLevelToPlayerSize: true, 284 capLevelToPlayerSize: true,