From bdbbd10347101ec6d47c44825f1436e613b0bf7a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 24 Oct 2024 16:11:54 +0200 Subject: [PATCH 1/2] fix: Add data to validator function --- packages/p2p-media-loader-core/src/p2p/peer.ts | 1 + packages/p2p-media-loader-core/src/types.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/p2p-media-loader-core/src/p2p/peer.ts b/packages/p2p-media-loader-core/src/p2p/peer.ts index 0b1288f9..d423d113 100644 --- a/packages/p2p-media-loader-core/src/p2p/peer.ts +++ b/packages/p2p-media-loader-core/src/p2p/peer.ts @@ -164,6 +164,7 @@ export class Peer { (await this.peerConfig.validateP2PSegment?.( request.segment.url, request.segment.byteRange, + request.data! )) ?? true; if (this.downloadingContext !== downloadingContext) return; diff --git a/packages/p2p-media-loader-core/src/types.ts b/packages/p2p-media-loader-core/src/types.ts index 644a9f86..0ff6554b 100644 --- a/packages/p2p-media-loader-core/src/types.ts +++ b/packages/p2p-media-loader-core/src/types.ts @@ -380,6 +380,7 @@ export type StreamConfig = { * Optional function to validate a P2P segment before fully integrating it into the playback buffer. * @param url URL of the segment to validate. * @param byteRange Optional byte range of the segment. + * @param data: Downloaded segment data. * @returns A promise that resolves with a boolean indicating if the segment is valid. * * @default @@ -387,7 +388,7 @@ export type StreamConfig = { * validateP2PSegment: undefined * ``` */ - validateP2PSegment?: (url: string, byteRange?: ByteRange) => Promise; + validateP2PSegment?: (url: string, byteRange: ByteRange | undefined, data: ArrayBuffer) => Promise; /** * Optional function to customize the setup of HTTP requests for segment downloads. From 2a572b0902ccc317e60f59bc0cef6007fd5afa53 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 24 Oct 2024 16:15:12 +0200 Subject: [PATCH 2/2] fix: Doc config typo --- packages/p2p-media-loader-core/src/p2p/peer.ts | 3 ++- packages/p2p-media-loader-core/src/types.ts | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/p2p-media-loader-core/src/p2p/peer.ts b/packages/p2p-media-loader-core/src/p2p/peer.ts index d423d113..7b6763b9 100644 --- a/packages/p2p-media-loader-core/src/p2p/peer.ts +++ b/packages/p2p-media-loader-core/src/p2p/peer.ts @@ -141,6 +141,7 @@ export class Peer { const { request, controls } = downloadingContext; const isWrongSegment = + !request.data || downloadingContext.request.segment.externalId !== command.i || downloadingContext.requestId !== command.r; @@ -164,7 +165,7 @@ export class Peer { (await this.peerConfig.validateP2PSegment?.( request.segment.url, request.segment.byteRange, - request.data! + request.data )) ?? true; if (this.downloadingContext !== downloadingContext) return; diff --git a/packages/p2p-media-loader-core/src/types.ts b/packages/p2p-media-loader-core/src/types.ts index 0ff6554b..ed9dc089 100644 --- a/packages/p2p-media-loader-core/src/types.ts +++ b/packages/p2p-media-loader-core/src/types.ts @@ -155,7 +155,6 @@ export type CommonCoreConfig = { * httpDownloadTimeWindow: 3000, * p2pDownloadTimeWindow: 6000, * swarmId: "custom swarm ID for video stream", - * cashedSegmentsCount: 1000, * } * ``` *