hls.js icon indicating copy to clipboard operation
hls.js copied to clipboard

custom transport

Open Dirard opened this issue 10 months ago • 2 comments

Is your feature request related to a problem? Please describe.

i have custom transport with refresh token logic with same intrerface as common fetch. FetchLoader uses fetch, can i replace it with my own?

Describe the solution you'd like

import { Hls, FetchLoader } from 'hls.mjs';

const transport = new CustomTransport()

var video = document.getElementById('video');
if (Hls.isSupported()) {
  var hls = (window.hls = new Hls({
    loader: FetchLoader,
    customFetch: transport.fetch
  })
}

Additional context

No response

Dirard avatar Feb 08 '25 15:02 Dirard

FetchLoader uses the global fetch. There is no way to pass a different fetch method to FetchLoader.

The preferred way to do any custom data transfer would be to create a new custom loader and replace loader with the custom loader n the config. If you transport mimics fetch and its interfaces, you could extend FetchLoader with a custom loader class that overrides (and copies) load using your transport.fetch.

robwalch avatar Apr 25 '25 16:04 robwalch

If you'd like to make a PR that puts the global fetch into the default config so that you could replace it with your own, we could accept that as a solution to this issue.

robwalch avatar Apr 25 '25 16:04 robwalch