Static
Readonly
DEFAULT_Default configuration for common core settings.
+Static
Readonly
DEFAULT_Default configuration for stream settings.
+Retrieves the current configuration for the core instance, ensuring immutability.
+A deep readonly version of the core configuration.
+Applies a set of dynamic configuration updates to the core, merging with the existing configuration.
+A set of configuration changes to apply.
+// Example of dynamically updating the download time windows and timeout settings.
const dynamicConfig = {
httpDownloadTimeWindow: 60, // Set HTTP download time window to 60 seconds
p2pDownloadTimeWindow: 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.
+The name of the event to listen for.
+The callback function to invoke when the event is fired.
+Removes an event listener for the specified event type on the core event target.
+The name of the event to listen for.
+The callback function to be removed.
+Retrieves a specific stream by its runtime identifier, if it exists.
+The runtime identifier of the stream to retrieve.
+The stream with its segments, or undefined
if not found.
Ensures a stream exists in the map; adds it if it does not.
+The stream to potentially add to the map.
+Updates the segments associated with a specific stream.
+The runtime identifier of the stream to update.
+Optional
addSegments: Iterable<Segment, any, any>Optional segments to add to the stream.
+Optional
removeSegmentIds: Iterable<string, any, any>Optional segment IDs to remove from the stream.
+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.
+The runtime identifier of the segment to load.
+The callbacks to be invoked during segment loading.
+Identify if a segment is loadable by the P2P core based on the segment's stream type and configuration.
+Segment runtime identifier to check.
+true
if the segment is loadable by the P2P core, otherwise false
.
Custom error class for errors that occur during core network requests.
+Constructs a new CoreRequestError.
+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.
+The specific type of request error.
+Constructs a new RequestError.
+The specific error type.
+Optional
message: stringOptional message describing the error.
+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.
+// Creating an instance of HlsJsP2PEngine with custom configuration
const hlsP2PEngine = new HlsJsP2PEngine({
core: {
highDemandTimeWindow: 30, // 30 seconds
simultaneousHttpDownloads: 3,
webRtcMaxMessageSize: 64 * 1024, // 64 KB
p2pNotReceivingBytesTimeoutMs: 10000, // 10 seconds
p2pInactiveLoaderDestroyTimeoutMs: 15000, // 15 seconds
httpNotReceivingBytesTimeoutMs: 8000, // 8 seconds
httpErrorRetries: 2,
p2pErrorRetries: 2,
announceTrackers: ["wss://personal.tracker.com"],
rtcConfig: {
iceServers: [{ urls: "stun:personal.stun.com" }]
},
swarmId: "example-swarm-id"
}
});
+
+
+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 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.
+// Initializing the ShakaP2PEngine with custom configuration
const shakaP2PEngine = new ShakaP2PEngine({
core: {
highDemandTimeWindow: 30, // 30 seconds
simultaneousHttpDownloads: 3,
webRtcMaxMessageSize: 64 * 1024, // 64 KB
p2pNotReceivingBytesTimeoutMs: 10000, // 10 seconds
p2pInactiveLoaderDestroyTimeoutMs: 15000, // 15 seconds
httpNotReceivingBytesTimeoutMs: 8000, // 8 seconds
httpErrorRetries: 2,
p2pErrorRetries: 2,
announceTrackers: ["wss://personal.tracker.com"],
rtcConfig: {
iceServers: [{ urls: "stun:personal.stun.com" }]
},
swarmId: "example-swarm-id"
}
});
+
+
+Constructs an instance of ShakaP2PEngine.
+Optional
config: PartialShakaEngineConfigOptional configuration for customizing the P2P engine's behavior.
+The Shaka Player library instance.
+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.
+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
unregisterP2P Media Loader is an open-source JavaScript library that leverages modern web browser features, such as HTML5 video and WebRTC, to enable media delivery over peer-to-peer (P2P) networks. It integrates smoothly with many popular HTML5 video players and works entirely without browser plugins or add-ons. Experience it in action with the demo.
+P2P Media Loader can be bundled in your project as an npm package or used through a CDN. Below are examples of both methods.
+To include P2P Media Loader in your project using npm, follow these steps:
+Install the package via npm:
+For HLS.js integration:
+npm install p2p-media-loader-hlsjs
+
+
+For Shaka Player integration:
+npm install p2p-media-loader-shaka
+
+
+Provide Node.js polyfills
+To ensure the P2P Media Loader works correctly in a browser environment, you must provide Node.js polyfills required by bittorrent-tracker dependency.
+Vite configuration example:
+// vite.config.ts
import { defineConfig } from "vite";
import { nodePolyfills } from "vite-plugin-node-polyfills";
export default defineConfig({
plugins: [nodePolyfills()],
});
+
+
+Webpack configuration example:
+// webpack.config.mjs
import NodePolyfillPlugin from "node-polyfill-webpack-plugin";
export default {
plugins: [new NodePolyfillPlugin({ additionalAliases: ["process"] })],
};
+
+
+Import and use it in your project:
+HLS.js integration:
+import Hls from "hls.js";
import { HlsJsP2PEngine } from "p2p-media-loader-hlsjs";
const HlsWithP2P = HlsJsP2PEngine.injectMixin(Hls);
+
+
+Shaka Player integration:
+import shaka from "shaka-player/dist/shaka-player.ui";
import { ShakaP2PEngine } from "p2p-media-loader-shaka";
ShakaP2PEngine.registerPlugins(shaka);
+
+
+For more examples with npm packages, you may check our React demo
+P2P Media Loader supports many players that use Hls.js as media engine. Lets pick Vidstack player for extended hlsjs example:
+<!doctype html>
<html>
<head>
<!-- Include Hls.js library from CDN -->
<script src="https://cdn.jsdelivr.net/npm/hls.js@~1/dist/hls.min.js"></script>
<!-- Import map for P2P Media Loader modules -->
<script type="importmap">
{
"imports": {
"p2p-media-loader-core": "https://cdn.jsdelivr.net/npm/p2p-media-loader-core@^2/dist/p2p-media-loader-core.es.min.js",
"p2p-media-loader-hlsjs": "https://cdn.jsdelivr.net/npm/p2p-media-loader-hlsjs@^2/dist/p2p-media-loader-hlsjs.es.min.js"
}
}
</script>
<!-- Include Vidstack player stylesheets -->
<link rel="stylesheet" href="https://cdn.vidstack.io/player/theme.css" />
<link rel="stylesheet" href="https://cdn.vidstack.io/player/video.css" />
<!-- Include Vidstack player library from CDN -->
<script src="https://cdn.vidstack.io/player" type="module"></script>
<!-- Module script to initialize Vidstack player with P2P Media Loader -->
<script type="module">
import { HlsJsP2PEngine } from "p2p-media-loader-hlsjs";
const player = document.querySelector("media-player");
// Inject P2P capabilities into Hls.js
const HlsWithP2P = HlsJsP2PEngine.injectMixin(window.Hls);
player.addEventListener("provider-change", (event) => {
const provider = event.detail;
// Check if the provider is HLS
if (provider?.type === "hls") {
provider.library = HlsWithP2P;
provider.config = {
p2p: {
core: {
swarmId: "Optional custom swarm ID for stream",
// other P2P engine config parameters go here
},
onHlsJsCreated: (hls) => {
hls.p2pEngine.addEventListener("onPeerConnect", (params) => {
console.log("Peer connected:", params.peerId);
});
// Subscribe to P2P engine and Hls.js events here
},
},
};
}
});
</script>
</head>
<body>
<div style="width: 800px">
<!-- Vidstack media player with HLS stream -->
<media-player src="streamUrl">
<media-provider></media-provider>
<media-video-layout></media-video-layout>
</media-player>
</div>
</body>
</html>
+
+
+<script type="module">
import { HlsJsP2PEngine } from "p2p-media-loader-hlsjs";
const videoElement = document.querySelector("#video");
const HlsWithP2P = HlsJsP2PEngine.injectMixin(window.Hls);
const hls = new HlsWithP2P({
p2p: {
core: {
swarmId: "Optional custom swarm ID for stream",
// Other P2P engine config parameters go here
},
onHlsJsCreated(hls) {
hls.p2pEngine.addEventListener("onPeerConnect", (params) => {
console.log("Peer connected:", params.peerId);
});
// Subscribe to P2P engine and Hls.js events here
},
},
});
hls.attachMedia(videoElement);
hls.loadSource(streamUrl);
</script>
+
+
+<script type="module">
import { HlsJsP2PEngine } from "p2p-media-loader-hlsjs";
window.Hls = HlsJsP2PEngine.injectMixin(window.Hls);
const player = new Playerjs({
id: "player",
hlsconfig: {
p2p: {
core: {
swarmId: "Optional custom swarm ID for stream",
// Other P2P engine config parameters go here
},
onHlsJsCreated: (hls) => {
// Subscribe to P2P engine and Hls.js events here
hls.p2pEngine.addEventListener("onPeerConnect", (details) => {
console.log(`Connected to peer ${details.peerId})`);
});
},
},
},
});
</script>
+
+
+<script type="module">
import { HlsJsP2PEngine } from "p2p-media-loader-hlsjs";
const videoContainer = document.querySelector("#player");
const player = new DPlayer({
container: videoContainer,
video: {
url: "",
type: "customHls",
customType: {
customHls: (video) => {
const HlsWithP2P = HlsJsP2PEngine.injectMixin(window.Hls);
const hls = new HlsWithP2P({
p2p: {
core: {
swarmId: "Optional custom swarm ID for stream",
// Other P2P engine config parameters go here
},
},
});
hls.attachMedia(video);
hls.loadSource(streamUrl);
},
},
},
});
player.play();
</script>
+
+
+<script type="module">
import { HlsJsP2PEngine } from "p2p-media-loader-hlsjs";
const engine = new HlsJsP2PEngine({
core: {
swarmId: "Optional custom swarm ID for stream",
// Other P2P engine config parameters go here
},
});
const player = new Clappr.Player({
source: streamUrl,
plugins: [LevelSelector], // https://cdn.jsdelivr.net/gh/clappr/clappr-level-selector-plugin@~0/dist/level-selector.min.js
height: "100%",
width: "100%",
parentId: `#player`,
playback: {
hlsjsConfig: {
...engine.getConfigForHlsJs(),
},
},
});
engine.bindHls(() => clapprPlayer.core.getCurrentPlayback()?._hls);
</script>
+
+
+<script type="module">
import { HlsJsP2PEngine } from "p2p-media-loader-hlsjs";
const videoElement = document.querySelector("#video");
window.Hls = HlsJsP2PEngine.injectMixin(window.Hls);
const player = new MediaElementPlayer(videoElement.id, {
videoHeight: "100%",
hls: {
p2p: {
core: {
swarmId: "Optional custom swarm ID for stream",
// Other P2P engine config parameters go here
},
onHlsJsCreated: (hls) => {
// Subscribe to P2P engine and Hls.js events here
},
},
},
});
player.setSrc(streamUrl);
player.load();
</script>
+
+
+<script type="module">
import { HlsJsP2PEngine } from "p2p-media-loader-hlsjs";
const videoElement = document.querySelector("#video");
const HlsWithP2P = HlsJsP2PEngine.injectMixin(window.Hls);
const hls = new HlsWithP2P({
p2p: {
core: {
swarmId: "Optional custom swarm ID for stream",
// Other P2P engine config parameters go here
},
onHlsJsCreated(hls) {
// Subscribe to P2P engine and Hls.js events here
},
},
});
hls.on(Hls.Events.MANIFEST_PARSED, () => {
const levels = hls.levels;
const quality = {
default: levels[levels.length - 1].height,
options: levels.map((level) => level.height),
forced: true,
onChange: (newQuality) => {
levels.forEach((level, levelIndex) => {
if (level.height === newQuality) {
hls.currentLevel = levelIndex;
}
});
},
};
player = new Plyr(videoElement, {
quality,
autoplay: true,
muted: true,
});
});
hls.attachMedia(videoElement);
hls.loadSource(streamUrl);
</script>
+
+
+<script type="module">
import { HlsJsP2PEngine } from "p2p-media-loader-hlsjs";
const videoElement = document.querySelector("#video");
const HlsWithP2P = HlsJsP2PEngine.injectMixin(window.Hls);
const player = new OpenPlayerJS(videoElement, {
hls: {
p2p: {
core: {
swarmId: "Optional custom swarm ID for stream",
// Other P2P engine config parameters go here
},
onHlsJsCreated: (hls) => {
// Subscribe to P2P engine and Hls.js events here
},
},
},
controls: {
layers: {
left: ["play", "time", "volume"],
right: ["settings", "fullscreen", "levels"],
middle: ["progress"],
},
},
});
player.src = [
{
src: streamUrl,
type: "application/x-mpegURL",
},
];
player.init();
</script>
+
+
+Shaka player is used for an extended example:
+<!doctype html>
<html>
<head>
<!-- Link to Shaka Player's CSS for controls -->
<link
rel="stylesheet"
type="text/css"
href="https://unpkg.com/shaka-player/dist/controls.css"
/>
<!-- Link to Shaka Player's compiled UI script -->
<script src="https://unpkg.com/shaka-player/dist/shaka-player.ui.js"></script>
<!-- Import map for P2P Media Loader modules -->
<script type="importmap">
{
"imports": {
"p2p-media-loader-core": "https://cdn.jsdelivr.net/npm/p2p-media-loader-core@^2/dist/p2p-media-loader-core.es.min.js",
"p2p-media-loader-shaka": "https://cdn.jsdelivr.net/npm/p2p-media-loader-shaka@^2/dist/p2p-media-loader-shaka.es.min.js"
}
}
</script>
<!-- Module script to initialize Shaka Player with P2P Media Loader -->
<script type="module">
import { ShakaP2PEngine } from "p2p-media-loader-shaka";
// Register P2P Media Loader plugins with Shaka
ShakaP2PEngine.registerPlugins();
async function init() {
// Get the video element by its ID
const video = document.getElementById("video");
// Get Shaka UI controls and player
const ui = video["ui"];
const controls = ui.getControls();
const player = controls.getPlayer();
// Initialize P2P Media Loader with custom config
const shakaP2PEngine = new ShakaP2PEngine({
core: {
swarmId: "Optional custom swarm ID for stream",
// Other P2P engine config parameters go here
},
});
//Subscribe to P2P engine events here
shakaP2PEngine.addEventListener("onPeerConnect", (params) => {
console.log("Peer connected:", params.peerId);
});
// Configure and initialize Shaka Player with P2P Media Loader
shakaP2PEngine.bindShakaPlayer(player);
// Load the stream URL into the player
player.load(streamUrl);
}
// Add event listener for Shaka UI loaded event to trigger initialization
document.addEventListener("shaka-ui-loaded", init);
</script>
</head>
<body>
<div data-shaka-player-container style="max-width:40em">
<!-- Video element with Shaka Player UI -->
<video
autoplay
data-shaka-player
id="video"
style="width:100%;height:100%"
></video>
</div>
</body>
</html>
+
+
+<script type="module">
import { ShakaP2PEngine } from "p2p-media-loader-shaka";
const container = document.getElementById("container");
ShakaP2PEngine.registerPlugins();
const shakaP2PEngine = new ShakaP2PEngine({
core: {
swarmId: "Optional custom swarm ID for stream",
// Other P2P Media Loader Core options
},
});
const player = new Clappr.Player({
parentId: `#${container.id}`,
source: streamUrl,
plugins: [window.DashShakaPlayback, window.LevelSelector],
shakaOnBeforeLoad: (shakaPlayerInstance) => {
subscribeToUiEvents({
engine: shakaP2PEngine,
onPeerConnect,
onPeerDisconnect,
onChunkDownloaded,
onChunkUploaded,
});
shakaP2PEngine.bindShakaPlayer(shakaPlayerInstance);
},
});
</script>
+
+
+<script type="module">
import { ShakaP2PEngine } from "p2p-media-loader-shaka";
const container = document.getElementById("container");
ShakaP2PEngine.registerPlugins();
const shakaP2PEngine = new ShakaP2PEngine({
core: {
swarmId: "Optional custom swarm ID for stream",
// Other P2P Media Loader Core options
},
});
const player = new DPlayer({
container,
video: {
url: "",
type: "customHlsOrDash",
customType: {
customHlsOrDash: (video) => {
const shakaPlayer = new shaka.Player();
void shakaPlayer.attach(video);
shakaP2PEngine.bindShakaPlayer(shakaPlayer);
void shakaPlayer.load(streamUrl);
},
},
},
});
</script>
+
+
+<script type="module">
import { ShakaP2PEngine } from "p2p-media-loader-shaka";
ShakaP2PEngine.registerPlugins();
const videoElement = document.getElementById("video");
const initPlayer = () => {
const shakaP2PEngine = new ShakaP2PEngine({
core: {
swarmId: "Optional custom swarm ID for stream",
// Other P2P Media Loader Core options
},
});
const shakaPlayer = new shaka.Player();
shakaPlayer.attach(videoElement);
shakaP2PEngine.bindShakaPlayer(shakaPlayer);
shakaPlayer.load(streamUrl);
const plyrPlayer = new Plyr(videoElement);
};
initPlayer();
</script>
+
+
+Segments storage interface
+Initializes storage
+Core configuration with storage options
+Main stream configuration
+Secondary stream configuration
+Provides segment request information from player
+Swarm identifier
+Stream identifier
+Segment identifier
+Segment start time
+Segment end time
+Stream type
+Is live stream
+Stores segment data
+Swarm identifier
+Stream identifier
+Segment identifier
+Segment data
+Segment start time
+Segment end time
+Stream type
+Is live stream
+Represents a range of bytes, used for specifying a segment of data to download.
+The starting byte index of the range.
+The ending byte index of the range.
+Represents the configuration for the Core functionality that is common to all streams.
+Defines the memory storage limit for media segments, in MiB.
+Optional
customOptional custom storage factory for the segments storage.
+Represents a set of configuration parameters that can be used to override or extend the +default configuration settings for a specific stream (main or secondary).
+Optional
mainOptional configuration for the main stream.
+Optional
secondaryOptional configuration for the secondary stream.
+const config: CoreConfig = {
highDemandTimeWindow: 15,
httpDownloadTimeWindow: 3000,
p2pDownloadTimeWindow: 6000,
swarmId: "custom swarm ID for video stream",
}
+
+
+const config: CoreConfig = {
// Configuration for both streams
highDemandTimeWindow: 20,
httpDownloadTimeWindow: 3000,
p2pDownloadTimeWindow: 6000,
mainStream: {
// Optional configuration for the main stream
swarmId: "custom swarm ID for video stream",
},
secondaryStream: {
// Optional configuration for the secondary stream
swarmId: "custom swarm ID for audio stream",
},
+
+
+The CoreEventMap defines a comprehensive suite of event handlers crucial for monitoring and controlling the lifecycle +of segment downloading and uploading processes.
+Invoked when a segment is fully downloaded and available for use.
+Contains information about the loaded segment.
+Triggered when an error occurs during the download of a segment.
+Contains information about the errored segment.
+Called if the download of a segment is aborted before completion.
+Contains information about the aborted segment.
+Fired at the beginning of a segment download process.
+Provides details about the segment being downloaded.
+Occurs when a new peer-to-peer connection is established.
+Contains details about the peer that the event is about.
+Triggered when an existing peer-to-peer connection is closed.
+Contains details about the peer that the event is about.
+Triggered when an error occurs during a peer-to-peer connection.
+Contains details about the error and the peer that the event is about.
+Invoked after a chunk of data from a segment has been successfully downloaded.
+The size of the downloaded chunk in bytes.
+The source of the download.
+Optional
peerId: stringThe peer ID of the peer that the event is about, if applicable.
+Called when a chunk of data has been successfully uploaded to a peer.
+The length of the segment in bytes.
+The peer ID, if the segment was downloaded from a peer
+Called when an error occurs during the tracker request process.
+Contains information about the tracker error.
+Called when a warning occurs during the tracker request process.
+Contains information about the tracker warning.
+Represents a defined Core configuration with specific settings for the main and secondary streams.
+Configuration for the main stream.
+Configuration for the secondary stream.
+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.
+Represents a dynamically modifiable configuration, allowing updates to selected CoreConfig properties at runtime.
+Optional
mainOptional dynamic configuration for the main stream.
+Optional
secondaryOptional dynamic configuration for the secondary stream.
+Represents a partial configuration for a stream with dynamic properties.
+Represents a set of properties that can be dynamically modified at runtime.
+Callbacks for handling the success or failure of an engine operation.
+Called when the operation is successful.
+The response from the successful operation.
+Called when the operation encounters an error.
+The error encountered during the operation.
+Defines the types of errors specific to HTTP requests.
+Represents the details of a peer in a peer-to-peer network.
+The unique identifier for a peer in the network.
+The type of stream that the peer is connected to.
+Represents the details of a peer error event.
+The unique identifier for a peer in the network.
+The type of stream that the peer is connected to.
+The error that occurred during the peer-to-peer connection.
+Defines the types of errors specific to peer-to-peer requests.
+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.
+Describes a media segment with its unique identifiers, location, and timing information.
+Readonly
runtimeA runtime identifier for the segment that includes URL and byte range from its manifest.
+Readonly
externalAn unique identifier of the segment in its stream used for P2P communications: sequence number for HLS or playtime for MPEG-DASH.
+Readonly
url: stringThe URL from which the segment can be downloaded.
+Optional
Readonly
byteAn optional property specifying the range of bytes that represent the segment.
+Readonly
startThe start time of the segment in seconds, relative to the beginning of the stream.
+Readonly
endThe end time of the segment in seconds, relative to the beginning of the stream.
+Represents details about a segment abort event.
+The segment that the event is about.
+The source of the download.
+The peer ID, if the segment was downloaded from a peer.
+The type of stream that the segment is associated with.
+Represents details about a segment error event.
+The error that occurred during the segment download.
+The segment that the event is about.
+The source of the download.
+The peer ID, if the segment was downloaded from a peer.
+The type of stream that the segment is associated with.
+Represents the details about a loaded segment.
+The URL of the loaded segment
+The length of the segment in bytes.
+The source of the download.
+The peer ID, if the segment was downloaded from a peer.
+The segment that the event is about.
+Represents the response from a segment request, including the data and measured bandwidth.
+Segment data as an ArrayBuffer.
+Measured bandwidth for the segment download, in bytes per second.
+Represents details about a segment event.
+The segment that the event is about.
+The origin of the segment download.
+The peer ID, if the segment is downloaded from a peer.
+Represents a media stream with various defining characteristics.
+Readonly
runtimeRuntime identifier of the stream from an engine.
+Readonly
type: StreamTypeStream type.
+Readonly
index: numberStream index in the manifest.
+Configuration options for the Core functionality, including network and processing parameters.
+Controls if peer-to-peer upload is disabled for the stream.
+If true
, the stream only downloads segments without uploading to peers.
Controls whether peer-to-peer functionality is disabled for the stream.
+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.
+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.
+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.
Maximum number of simultaneous HTTP downloads allowed.
+Maximum number of simultaneous P2P downloads allowed.
+Maximum message size for WebRTC communications, in bytes.
+Timeout for not receiving bytes from P2P, in milliseconds.
+Timeout for destroying the P2P loader if inactive, in milliseconds.
+Timeout for not receiving bytes from HTTP downloads, in milliseconds.
+Number of retries allowed after an HTTP error.
+Number of retries allowed after a P2P error.
+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.
+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.
+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.
+Optional
swarmOptional 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.
+Optional
validateOptional function to validate a P2P segment before fully integrating it into the playback buffer.
+URL of the segment to validate.
+Optional byte range of the segment.
+Downloaded segment data.
+A promise that resolves with a boolean indicating if the segment is valid.
+Optional
httpOptional function to customize the setup of HTTP requests for segment downloads.
+URL of the segment.
+The range of bytes requested for the segment.
+An abort signal to cancel the request if needed.
+Additional byte range for partial requests, if required.
+A promise that resolves with the configured request, or undefined if no customization should be made.
+Represents the types of streams available, either primary (main) or secondary.
+Represents a stream that includes multiple segments, each associated with the stream.
+Represents the details of a tracker error event.
+The type of stream that the tracker is for.
+The error that occurred during the tracker request.
+The type of stream that the tracker is for.
+The warning that occurred during the tracker request.
+Type for specifying dynamic configuration options that can be changed at runtime for the P2P engine's core.
+Optional
core?: DynamicCoreConfigDynamic core config
+Represents the complete configuration for HlsJsP2PEngine.
+Complete core configuration settings.
+Configuration type for HLS instances that includes P2P settings, augmenting standard HLS configuration with P2P capabilities.
+Extends a generic HLS type to include the P2P engine, integrating P2P capabilities directly into the HLS instance.
+Readonly
p2pHlsJsP2PEngine instance
+Allows for partial configuration of HlsJsP2PEngine, useful for providing overrides or partial updates.
+Optional
core?: Partial<CoreConfig>Partial core config
+Type for specifying dynamic configuration options that can be changed at runtime for the P2P engine's core.
+Optional
core?: DynamicCoreConfigDynamic core config
+Allows for partial configuration settings for the Shaka P2P Engine.
+Optional
core?: Partial<CoreConfig>Partial core config
+Represents the complete configuration for ShakaP2PEngine.
+Complete core configuration settings.
+
Core class for managing media streams loading via P2P.
+