From 4c280004ce62bf11ddb091854c28f1e1d54a54d6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 7 Feb 2019 15:08:19 +0100 Subject: Use a single file instead of segments for HLS --- .../assets/player/p2p-media-loader/segment-validator.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'client') 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 8f4922daa..72c32f9e0 100644 --- a/client/src/assets/player/p2p-media-loader/segment-validator.ts +++ b/client/src/assets/player/p2p-media-loader/segment-validator.ts @@ -3,18 +3,25 @@ import { basename } from 'path' function segmentValidatorFactory (segmentsSha256Url: string) { const segmentsJSON = fetchSha256Segments(segmentsSha256Url) + const regex = /bytes=(\d+)-(\d+)/ return async function segmentValidator (segment: Segment) { - const segmentName = basename(segment.url) + const filename = basename(segment.url) + const captured = regex.exec(segment.range) - const hashShouldBe = (await segmentsJSON)[segmentName] + const range = captured[1] + '-' + captured[2] + + const hashShouldBe = (await segmentsJSON)[filename][range] if (hashShouldBe === undefined) { - throw new Error(`Unknown segment name ${segmentName} in segment validator`) + throw new Error(`Unknown segment name ${filename}/${range} in segment validator`) } const calculatedSha = bufferToEx(await sha256(segment.data)) if (calculatedSha !== hashShouldBe) { - throw new Error(`Hashes does not correspond for segment ${segmentName} (expected: ${hashShouldBe} instead of ${calculatedSha})`) + throw new Error( + `Hashes does not correspond for segment ${filename}/${range}` + + `(expected: ${hashShouldBe} instead of ${calculatedSha})` + ) } } } -- cgit v1.2.3