Core class for managing media streams loading via P2P.

Type Parameters

Constructors

  • Constructs a new Core instance with optional initial configuration.

    Type Parameters

    Parameters

    • Optionalconfig: Partial<CoreConfig>

      Optional partial configuration to override default settings.

    Returns Core<TStream>

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

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

    Parameters

    Returns void

    // 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.

    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.

    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.

    Parameters

    • url: string

      The full URL to the manifest response.

    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.

    Parameters

    • stream: TStream

      The stream to potentially add to the map.

    Returns void

  • Updates the segments associated with a specific stream.

    Parameters

    • streamRuntimeId: string

      The runtime identifier of the stream to update.

    • OptionaladdSegments: Iterable<Segment>

      Optional segments to add to the stream.

    • OptionalremoveSegmentIds: 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. 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 if the manifest response URL is not defined.
  • 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.

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

    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.

    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 and clearing stored segments.

    Returns void