p2p-media-loader icon indicating copy to clipboard operation
p2p-media-loader copied to clipboard

specifying onHlsJsCreated prevents hlsjs p2p from initializing

Open sloev opened this issue 6 months ago • 1 comments

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`)
                    })
                }
            },
        }

sloev avatar Jun 13 '25 09:06 sloev

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.

mrlika avatar Jun 13 '25 11:06 mrlika