mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
test(player): fix binge watching (5)
This commit is contained in:
parent
9aed64d998
commit
9b405c53d8
1 changed files with 43 additions and 17 deletions
|
|
@ -103,7 +103,6 @@ const Player = ({ urlParams, queryParams }) => {
|
|||
}, [settings.subtitlesSize, settings.subtitlesOffset, settings.subtitlesTextColor, settings.subtitlesBackgroundColor, settings.subtitlesOutlineColor]);
|
||||
|
||||
const onEnded = React.useCallback(() => {
|
||||
console.log('Player in on ended callback', player.nextVideo); // eslint-disable-line no-console
|
||||
ended();
|
||||
if (player.nextVideo !== null) {
|
||||
onNextVideoRequested();
|
||||
|
|
@ -216,22 +215,36 @@ const Player = ({ urlParams, queryParams }) => {
|
|||
}, []);
|
||||
|
||||
const onNextVideoRequested = React.useCallback(() => {
|
||||
if (player.nextVideo !== null && !nextVideoHandledRef.current) {
|
||||
nextVideoHandledRef.current = true;
|
||||
if (player.nextVideo !== null) {
|
||||
// Call nextVideo only for analytics
|
||||
nextVideo();
|
||||
|
||||
const navigationData = {
|
||||
playerLink: player.nextVideo.deepLinks.player,
|
||||
metaDetailsLink: player.nextVideo.deepLinks.metaDetailsStreams
|
||||
};
|
||||
// Capture navigation data
|
||||
const navigationLink = player.nextVideo.deepLinks.player ||
|
||||
player.nextVideo.deepLinks.metaDetailsStreams;
|
||||
|
||||
const targetLink = navigationData.playerLink || navigationData.metaDetailsLink;
|
||||
if (navigationLink) {
|
||||
// Force immediate navigation with no chance of React re-renders affecting it
|
||||
// This bypasses the React lifecycle entirely
|
||||
const navigateImmediately = () => {
|
||||
const form = document.createElement('form');
|
||||
form.style.display = 'none';
|
||||
form.method = 'GET';
|
||||
form.action = navigationLink;
|
||||
|
||||
if (targetLink) {
|
||||
nextVideo();
|
||||
const input = document.createElement('input');
|
||||
input.type = 'hidden';
|
||||
input.name = 'navigationFromPlayer';
|
||||
input.value = 'true';
|
||||
form.appendChild(input);
|
||||
|
||||
window.location.replace(targetLink);
|
||||
} else {
|
||||
nextVideo();
|
||||
// Force immediate navigation
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
};
|
||||
|
||||
// Execute immediately
|
||||
navigateImmediately();
|
||||
}
|
||||
}
|
||||
}, [player.nextVideo]);
|
||||
|
|
@ -511,10 +524,7 @@ const Player = ({ urlParams, queryParams }) => {
|
|||
video.events.off('extraSubtitlesTrackAdded', onExtraSubtitlesTrackAdded);
|
||||
video.events.off('implementationChanged', onImplementationChanged);
|
||||
};
|
||||
}, [
|
||||
onEnded,
|
||||
onImplementationChanged
|
||||
]);
|
||||
}, [onEnded]);
|
||||
|
||||
React.useLayoutEffect(() => {
|
||||
const onKeyDown = (event) => {
|
||||
|
|
@ -647,6 +657,22 @@ const Player = ({ urlParams, queryParams }) => {
|
|||
};
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
// eslint-disable-next-line
|
||||
const cameFromPlayer = urlParams.get('navigationFromPlayer');
|
||||
|
||||
if (cameFromPlayer === 'true') {
|
||||
// eslint-disable-next-line
|
||||
urlParams.delete('navigationFromPlayer');
|
||||
const newUrl = window.location.pathname +
|
||||
(urlParams.toString() ? '?' + urlParams.toString() : '') +
|
||||
window.location.hash;
|
||||
|
||||
window.history.replaceState({}, '', newUrl);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={classnames(styles['player-container'], { [styles['overlayHidden']]: overlayHidden })}
|
||||
onMouseDown={onContainerMouseDown}
|
||||
|
|
|
|||
Loading…
Reference in a new issue