Hls.js: set drm key request header

Created on 25 Aug 2020  路  9Comments  路  Source: video-dev/hls.js

What do you want to do with Hls.js?
I want to set drm key request header, add Authorization
What have you tried so far?

const config = {
    xhrSetup: (xhr,url) => xhr.setRequestHeader("Authorization", "Bearer ....")
}

I want to set drm key request header, rather then each xhr request銆侷 know that in the above way, regular expressions can be used to determine whether the request URL belongs to the drm key. Is there any other simpler way?

Documentation Stale answered

Most helpful comment

@ourfor you can use config.licenseXhrSetup for that. it works exactly like xhrSetup !

see https://github.com/video-dev/hls.js/blob/master/src/controller/eme-controller.ts#L127

this should be documented in API docs (and we should fix that). I wonder how it happened we didn't in fact.

All 9 comments

@ourfor you can use config.licenseXhrSetup for that. it works exactly like xhrSetup !

see https://github.com/video-dev/hls.js/blob/master/src/controller/eme-controller.ts#L127

this should be documented in API docs (and we should fix that). I wonder how it happened we didn't in fact.

see xhrSetup docs here, we should add same licenseXhrSetup docs as well: https://github.com/video-dev/hls.js/blob/master/docs/API.md#xhrsetup

Great thanks!

const hls = new Hls({
    licenseXhrSetup: (xhr,url) => {
                console.log('key request')
                xhr.setRequestHeader("Authorization","Bearer test")
        }
});

It seems not working.

image

https://github.com/video-dev/hls.js/blob/043118a508b9da7d786cf768f8b4ea7a98cfcd8d/src/loader/key-loader.ts#L90

https://github.com/video-dev/hls.js/blob/043118a508b9da7d786cf768f8b4ea7a98cfcd8d/src/utils/xhr-loader.js#L52-L70
not call method licenseXhrSetup

Hi @ourfor,

Make sure you are using the XHRLoader when using xhrSetup. It's the default loader in the latest release but not in some branches and earlier LHLS versions of feature/v1.0.0. The FetchLoader and custom loaders (unless implemented) do not support xhrSetup.

@ourfor @robwalch In any case, this isn't a matter of which loader you use for HLS media content itself :)

Our EME client has an own loader you can basically say.

The XHR with which we load the DRM license data to feed the EME API with is created here, and that is where we (eventually) use the licenseXhrSetup function passed to the config: https://github.com/video-dev/hls.js/blob/master/src/controller/eme-controller.ts#L388

And see also: https://github.com/video-dev/hls.js/blob/master/src/controller/eme-controller.ts#L127

@ourfor I am not sure what your problem is. If you have a media that uses a DRM scheme we support (only Widevine in master branch so far) then it should "just work". License access will work as licenseXhrSetup is implemented/configured in such way that will allow the request to succeed (like for example setting auth request headers that the license server expects).

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

krsvital picture krsvital  路  3Comments

neuman picture neuman  路  4Comments

GeorgySerga picture GeorgySerga  路  3Comments

eteubert picture eteubert  路  3Comments

mmmmoj picture mmmmoj  路  3Comments