mirror of
https://github.com/owncast/owncast.git
synced 2024-11-21 20:28:15 +03:00
refactor: update vjs beforeRequest to onRequest (#3945)
* refactor: update vjs onRequst to onRequest * fix(js): update vjs to use the new onrequest hook for manipulating request uri --------- Co-authored-by: Gabe Kangas <gabek@real-ity.com>
This commit is contained in:
parent
284833d6a0
commit
681111ceb2
1 changed files with 13 additions and 14 deletions
|
@ -30,22 +30,21 @@ export const VideoJS: FC<VideoJSProps> = ({ options, onReady }) => {
|
||||||
player.src(options.sources);
|
player.src(options.sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a cachebuster param to playlist URLs.
|
videojs.getPlayer(videoRef.current).on('xhr-hooks-ready', () => {
|
||||||
if (
|
const cachebusterRequestHook = o => {
|
||||||
(videojs.getPlayer(videoRef.current).tech({ IWillNotUseThisInPlugins: true }) as any)?.vhs
|
let { uri } = o;
|
||||||
) {
|
if (o.uri.match('m3u8')) {
|
||||||
|
const cachebuster = Math.random().toString(16).slice(2, 8);
|
||||||
|
uri = `${o.uri}?cachebust=${cachebuster}`;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
uri,
|
||||||
|
};
|
||||||
|
};
|
||||||
(
|
(
|
||||||
videojs.getPlayer(videoRef.current).tech({ IWillNotUseThisInPlugins: true }) as any
|
videojs.getPlayer(videoRef.current).tech({ IWillNotUseThisInPlugins: true }) as any
|
||||||
).vhs.xhr.beforeRequest = o => {
|
)?.vhs.xhr.onRequest(cachebusterRequestHook);
|
||||||
if (o.uri.match('m3u8')) {
|
});
|
||||||
const cachebuster = Math.random().toString(16).substr(2, 8);
|
|
||||||
// eslint-disable-next-line no-param-reassign
|
|
||||||
o.uri = `${o.uri}?cachebust=${cachebuster}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return o;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}, [options, videoRef]);
|
}, [options, videoRef]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in a new issue