diff --git a/docs/v1.0/assets/highlight.css b/docs/v1.0/assets/highlight.css index ae684ee1..7f3d87ba 100644 --- a/docs/v1.0/assets/highlight.css +++ b/docs/v1.0/assets/highlight.css @@ -5,22 +5,22 @@ --dark-hl-1: #D4D4D4; --light-hl-2: #A31515; --dark-hl-2: #CE9178; - --light-hl-3: #AF00DB; - --dark-hl-3: #C586C0; - --light-hl-4: #001080; - --dark-hl-4: #9CDCFE; - --light-hl-5: #0000FF; - --dark-hl-5: #569CD6; - --light-hl-6: #0070C1; - --dark-hl-6: #4FC1FF; - --light-hl-7: #800000; - --dark-hl-7: #808080; + --light-hl-3: #008000; + --dark-hl-3: #6A9955; + --light-hl-4: #AF00DB; + --dark-hl-4: #C586C0; + --light-hl-5: #001080; + --dark-hl-5: #9CDCFE; + --light-hl-6: #0000FF; + --dark-hl-6: #569CD6; + --light-hl-7: #0070C1; + --dark-hl-7: #4FC1FF; --light-hl-8: #800000; - --dark-hl-8: #569CD6; - --light-hl-9: #E50000; - --dark-hl-9: #9CDCFE; - --light-hl-10: #008000; - --dark-hl-10: #6A9955; + --dark-hl-8: #808080; + --light-hl-9: #800000; + --dark-hl-9: #569CD6; + --light-hl-10: #E50000; + --dark-hl-10: #9CDCFE; --light-hl-11: #000000FF; --dark-hl-11: #D4D4D4; --light-hl-12: #0000FF; diff --git a/docs/v1.0/classes/p2p_media_loader_core.Core.html b/docs/v1.0/classes/p2p_media_loader_core.Core.html index bf64b2d1..a017e6f3 100644 --- a/docs/v1.0/classes/p2p_media_loader_core.Core.html +++ b/docs/v1.0/classes/p2p_media_loader_core.Core.html @@ -157,7 +157,7 @@ --md-sys-color-surface-container-highest: #e9e1d9 }

Core class for managing media streams loading via P2P.

-

Type Parameters

Constructors

Type Parameters

Constructors

Properties

Methods

getConfig @@ -178,61 +178,61 @@ destroy

Constructors

  • Constructs a new Core instance with optional initial configuration.

    Type Parameters

    Parameters

    • Optional config: Partial<CoreConfig>

      Optional partial configuration to override default settings.

      -

    Returns Core<TStream>

    Example

    // Create a Core instance with custom configuration for HTTP and P2P downloads.
    const core = new Core({
    simultaneousHttpDownloads: 5,
    simultaneousP2PDownloads: 5,
    httpErrorRetries: 5,
    p2pErrorRetries: 5
    }); +

Returns Core<TStream>

Example

// Create a Core instance with custom configuration for HTTP and P2P downloads.
const core = new Core({
simultaneousHttpDownloads: 5,
simultaneousP2PDownloads: 5,
httpErrorRetries: 5,
p2pErrorRetries: 5
});
-

Example

// Create a Core instance using the default configuration.
const core = new Core(); +

Example

// Create a Core instance using the default configuration.
const core = new Core();
-

Properties

DEFAULT_COMMON_CORE_CONFIG: CommonCoreConfig = ...

Default configuration for common core settings.

-
DEFAULT_STREAM_CONFIG: StreamConfig = ...

Default configuration for stream settings.

-

Methods

Properties

DEFAULT_COMMON_CORE_CONFIG: CommonCoreConfig = ...

Default configuration for common core settings.

+
DEFAULT_STREAM_CONFIG: StreamConfig = ...

Default configuration for stream settings.

+

Methods

  • Applies a set of dynamic configuration updates to the core, merging with the existing configuration.

    +
  • Applies a set of dynamic configuration updates to the core, merging with the existing configuration.

    Parameters

    Returns void

    Example

    // Example of dynamically updating the download time windows and timeout settings.
    const dynamicConfig = {
    httpDownloadTimeWindowMs: 60, // Set HTTP download time window to 60 seconds
    p2pDownloadTimeWindowMs: 60, // Set P2P download time window to 60 seconds
    httpNotReceivingBytesTimeoutMs: 1500, // Set HTTP timeout to 1500 milliseconds
    p2pNotReceivingBytesTimeoutMs: 1500 // Set P2P timeout to 1500 milliseconds
    };
    core.applyDynamicConfig(dynamicConfig); +

Returns void

Example

