Last active
December 12, 2022 19:15
-
-
Save onetdev/97a6e28f2479711a279a00c8ae298b1e to your computer and use it in GitHub Desktop.
VideoJS + XHR mod : Adding XHR interceptor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link media="all" rel="stylesheet" href="https://unpkg.com/[email protected]/dist/video-js.css"> | |
<script src="https://unpkg.com/[email protected]/dist/video.js"></script> | |
<video-js id="player"> | |
<source src="//video/index.m3u8" type="application/x-mpegURL" /> | |
</video-js> | |
<script> | |
var player = videojs("player"); | |
var prefix = "key://"; | |
var urlTpl = "https://domain.com/path/{key}"; | |
// player.ready | |
player.on("loadstart", function (e) { | |
player.tech().hls.xhr.beforeRequest = function(options) { | |
// required for detecting only the key requests | |
if (!options.uri.startsWith(keyPrefix)) { return; } | |
options.headers = options.headers || {}; | |
optopns.headers["Custom-Header"] = "value"; | |
options.uri = urlTpl.replace("{key}", options.uri.substring(keyPrefix.length)); | |
}; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment