]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/p2p-media-loader/segment-validator.ts
Fix console error when watching a video
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / p2p-media-loader / segment-validator.ts
index 9add3518459d0a5831584f69fabee2c654424c50..4a0caec5e621cbb469978665513e7f513c2d5057 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) {
+  return async function segmentValidator (segment: Segment, _method: string, _peerId: string, 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,12 +23,12 @@ 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)
+      await segmentValidator(segment, _method, _peerId, retry + 1)
 
       return
     }