From 210856a7be4631540791bad027fb3ef0f7a51f14 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 10 Nov 2020 14:15:59 +0100 Subject: Try to fix live segments check --- .../assets/player/p2p-media-loader/segment-validator.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 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 fa6e6df1d..9add35184 100644 --- a/client/src/assets/player/p2p-media-loader/segment-validator.ts +++ b/client/src/assets/player/p2p-media-loader/segment-validator.ts @@ -1,27 +1,32 @@ +import { wait } from '@root-helpers/utils' import { Segment } from 'p2p-media-loader-core' import { basename } from 'path' type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } } +const maxRetries = 3 + function segmentValidatorFactory (segmentsSha256Url: string) { let segmentsJSON = fetchSha256Segments(segmentsSha256Url) const regex = /bytes=(\d+)-(\d+)/ - return async function segmentValidator (segment: Segment, canRefetchSegmentHashes = true) { + return async function segmentValidator (segment: Segment, retry = 1) { const filename = basename(segment.url) const segmentValue = (await segmentsJSON)[filename] - if (!segmentValue && !canRefetchSegmentHashes) { + if (!segmentValue && retry > maxRetries) { throw new Error(`Unknown segment name ${filename} in segment validator`) } if (!segmentValue) { - console.log('Refetching sha segments.') + await wait(1000) + + console.log('Refetching sha segments for %s.', filename) - // Refetch segmentsJSON = fetchSha256Segments(segmentsSha256Url) - segmentValidator(segment, false) + await segmentValidator(segment, retry + 1) + return } -- cgit v1.2.3