p2p-media-loader
p2p-media-loader copied to clipboard
specifying onHlsJsCreated prevents hlsjs p2p from initializing
if using this config it works:
{
p2p: {
core: {
liveDurationInfinity: true,
announceTrackers: [
"wss://tracker.novage.com.ua",
"wss://tracker.webtorrent.dev",
"wss://tracker.openwebtorrent.com",
],
rtcConfig: {
iceServers: [
{ urls: "stun.l.google.com:19302" },
{ urls: "stun1.l.google.com:19302" },
{ urls: "stun2.l.google.com:19302" },
{ urls: "stun3.l.google.com:19302" },
{ urls: "stun4.l.google.com:19302" }
],
},
}
}
}
but adding this it stops working:
{
p2p: {
core: {
onHlsJsCreated(hls) {
console.log("hls created", hls)
// // Subscribe to P2P engine and Hls.js events here
hls.p2pEngine.addEventListener("onChunkDownloaded", (bytesLength, downloadSource) => {
switch (downloadSource) {
case "http":
data.current.httpDownloaded += bytesLength;
console.log(`http downloaded ${bytesLength} bytes`)
break;
case "p2p":
console.log(`p2p downloaded ${bytesLength} bytes`)
break;
default:
break;
}
})
hls.p2pEngine.addEventListener("onChunkUploaded", (bytesLength) => {
console.log(`p2p uploaded ${bytesLength} bytes`)
})
}
},
}
Most likely your event handle is buggy. Probably there is no data or data.current variable that leads to an exception.
Wrap event listener's code into try\catch and console log errors.
Alternatively remove data.current.httpDownloaded += bytesLength; line. It is the only line that may cause issues.