// Example of dynamically updating the download time windows and timeout settings.
const dynamicConfig = {
httpDownloadTimeWindowMs: 60, // Set HTTP download time window to 60 seconds
p2pDownloadTimeWindowMs: 60, // Set P2P download time window to 60 seconds
httpNotReceivingBytesTimeoutMs: 1500, // Set HTTP timeout to 1500 milliseconds
p2pNotReceivingBytesTimeoutMs: 1500 // Set P2P timeout to 1500 milliseconds
};
core.applyDynamicConfig(dynamicConfig);
-
  • Adds an event listener for the specified event type on the core event target.

    +
  • Adds an event listener for the specified event type on the core event target.

    Type Parameters

    Parameters

    • eventName: K

      The name of the event to listen for.

    • listener: CoreEventMap[K]

      The callback function to invoke when the event is fired.

      -

    Returns void

  • Removes an event listener for the specified event type on the core event target.

    +

Returns void

  • Removes an event listener for the specified event type on the core event target.

    Type Parameters

    Parameters

    • eventName: K

      The name of the event to listen for.

    • listener: CoreEventMap[K]

      The callback function to be removed.

      -

    Returns void

  • Sets the response URL for the manifest, stripping any query parameters.

    +

Returns void

  • Sets the response URL for the manifest, stripping any query parameters.

    Parameters

    • url: string

      The full URL to the manifest response.

      -

    Returns void

  • Checks if a segment is already stored within the core.

    +

Returns void

  • Checks if a segment is already stored within the core.

    Parameters

    • segmentRuntimeId: string

      The runtime identifier of the segment to check.

    Returns boolean

    true if the segment is present, otherwise false.

    -
  • Retrieves a specific stream by its runtime identifier, if it exists.

    Parameters

    • streamRuntimeId: string

      The runtime identifier of the stream to retrieve.

    Returns undefined | StreamWithSegments<TStream>

    The stream with its segments, or undefined if not found.

    -
  • Ensures a stream exists in the map; adds it if it does not.

    +
  • Ensures a stream exists in the map; adds it if it does not.

    Parameters

    • stream: TStream

      The stream to potentially add to the map.

      -

    Returns void

  • Updates the segments associated with a specific stream.

    +

Returns void

  • Updates the segments associated with a specific stream.

    Parameters

    • streamRuntimeId: string

      The runtime identifier of the stream to update.

    • Optional addSegments: Iterable<Segment>

      Optional segments to add to the stream.

    • Optional removeSegmentIds: Iterable<string>

      Optional segment IDs to remove from the stream.

      -

    Returns void

  • Loads a segment given its runtime identifier and invokes the provided callbacks during the process. +

Returns void

  • Loads a segment given its runtime identifier and invokes the provided callbacks during the process. Initializes segment storage if it has not been initialized yet.

    Parameters

    • segmentRuntimeId: string

      The runtime identifier of the segment to load.

    • callbacks: EngineCallbacks

      The callbacks to be invoked during segment loading.

    Returns Promise<void>

    Throws

    • Throws if the manifest response URL is not defined.
    -
  • Aborts the loading of a segment specified by its runtime identifier.

    +
  • Aborts the loading of a segment specified by its runtime identifier.

    Parameters

    • segmentRuntimeId: string

      The runtime identifier of the segment whose loading is to be aborted.

      -

    Returns void

  • Updates the playback parameters while play head moves, specifically position and playback rate, for stream loaders.

    +

Returns void

  • Updates the playback parameters while play head moves, specifically position and playback rate, for stream loaders.

    Parameters

    • position: number

      The new position in the stream, in seconds.

    • rate: number

      The new playback rate.

      -

    Returns void

  • Sets the active level bitrate, used for adjusting quality levels in adaptive streaming. +

Returns void

  • Sets the active level bitrate, used for adjusting quality levels in adaptive streaming. Notifies the stream loaders if a change occurs.

    Parameters

    • bitrate: number

      The new bitrate to set as active.

      -

    Returns void

  • Updates the 'isLive' status of the stream.

    +

Returns void

  • Updates the 'isLive' status of the stream.

    Parameters

    • isLive: boolean

      Boolean indicating whether the stream is live.

      -

    Returns void

  • Identify if a segment is loadable by the P2P core based on the segment's stream type and configuration.

    +

Returns void

  • Identify if a segment is loadable by the P2P core based on the segment's stream type and configuration.

    Parameters

    • segmentRuntimeId: string

      Segment runtime identifier to check.

    Returns boolean

    true if the segment is loadable by the P2P core, otherwise false.

    -
  • Cleans up resources used by the Core instance, including destroying any active stream loaders +

  • Cleans up resources used by the Core instance, including destroying any active stream loaders and clearing stored segments.

    -

    Returns void

Custom error class for errors that occur during core network requests.

-

Hierarchy

  • Error
    • CoreRequestError

Constructors

Hierarchy

  • Error
    • CoreRequestError

Constructors

Properties

