aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets')
-rw-r--r--client/src/assets/player/p2p-media-loader/segment-validator.ts15
1 files changed, 10 insertions, 5 deletions
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 @@
1import { wait } from '@root-helpers/utils'
1import { Segment } from 'p2p-media-loader-core' 2import { Segment } from 'p2p-media-loader-core'
2import { basename } from 'path' 3import { basename } from 'path'
3 4
4type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } } 5type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } }
5 6
7const maxRetries = 3
8
6function segmentValidatorFactory (segmentsSha256Url: string) { 9function segmentValidatorFactory (segmentsSha256Url: string) {
7 let segmentsJSON = fetchSha256Segments(segmentsSha256Url) 10 let segmentsJSON = fetchSha256Segments(segmentsSha256Url)
8 const regex = /bytes=(\d+)-(\d+)/ 11 const regex = /bytes=(\d+)-(\d+)/
9 12
10 return async function segmentValidator (segment: Segment, canRefetchSegmentHashes = true) { 13 return async function segmentValidator (segment: Segment, retry = 1) {
11 const filename = basename(segment.url) 14 const filename = basename(segment.url)
12 15
13 const segmentValue = (await segmentsJSON)[filename] 16 const segmentValue = (await segmentsJSON)[filename]
14 17
15 if (!segmentValue && !canRefetchSegmentHashes) { 18 if (!segmentValue && retry > maxRetries) {
16 throw new Error(`Unknown segment name ${filename} in segment validator`) 19 throw new Error(`Unknown segment name ${filename} in segment validator`)
17 } 20 }
18 21
19 if (!segmentValue) { 22 if (!segmentValue) {
20 console.log('Refetching sha segments.') 23 await wait(1000)
24
25 console.log('Refetching sha segments for %s.', filename)
21 26
22 // Refetch
23 segmentsJSON = fetchSha256Segments(segmentsSha256Url) 27 segmentsJSON = fetchSha256Segments(segmentsSha256Url)
24 segmentValidator(segment, false) 28 await segmentValidator(segment, retry + 1)
29
25 return 30 return
26 } 31 }
27 32