From 25b7c847249c2b7f7b309b14eecb03dd024db649 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 10 Nov 2020 14:21:26 +0100 Subject: Try to optimize sha segments fetching --- client/src/assets/player/p2p-media-loader/segment-validator.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'client/src/assets/player/p2p-media-loader') diff --git a/client/src/assets/player/p2p-media-loader/segment-validator.ts b/client/src/assets/player/p2p-media-loader/segment-validator.ts index 9add35184..844956d6a 100644 --- a/client/src/assets/player/p2p-media-loader/segment-validator.ts +++ b/client/src/assets/player/p2p-media-loader/segment-validator.ts @@ -6,11 +6,14 @@ type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string const maxRetries = 3 -function segmentValidatorFactory (segmentsSha256Url: string) { +function segmentValidatorFactory (segmentsSha256Url: string, isLive: boolean) { let segmentsJSON = fetchSha256Segments(segmentsSha256Url) const regex = /bytes=(\d+)-(\d+)/ return async function segmentValidator (segment: Segment, retry = 1) { + // Wait for hash generation from the server + if (isLive) await wait(1000) + const filename = basename(segment.url) const segmentValue = (await segmentsJSON)[filename] @@ -20,10 +23,10 @@ function segmentValidatorFactory (segmentsSha256Url: string) { } if (!segmentValue) { - await wait(1000) - console.log('Refetching sha segments for %s.', filename) + await wait(1000) + segmentsJSON = fetchSha256Segments(segmentsSha256Url) await segmentValidator(segment, retry + 1) -- cgit v1.2.3