]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/p2p-media-loader/segment-validator.ts
Try to optimize sha segments fetching
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / p2p-media-loader / segment-validator.ts
index 9add3518459d0a5831584f69fabee2c654424c50..844956d6a6cb543ed441344af095dbfe91d9afb5 100644 (file)
@@ -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)