diff options
author | Chocobozzz <me@florianbigard.com> | 2020-11-10 14:21:26 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-11-10 14:21:26 +0100 |
commit | 25b7c847249c2b7f7b309b14eecb03dd024db649 (patch) | |
tree | bad822d4a10f902a23ad29ca5569e4f8b824446f /client/src/assets/player/p2p-media-loader | |
parent | 210856a7be4631540791bad027fb3ef0f7a51f14 (diff) | |
download | PeerTube-25b7c847249c2b7f7b309b14eecb03dd024db649.tar.gz PeerTube-25b7c847249c2b7f7b309b14eecb03dd024db649.tar.zst PeerTube-25b7c847249c2b7f7b309b14eecb03dd024db649.zip |
Try to optimize sha segments fetching
Diffstat (limited to 'client/src/assets/player/p2p-media-loader')
-rw-r--r-- | client/src/assets/player/p2p-media-loader/segment-validator.ts | 9 |
1 files changed, 6 insertions, 3 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 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 | |||
6 | 6 | ||
7 | const maxRetries = 3 | 7 | const maxRetries = 3 |
8 | 8 | ||
9 | function segmentValidatorFactory (segmentsSha256Url: string) { | 9 | function segmentValidatorFactory (segmentsSha256Url: string, isLive: boolean) { |
10 | let segmentsJSON = fetchSha256Segments(segmentsSha256Url) | 10 | let segmentsJSON = fetchSha256Segments(segmentsSha256Url) |
11 | const regex = /bytes=(\d+)-(\d+)/ | 11 | const regex = /bytes=(\d+)-(\d+)/ |
12 | 12 | ||
13 | return async function segmentValidator (segment: Segment, retry = 1) { | 13 | return async function segmentValidator (segment: Segment, retry = 1) { |
14 | // Wait for hash generation from the server | ||
15 | if (isLive) await wait(1000) | ||
16 | |||
14 | const filename = basename(segment.url) | 17 | const filename = basename(segment.url) |
15 | 18 | ||
16 | const segmentValue = (await segmentsJSON)[filename] | 19 | const segmentValue = (await segmentsJSON)[filename] |
@@ -20,10 +23,10 @@ function segmentValidatorFactory (segmentsSha256Url: string) { | |||
20 | } | 23 | } |
21 | 24 | ||
22 | if (!segmentValue) { | 25 | if (!segmentValue) { |
23 | await wait(1000) | ||
24 | |||
25 | console.log('Refetching sha segments for %s.', filename) | 26 | console.log('Refetching sha segments for %s.', filename) |
26 | 27 | ||
28 | await wait(1000) | ||
29 | |||
27 | segmentsJSON = fetchSha256Segments(segmentsSha256Url) | 30 | segmentsJSON = fetchSha256Segments(segmentsSha256Url) |
28 | await segmentValidator(segment, retry + 1) | 31 | await segmentValidator(segment, retry + 1) |
29 | 32 | ||