Cleanup; no functional change.
- Handle null `vjsPlayer` so we don't need to add FlowFixMe everywhere. - Remove redundant comments.
This commit is contained in:
parent
99b446a8fe
commit
4f600fbc8e
1 changed files with 7 additions and 18 deletions
|
@ -333,19 +333,17 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
// }
|
// }
|
||||||
// }, [showQualitySelector]);
|
// }, [showQualitySelector]);
|
||||||
|
|
||||||
/** instantiate videoJS and dispose of it when done with code **/
|
|
||||||
// This lifecycle hook is only called once (on mount), or when `isAudio` or `source` changes.
|
// This lifecycle hook is only called once (on mount), or when `isAudio` or `source` changes.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async function () {
|
(async function () {
|
||||||
// test if perms to play video are available
|
|
||||||
let canAutoplayVideo = await canAutoplay.video({ timeout: 2000, inline: true });
|
let canAutoplayVideo = await canAutoplay.video({ timeout: 2000, inline: true });
|
||||||
|
|
||||||
canAutoplayVideo = canAutoplayVideo.result === true;
|
canAutoplayVideo = canAutoplayVideo.result === true;
|
||||||
|
|
||||||
const vjsElement = createVideoPlayerDOM(containerRef.current);
|
const vjsElement = createVideoPlayerDOM(containerRef.current);
|
||||||
|
|
||||||
// Initialize Video.js
|
|
||||||
const vjsPlayer = initializeVideoPlayer(vjsElement, canAutoplayVideo);
|
const vjsPlayer = initializeVideoPlayer(vjsElement, canAutoplayVideo);
|
||||||
|
if (!vjsPlayer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Add reference to player to global scope
|
// Add reference to player to global scope
|
||||||
window.player = vjsPlayer;
|
window.player = vjsPlayer;
|
||||||
|
@ -355,38 +353,31 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
|
|
||||||
window.addEventListener('keydown', curried_function(playerRef, containerRef));
|
window.addEventListener('keydown', curried_function(playerRef, containerRef));
|
||||||
|
|
||||||
// $FlowFixMe
|
|
||||||
const controlBar = document.querySelector('.vjs-control-bar');
|
const controlBar = document.querySelector('.vjs-control-bar');
|
||||||
if (controlBar) controlBar.style.setProperty('opacity', '1', 'important');
|
if (controlBar) {
|
||||||
|
controlBar.style.setProperty('opacity', '1', 'important');
|
||||||
|
}
|
||||||
|
|
||||||
if (isLivestreamClaim && userClaimId) {
|
if (isLivestreamClaim && userClaimId) {
|
||||||
// $FlowFixMe
|
|
||||||
vjsPlayer.addClass('livestreamPlayer');
|
vjsPlayer.addClass('livestreamPlayer');
|
||||||
|
|
||||||
// $FlowFixMe
|
|
||||||
vjsPlayer.src({
|
vjsPlayer.src({
|
||||||
type: 'application/x-mpegURL',
|
type: 'application/x-mpegURL',
|
||||||
src: livestreamVideoUrl,
|
src: livestreamVideoUrl,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// $FlowFixMe
|
|
||||||
vjsPlayer.removeClass('livestreamPlayer');
|
vjsPlayer.removeClass('livestreamPlayer');
|
||||||
|
|
||||||
// change to m3u8 if applicable
|
// change to m3u8 if applicable
|
||||||
const response = await fetch(source, { method: 'HEAD', cache: 'no-store' });
|
const response = await fetch(source, { method: 'HEAD', cache: 'no-store' });
|
||||||
|
|
||||||
playerServerRef.current = response.headers.get('x-powered-by');
|
playerServerRef.current = response.headers.get('x-powered-by');
|
||||||
|
|
||||||
if (response && response.redirected && response.url && response.url.endsWith('m3u8')) {
|
if (response && response.redirected && response.url && response.url.endsWith('m3u8')) {
|
||||||
// use m3u8 source
|
|
||||||
// $FlowFixMe
|
|
||||||
vjsPlayer.src({
|
vjsPlayer.src({
|
||||||
type: 'application/x-mpegURL',
|
type: 'application/x-mpegURL',
|
||||||
src: response.url,
|
src: response.url,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// use original mp4 source
|
|
||||||
// $FlowFixMe
|
|
||||||
vjsPlayer.src({
|
vjsPlayer.src({
|
||||||
type: sourceType,
|
type: sourceType,
|
||||||
src: source,
|
src: source,
|
||||||
|
@ -394,11 +385,9 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// load video once source setup
|
|
||||||
// $FlowFixMe
|
|
||||||
vjsPlayer.load();
|
vjsPlayer.load();
|
||||||
|
|
||||||
// fix invisible vidcrunch overlay on IOS
|
// fix invisible vidcrunch overlay on IOS << TODO: does not belong here. Move to ads.jsx (#739)
|
||||||
if (IS_IOS) {
|
if (IS_IOS) {
|
||||||
// ads video player
|
// ads video player
|
||||||
const adsClaimDiv = document.querySelector('.ads__claim-item');
|
const adsClaimDiv = document.querySelector('.ads__claim-item');
|
||||||
|
|
Loading…
Reference in a new issue