Skip to content

ReactPlayer config for HLS is not applied (e.g., xhrSetup not triggered) #1977

@jpstijn

Description

@jpstijn

I am trying to use the config property in ReactPlayer to apply custom HLS settings, specifically the xhrSetup function, to append a token to the stream URL and set custom headers. However, it seems that the config is not being applied, and the xhrSetup function is never triggered.

Steps to Reproduce:
Use ReactPlayer with an HLS stream (.m3u8 URL).
Pass a config object with an hls configuration, including an xhrSetup function.
Observe that the xhrSetup function is not called, and the custom headers or URL modifications are not applied.

import ReactPlayer from 'react-player';

const streamToken = 'my-stream-token';
const src = 'https://example.com/stream.m3u8';

const config = {
  hls: {
    xhrSetup: (xhr, url) => {
      console.log('XHR Setup for URL:', url);
      const urlWithToken = `${url}${url.includes('?') ? '&' : '?'}token=${encodeURIComponent(streamToken)}`;
      xhr.open('GET', urlWithToken, true);
      xhr.setRequestHeader('Authorization', `Bearer ${streamToken}`);
      xhr.withCredentials = true;
    },
    debug: true,
  },
};

<ReactPlayer
  url={src}
  playing
  config={config}
/>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions