diff --git a/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts b/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts index a2f7e676d..9cb6344a9 100644 --- a/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts +++ b/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts @@ -15,6 +15,8 @@ export class SegmentValidator { private destroyed = false + private segmentJSONPromise: Promise + constructor (private readonly options: { serverUrl: string segmentsSha256Url: string @@ -23,15 +25,16 @@ export class SegmentValidator { requiresPassword: boolean videoPassword: () => string }) { - } async validate (segment: Segment, _method: string, _peerId: string, retry = 1) { if (this.destroyed) return + this.loadSha256SegmentsPromiseIfNeeded() + const filename = basename(removeQueryParams(segment.url)) - const segmentValue = (await this.fetchSha256Segments())[filename] + const segmentValue = (await this.segmentJSONPromise)[filename] if (!segmentValue && retry > maxRetries) { throw new Error(`Unknown segment name ${filename} in segment validator`) @@ -42,6 +45,8 @@ export class SegmentValidator { await wait(500) + this.loadSha256SegmentsPromise() + await this.validate(segment, _method, _peerId, retry + 1) return @@ -76,6 +81,16 @@ export class SegmentValidator { this.destroyed = true } + private loadSha256SegmentsPromiseIfNeeded () { + if (this.segmentJSONPromise) return + + this.loadSha256SegmentsPromise() + } + + private loadSha256SegmentsPromise () { + this.segmentJSONPromise = this.fetchSha256Segments() + } + private fetchSha256Segments (): Promise { let headers: { [ id: string ]: string } = {} diff --git a/client/src/assets/player/shared/player-options-builder/hls-options-builder.ts b/client/src/assets/player/shared/player-options-builder/hls-options-builder.ts index 10df2db5d..1658f776c 100644 --- a/client/src/assets/player/shared/player-options-builder/hls-options-builder.ts +++ b/client/src/assets/player/shared/player-options-builder/hls-options-builder.ts @@ -108,7 +108,6 @@ export class HLSOptionsBuilder { if (!isSameOrigin(this.options.serverUrl, url)) return if (requiresPassword) xhr.setRequestHeader('x-peertube-video-password', this.options.videoPassword()) - else xhr.setRequestHeader('Authorization', this.options.authorizationHeader()) },