Constructors

  • Constructs a new CoreRequestError.

    Parameters

    • type: "failed" | "aborted"

      The type of the error, either 'failed' or 'aborted'.

      -

    Returns CoreRequestError

Properties

type: "failed" | "aborted"

The type of the error, either 'failed' or 'aborted'.

-

Represents an error that can occur during the request process, with a timestamp for when the error occurred.

Type Parameters

Hierarchy

  • Error
    • RequestError

Constructors

Hierarchy

  • Error
    • RequestError

Constructors

Properties

Constructors

Properties

timestamp: number

Error timestamp.

-
type: T

The specific error type.

-
ByteRange: {
    start: number;
    end: number;
}

Represents a range of bytes, used for specifying a segment of data to download.

Type declaration

  • start: number

    The starting byte index of the range.

  • end: number

    The ending byte index of the range.

    -
CommonCoreConfig: {
    cachedSegmentExpiration?: number;
    cachedSegmentsCount: number;
}

Represents the configuration for the Core functionality that is common to all streams.

Type declaration

  • Optional cachedSegmentExpiration?: number

    Time after which a cached segment expires, in seconds. If set to undefined, the cacheSegmentExpiration is disabled for VOD streams, and a default value (20 minutes) is used for live streams.

    -

    Default

    cachedSegmentExpiration: undefined
    +

    Default

    cachedSegmentExpiration: undefined
     
  • cachedSegmentsCount: number

    Maximum number of segments to store in the cache. Has to be less then httpDownloadTimeWindow and p2pDownloadTimeWindow. If set to 0, the cache is unlimited.

    Default

    cachedSegmentsCount: 0
     
    -
DefinedCoreConfig: CommonCoreConfig & {
    mainStream: StreamConfig;
    secondaryStream: StreamConfig;
}

Represents a defined Core configuration with specific settings for the main and secondary streams.

Type declaration

  • mainStream: StreamConfig

    Configuration for the main stream.

  • secondaryStream: StreamConfig

    Configuration for the secondary stream.

    -
DownloadSource: "http" | "p2p"

Specifies the source of a download within a media streaming context.

"http" - Indicates that the segment was downloaded using the HTTP protocol.

"p2p"- Indicates that the segment was downloaded through a peer-to-peer network.

-
DynamicCoreConfig: Partial<Pick<CoreConfig, DynamicStreamProperties>> & Partial<CommonCoreConfig> & {
    mainStream?: Partial<Pick<StreamConfig, DynamicStreamProperties>>;
    secondaryStream?: Partial<Pick<StreamConfig, DynamicStreamProperties>>;
}

Represents a dynamically modifiable configuration, allowing updates to selected CoreConfig properties at runtime.

Type declaration

Example

const dynamicConfig: DynamicCoreConfig = {
core: {
cachedSegmentsCount: 200,
},
mainStream: {
swarmId: "custom swarm ID for video stream",
p2pDownloadTimeWindow: 6000,
},
secondaryStream: {
swarmId: "custom swarm ID for audio stream",
p2pDownloadTimeWindow: 3000,
}
}; +

Example

const dynamicConfig: DynamicCoreConfig = {
core: {
cachedSegmentsCount: 200,
},
mainStream: {
swarmId: "custom swarm ID for video stream",
p2pDownloadTimeWindow: 6000,
},
secondaryStream: {
swarmId: "custom swarm ID for audio stream",
p2pDownloadTimeWindow: 3000,
}
};
-
DynamicStreamProperties: "highDemandTimeWindow" | "httpDownloadTimeWindow" | "p2pDownloadTimeWindow" | "simultaneousHttpDownloads" | "simultaneousP2PDownloads" | "webRtcMaxMessageSize" | "p2pNotReceivingBytesTimeoutMs" | "p2pInactiveLoaderDestroyTimeoutMs" | "httpNotReceivingBytesTimeoutMs" | "httpErrorRetries" | "p2pErrorRetries" | "validateP2PSegment" | "httpRequestSetup" | "isP2PDisabled"

Represents a set of properties that can be dynamically modified at runtime.

-
HttpRequestErrorType: "http-error" | "http-bytes-mismatch" | "http-unexpected-status-code"

Defines the types of errors specific to HTTP requests.

-
PeerDetails: {
    peerId: string;
}

Represents the details of a peer in a peer-to-peer network.

Type declaration

  • peerId: string

    The unique identifier for a peer in the network.

    -
PeerRequestErrorType: "peer-response-bytes-length-mismatch" | "peer-protocol-violation" | "peer-segment-absent" | "peer-closed" | "p2p-segment-validation-failed"

Defines the types of errors specific to peer-to-peer requests.

-
RequestAbortErrorType: "abort" | "bytes-receiving-timeout"

Defines the types of errors that can occur during a request abortion process.

-

Enumerates all possible request error types, including HTTP and peer-related errors.

