Skip to content

Commit

Permalink
Merge pull request #426 from Chocobozzz/feature/validator
Browse files Browse the repository at this point in the history
Add missing data param in segment validator
  • Loading branch information
DimaDemchenko authored Oct 28, 2024
2 parents fe59c09 + 2a572b0 commit 4afd085
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/p2p-media-loader-core/src/p2p/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -164,6 +165,7 @@ export class Peer {
(await this.peerConfig.validateP2PSegment?.(
request.segment.url,
request.segment.byteRange,
request.data
)) ?? true;

if (this.downloadingContext !== downloadingContext) return;
Expand Down
4 changes: 2 additions & 2 deletions packages/p2p-media-loader-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ export type CommonCoreConfig = {
* httpDownloadTimeWindow: 3000,
* p2pDownloadTimeWindow: 6000,
* swarmId: "custom swarm ID for video stream",
* cashedSegmentsCount: 1000,
* }
* ```
*
Expand Down Expand Up @@ -380,14 +379,15 @@ 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
* ```typescript
* validateP2PSegment: undefined
* ```
*/
validateP2PSegment?: (url: string, byteRange?: ByteRange) => Promise<boolean>;
validateP2PSegment?: (url: string, byteRange: ByteRange | undefined, data: ArrayBuffer) => Promise<boolean>;

/**
* Optional function to customize the setup of HTTP requests for segment downloads.
Expand Down

0 comments on commit 4afd085

Please sign in to comment.