Add custom headers to videojs player source

被刻印的时光 ゝ 提交于 2019-12-02 08:03:28

Videojs initialization is happening on client side so you need to pass token before this initialization. I suggest you to initialize Videojs using ajax and send token using Ajax. I hope it helps.

The solution I've gone with was to intercept browser XHR requests(using the xhook npm package) and set headers programmatically. Bellow is a simple example:

...

this.player.src({
  src: SOME_VIDEO_URL,
});

...

/**
 * add manifest authorization header
 */
window.xhook.before((request, callback) => {
  // only set header request for the videojs src url (don't touch other xhr requests)
  if (request.url === SOME_VIDEO_URL) {
    request.xhr.setRequestHeader('Authorization', manifestAuthorization);
  }
  callback();
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!