-
SegmentResponse: {
    data: ArrayBuffer;
    bandwidth: number;
}

Represents the response from a segment request, including the data and measured bandwidth.

Type declaration

  • data: ArrayBuffer

    Segment data as an ArrayBuffer.

  • bandwidth: number

    Measured bandwidth for the segment download, in bytes per second.

    -
SegmentWithStream<TStream>: Segment & {
    stream: StreamWithSegments<TStream>;
}

Extends a Segment with a reference to its associated stream.

-

Type Parameters

Type declaration

StreamConfig: {
    isP2PDisabled: boolean;
    highDemandTimeWindow: number;
    httpDownloadTimeWindow: 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, byteRange?) => Promise<boolean>);
    httpRequestSetup?: ((segmentUrl, segmentByteRange, requestAbortSignal, requestByteRange) => Promise<Request | undefined | null>);
}

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

Type declaration

  • isP2PDisabled: boolean

    Indicates whether Peer-to-Peer (P2P) functionality is disabled for the stream. If set to true, P2P functionality is disabled for the stream.

    -

    Default

    isP2PDisabled: false
    +

    Default

    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.

    @@ -212,27 +212,27 @@

    Default

    {
  • 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.

    -

    Default

    trackerClientVersionPrefix: undefined
    +

    Default

    trackerClientVersionPrefix: undefined
     
  • Optional 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.

    -

    Default

    swarmId: undefined
    +

    Default

    swarmId: undefined
     
  • Optional validateP2PSegment?: ((url, byteRange?) => Promise<boolean>)

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

    Returns

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

    -

    Default

    validateP2PSegment: undefined
    +

    Default

    validateP2PSegment: undefined
     
      • (url, byteRange?): Promise<boolean>
      • Parameters

        • url: string

          URL of the segment to validate.

        • Optional byteRange: ByteRange

          Optional byte range of the segment.

        Returns Promise<boolean>

  • Optional httpRequestSetup?: ((segmentUrl, segmentByteRange, requestAbortSignal, requestByteRange) => Promise<Request | undefined | null>)

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

    Returns

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

    -

    Default

    httpRequestSetup: undefined
    +

    Default

    httpRequestSetup: undefined
     
      • (segmentUrl, segmentByteRange, requestAbortSignal, requestByteRange): 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>

StreamType: "main" | "secondary"

Represents the types of streams available, either primary (main) or secondary.

-
StreamWithSegments<TStream>: TStream & {
    segments: Map<string, SegmentWithStream<TStream>>;
}

Represents a stream that includes multiple segments, each associated with the stream.

Type Parameters

  • TStream extends Stream = Stream

    Type of the underlying stream data structure.

    -

Type declaration

DynamicHlsJsP2PEngineConfig: {
    core?: DynamicCoreConfig;
}

Type for specifying dynamic configuration options that can be changed at runtime for the P2P engine's core.

Type declaration

HlsJsP2PEngineConfig: {
    core: CoreConfig;
}

Represents the complete configuration for HlsJsP2PEngine.

Type declaration

HlsWithP2PConfig<HlsType>: ConstructorParameters<HlsType>[0] & {
    p2p?: PartialHlsJsP2PEngineConfig & {
        onHlsJsCreated?: ((hls) => void);
    };
}

Configuration type for HLS instances that includes P2P settings, augmenting standard HLS configuration with P2P capabilities.

Type Parameters

  • HlsType extends (abstract new () => unknown)

    A constructor type that produces an HLS instance.

    -

Type declaration

HlsWithP2PInstance<HlsType>: HlsType & {
    p2pEngine: HlsJsP2PEngine;
}

Extends a generic HLS type to include the P2P engine, integrating P2P capabilities directly into the HLS instance.

Type Parameters

  • HlsType

    The base HLS type that is being extended.

Type declaration

PartialHlsJsP2PEngineConfig: Partial<Omit<HlsJsP2PEngineConfig, "core">> & {
    core?: Partial<CoreConfig>;
}

Allows for partial configuration of HlsJsP2PEngine, useful for providing overrides or partial updates.

Type declaration

  • Optional core?: Partial<CoreConfig>

    Partial core config

    -
DynamicShakaP2PEngineConfig: {
    core?: DynamicCoreConfig;
}

Type for specifying dynamic configuration options that can be changed at runtime for the P2P engine's core.

Type declaration

PartialShakaEngineConfig: Partial<Omit<ShakaP2PEngineConfig, "core">> & {
    core?: Partial<CoreConfig>;
}

Allows for partial configuration settings for the Shaka P2P Engine.

Type declaration

  • Optional core?: Partial<CoreConfig>

    Partial core config

    -
ShakaP2PEngineConfig: {
    core: CoreConfig;
}

Represents the complete configuration for ShakaP2PEngine.

Type declaration