P2P Media Loader Documentation
    Preparing search index...

    Type Alias StreamConfig

    Configuration options for the Core functionality, including network and processing parameters.

    type StreamConfig = {
        isP2PUploadDisabled: boolean;
        isP2PDisabled: boolean;
        highDemandTimeWindow: number;
        httpDownloadTimeWindow: number;
        httpDownloadInitialTimeoutMs: number;
        p2pDownloadTimeWindow: number;
        simultaneousHttpDownloads: number;
        simultaneousP2PDownloads: number;
        webRtcMaxMessageSize: number;
        p2pNotReceivingBytesTimeoutMs: number;
        p2pInactiveLoaderDestroyTimeoutMs: number;
        httpNotReceivingBytesTimeoutMs: number;
        httpErrorRetries: number;
        p2pErrorRetries: number;
        announceTrackers: string[];
        rtcConfig: RTCConfiguration;
        trackerClientVersionPrefix: string;
        swarmId?: string;
        validateP2PSegment?: (
            url: string,
            byteRange: ByteRange | undefined,
            data: ArrayBuffer,
        ) => Promise<boolean>;
        validateHTTPSegment?: (
            url: string,
            byteRange: ByteRange | undefined,
            data: ArrayBuffer,
        ) => Promise<boolean>;
        httpRequestSetup?: (
            segmentUrl: string,
            segmentByteRange: ByteRange | undefined,
            requestAbortSignal: AbortSignal,
            requestByteRange: { start: number; end?: number } | undefined,
        ) => Promise<Request | undefined | null>;
    }
    Index

    Properties

    isP2PUploadDisabled: boolean

    Controls if peer-to-peer upload is disabled for the stream. If true, the stream only downloads segments without uploading to peers.

    isP2PUploadDisabled: false
    
    isP2PDisabled: boolean

    Controls whether peer-to-peer functionality is disabled for the stream.

    isP2PDisabled: false
    
    highDemandTimeWindow: number

    Defines the duration of the time window, in seconds, during which segments are pre-loaded to ensure smooth playback. This window helps prioritize the fetching of media segments that are imminent to playback.

    highDemandTimeWindow: 15
    
    httpDownloadTimeWindow: number

    Defines the time window, in seconds, for HTTP segment downloads. This property specifies the duration over which media segments are pre-fetched using HTTP requests.

    For a better P2P ratio, it is recommended to set this httpDownloadTimeWindow to be lower than p2pDownloadTimeWindow.

    NOTE: This setting only takes effect if there is at least one peer connection and the connected peer does not have the requested segments available to share via P2P.

    httpDownloadTimeWindow: 3000
    
    httpDownloadInitialTimeoutMs: number

    Time in milliseconds to delay the HTTP fallback for the very first segments. This gives the tracker time to discover peers when playback just started. A higher value gives a better chance to download the initial segments via P2P, thus improving the overall P2P ratio. However, setting this value too high can increase the playback startup time or even stall the playback if peers are not immediately available. If 0, HTTP fallback happens immediately.

    httpDownloadInitialTimeoutMs: 0
    
    p2pDownloadTimeWindow: number

    Defines the time window, in seconds, dedicated to pre-fetching media segments via Peer-to-Peer (P2P) downloads. This duration determines how much content is downloaded in advance using P2P connections to ensure smooth playback and reduce reliance on HTTP downloads.

    For a better P2P ratio, it is recommended to set this time window to be greater than httpDownloadTimeWindow to maximize P2P usage.

    p2pDownloadTimeWindow: 6000
    
    simultaneousHttpDownloads: number

    Maximum number of simultaneous HTTP downloads allowed.

    simultaneousHttpDownloads: 2
    
    simultaneousP2PDownloads: number

    Maximum number of simultaneous P2P downloads allowed.

    simultaneousP2PDownloads: 3
    
    webRtcMaxMessageSize: number

    Maximum message size for WebRTC communications, in bytes.

    webRtcMaxMessageSize: 64 * 1024 - 1
    
    p2pNotReceivingBytesTimeoutMs: number

    Timeout for not receiving bytes from P2P, in milliseconds.

    p2pNotReceivingBytesTimeoutMs: 2000
    
    p2pInactiveLoaderDestroyTimeoutMs: number

    Timeout for destroying the P2P loader if inactive, in milliseconds.

    p2pInactiveLoaderDestroyTimeoutMs: 30 * 1000
    
    httpNotReceivingBytesTimeoutMs: number

    Timeout for not receiving bytes from HTTP downloads, in milliseconds.

    httpNotReceivingBytesTimeoutMs: 3000
    
    httpErrorRetries: number

    Number of retries allowed after an HTTP error.

    httpErrorRetries: 3
    
    p2pErrorRetries: number

    Number of retries allowed after a P2P error.

    p2pErrorRetries: 3
    
    announceTrackers: string[]

    List of URLs to the WebTorrent trackers used for announcing and discovering peers (i.e. WebRTC signaling).

    WARNING: In the Safari browser, only the first tracker will be used. Safari has issues with multiple trackers, leading to problems with sending SDP messages for WebRTC signaling.

    The default trackers used are:

    [
    "wss://tracker.novage.com.ua",
    "wss://tracker.openwebtorrent.com",
    ]
    rtcConfig: RTCConfiguration

    Configuration for the RTC layer, used in WebRTC communication. This configuration specifies the STUN/TURN servers used by WebRTC to establish connections through NATs and firewalls.

    {
    "rtcConfig": {
    "iceServers": [
    { "urls": "stun:stun.l.google.com:19302" },
    { "urls": "stun:global.stun.twilio.com:3478" }
    ]
    }
    }
    trackerClientVersionPrefix: string

    Prefix to use for the WebTorrent client version in tracker communications. If undefined, the default version prefix is used, which is calculated based on the package version.

    trackerClientVersionPrefix: undefined
    
    swarmId?: string

    Optional unique identifier for the swarm, used to isolate peer pools by media stream. If undefined, the URL of the manifest is used as the swarm ID.

    swarmId: undefined
    
    validateP2PSegment?: (
        url: string,
        byteRange: ByteRange | undefined,
        data: ArrayBuffer,
    ) => Promise<boolean>

    Optional function to validate a P2P segment before fully integrating it into the playback buffer.

    Type Declaration

      • (
            url: string,
            byteRange: ByteRange | undefined,
            data: ArrayBuffer,
        ): Promise<boolean>
      • Parameters

        • url: string

          URL of the segment to validate.

        • byteRange: ByteRange | undefined

          Optional byte range of the segment.

        • data: ArrayBuffer

          Downloaded segment data.

        Returns Promise<boolean>

        A promise that resolves with a boolean indicating if the segment is valid.

    validateP2PSegment: undefined
    
    validateHTTPSegment?: (
        url: string,
        byteRange: ByteRange | undefined,
        data: ArrayBuffer,
    ) => Promise<boolean>

    Optional function to validate a HTTP segment before fully integrating it into the playback buffer.

    Type Declaration

      • (
            url: string,
            byteRange: ByteRange | undefined,
            data: ArrayBuffer,
        ): Promise<boolean>
      • Parameters

        • url: string

          URL of the segment to validate.

        • byteRange: ByteRange | undefined

          Optional byte range of the segment.

        • data: ArrayBuffer

          Downloaded segment data.

        Returns Promise<boolean>

        A promise that resolves with a boolean indicating if the segment is valid.

    validateHTTPSegment: undefined
    
    httpRequestSetup?: (
        segmentUrl: string,
        segmentByteRange: ByteRange | undefined,
        requestAbortSignal: AbortSignal,
        requestByteRange: { start: number; end?: number } | undefined,
    ) => Promise<Request | undefined | null>

    Optional function to customize the setup of HTTP requests for segment downloads.

    Type Declaration

      • (
            segmentUrl: string,
            segmentByteRange: ByteRange | undefined,
            requestAbortSignal: AbortSignal,
            requestByteRange: { start: number; end?: number } | undefined,
        ): Promise<Request | undefined | null>
      • Parameters

        • segmentUrl: string

          URL of the segment.

        • segmentByteRange: ByteRange | undefined

          The range of bytes requested for the segment.

        • requestAbortSignal: AbortSignal

          An abort signal to cancel the request if needed.

        • requestByteRange: { start: number; end?: number } | undefined

          Additional byte range for partial requests, if required.

        Returns Promise<Request | undefined | null>

        A promise that resolves with the configured request, or undefined if no customization should be made.

    httpRequestSetup: undefined