Constructs an instance of HlsJsP2PEngine.
Optional
config: PartialHlsJsP2PEngineConfigOptional configuration for P2P engine setup.
Static
injectEnhances a given Hls.js class by injecting additional P2P (peer-to-peer) functionalities.
Optional
config: Partial<HlsConfig> & { Adds an event listener for the specified event.
The name of the event to listen for.
The callback function to be invoked when the event is triggered.
// Listening for a segment being successfully loaded
p2pEngine.addEventListener('onSegmentLoaded', (details) => {
console.log('Segment Loaded:', details);
});
Removes an event listener for the specified event.
The name of the event.
The callback function that was previously added.
Returns the configuration of the HLS.js P2P engine.
A readonly version of the HlsJsP2PEngineConfig.
Applies dynamic configuration updates to the P2P engine.
Configuration changes to apply.
// Assuming `hlsP2PEngine` is an instance of HlsJsP2PEngine
const newDynamicConfig = {
core: {
// Increase the number of cached segments to 1000
cachedSegmentsCount: 1000,
// 50 minutes of segments will be downloaded further through HTTP connections if P2P fails
httpDownloadTimeWindow: 3000,
// 100 minutes of segments will be downloaded further through P2P connections
p2pDownloadTimeWindow: 6000,
};
hlsP2PEngine.applyDynamicConfig(newDynamicConfig);
Sets the HLS instance for handling media.
Represents a P2P (peer-to-peer) engine for HLS (HTTP Live Streaming) to enhance media streaming efficiency. This class integrates P2P technologies into HLS.js, enabling the distribution of media segments via a peer network alongside traditional HTTP fetching. It reduces server bandwidth costs and improves scalability by sharing the load across multiple clients.
The engine manages core functionalities such as segment fetching, segment management, peer connection management, and event handling related to the P2P and HLS processes.
Example