hlsjs-ipfs-loader icon indicating copy to clipboard operation
hlsjs-ipfs-loader copied to clipboard

JS IPFS instance supplied via hls.config prevents Hls.js from kicking off its demuxing web worker

Open UnKnoWn-Consortium opened this issue 4 years ago • 1 comments

By default, Hls.js delegates the demuxing work to a web worker and the Hls.js config is included in the payload sent to that web worker.

Error is thrown when JSON.stringify tries to "stringify" circular structure inside the JS IPFS instance. Hls.js then reverts to inline demuxing as a fallback solution. This is not ideal.

2021-01-14_090434

UnKnoWn-Consortium avatar Jan 15 '21 08:01 UnKnoWn-Consortium

A viable solution is to inject the IPFS instance to the IPFS loader class via a factory function (that accepts the IPFS instance as an augment and supplies it to the loader class returned).

For instance,

function HlsjsIPFSLoaderFactory (ipfs) {
    return class HlsjsIPFSLoader {...}
}

Then to use it:

const ipfs = await Ipfs.create();
Hls.DefaultConfig.loader = IPFSLoaderFactory(ipfs);

UnKnoWn-Consortium avatar Jan 15 '21 08:01 UnKnoWn-Consortium