Constructs an instance of ShakaP2PEngine.
Optional
config: PartialShakaEngineConfigOptional configuration for customizing the P2P engine's behavior.
The Shaka Player library instance.
Configures and initializes the Shaka Player instance with predefined settings for optimal P2P performance.
The Shaka Player instance to configure.
Applies dynamic configuration updates to the P2P engine.
Configuration changes to apply.
// Assuming `shakaP2PEngine` is an instance of ShakaP2PEngine
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,
};
shakaP2PEngine.applyDynamicConfig(newDynamicConfig);
Retrieves the current configuration of the ShakaP2PEngine.
The configuration as a readonly object.
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
shakaP2PEngine.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.
Clean up and release all resources. Unregister all event handlers.
Static
registerRegisters plugins related to P2P functionality into the Shaka Player. Plugins must be registered before initializing the player to ensure proper integration.
The Shaka Player library. Defaults to the global Shaka Player instance if not provided.
Static
unregisterUnregister plugins related to P2P functionality from the Shaka Player.
The Shaka Player library. Defaults to the global Shaka Player instance if not provided.
Represents a P2P (peer-to-peer) engine for HLS (HTTP Live Streaming) to enhance media streaming efficiency. This class integrates P2P technologies into Shaka Player, 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