Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add custom header in every dash request from videojs #346

Open
krackjack234 opened this issue May 12, 2020 · 1 comment
Open

How to add custom header in every dash request from videojs #346

krackjack234 opened this issue May 12, 2020 · 1 comment

Comments

@krackjack234
Copy link

Hi,

We want to add a custom header in every request that the player makes while playing a mpd file.

Is there anyway we can add/modify a header in every mpd/mp4/m4v/m4a request that we make from the player (like an interceptor)?

We saw the example present at https://reference.dashif.org/dash.js/v3.1.0/samples/advanced/extend.html

but when we try the same using videojs, we dont see the functions getting called

Here is a code snippet we used

var player = videojs('my-player', options, function onPlayerReady() {
  videojs.log('Your player is ready!');

  player.on('loadstart', function() {
    addCustomHeaderForDash();
  })
 
 
  function addCustomHeaderForDash(){
    if (player.dash && player.dash.mediaPlayer) {
      player.dash.mediaPlayer.extend("RequestModifier", function () {
                  return {
                      modifyRequestHeader: function (xhr) {
                          // Add custom header. Requires to set up Access-Control-Allow-Headers in your
                          // response header in the server side. Reference: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader
                          // xhr.setRequestHeader('DASH-CUSTOM-HEADER', 'MyValue');
                          
                          return xhr;
                      },
                      modifyRequestURL: function (url) {
                          // Modify url adding a custom query string parameter
                          return url + '?customQuery=value';
                      }
                  };
      });
    }
  }

})

Any pointers will be really helpful.
Thanks

@krackjack234
Copy link
Author

videojs-dash.html.zip

Test page attached

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant