Remove polling, still happen on channel pages (#1558)
This commit is contained in:
parent
54ee4ee94a
commit
c38e37cd38
4 changed files with 10 additions and 29 deletions
|
@ -97,7 +97,7 @@ function ChannelContent(props: Props) {
|
|||
const isInitialized = Boolean(activeLivestreamForChannel) || activeLivestreamInitialized;
|
||||
const isChannelBroadcasting = Boolean(activeLivestreamForChannel);
|
||||
|
||||
useFetchLiveStatus(claimId, doFetchChannelLiveStatus);
|
||||
useFetchLiveStatus(claimId, doFetchChannelLiveStatus, true);
|
||||
|
||||
const showScheduledLiveStreams = claimType !== 'collection'; // ie. not on the playlist page.
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import { LIVESTREAM_STATUS_CHECK_INTERVAL_SOON, LIVESTREAM_STATUS_CHECK_INTERVAL
|
|||
export default function useFetchLiveStatus(
|
||||
channelClaimId: ?string,
|
||||
doFetchChannelLiveStatus: (string) => void,
|
||||
poll?: boolean,
|
||||
fasterPoll?: boolean
|
||||
) {
|
||||
// Find out current channels status + active live claim every 30 seconds
|
||||
|
@ -12,12 +13,14 @@ export default function useFetchLiveStatus(
|
|||
if (!channelClaimId) return;
|
||||
|
||||
const fetch = () => doFetchChannelLiveStatus(channelClaimId || '');
|
||||
const interval = fasterPoll ? LIVESTREAM_STATUS_CHECK_INTERVAL_SOON : LIVESTREAM_STATUS_CHECK_INTERVAL;
|
||||
|
||||
fetch();
|
||||
|
||||
const intervalId = setInterval(fetch, interval);
|
||||
if (poll) {
|
||||
const interval = fasterPoll ? LIVESTREAM_STATUS_CHECK_INTERVAL_SOON : LIVESTREAM_STATUS_CHECK_INTERVAL;
|
||||
const intervalId = setInterval(fetch, interval);
|
||||
|
||||
return () => clearInterval(intervalId);
|
||||
}, [channelClaimId, doFetchChannelLiveStatus, fasterPoll]);
|
||||
return () => clearInterval(intervalId);
|
||||
}
|
||||
}, [channelClaimId, doFetchChannelLiveStatus, fasterPoll, poll]);
|
||||
}
|
||||
|
|
|
@ -107,16 +107,7 @@ export default function LivestreamPage(props: Props) {
|
|||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const claimReleaseStartingSoonStatic = () =>
|
||||
releaseTime.isBetween(moment(), moment().add(LIVESTREAM_STARTS_SOON_BUFFER, 'minutes'));
|
||||
|
||||
const claimReleaseStartedRecentlyStatic = () =>
|
||||
releaseTime.isBetween(moment().subtract(LIVESTREAM_STARTED_RECENTLY_BUFFER, 'minutes'), moment());
|
||||
|
||||
// Find out current channels status + active live claim every 30 seconds (or 15 if not live)
|
||||
const fasterPoll = !isCurrentClaimLive && (claimReleaseStartingSoonStatic() || claimReleaseStartedRecentlyStatic());
|
||||
|
||||
useFetchLiveStatus(livestreamChannelId, doFetchChannelLiveStatus, fasterPoll);
|
||||
useFetchLiveStatus(livestreamChannelId, doFetchChannelLiveStatus);
|
||||
|
||||
React.useEffect(() => {
|
||||
setActiveStreamUri(!isCurrentClaimLive && isChannelBroadcasting ? activeLivestreamForChannel.claimUri : false);
|
||||
|
|
|
@ -10,7 +10,6 @@ import {
|
|||
filterUpcomingLiveStreamClaims,
|
||||
} from 'util/livestream';
|
||||
import moment from 'moment';
|
||||
import { LocalStorage, LS } from 'util/storage';
|
||||
import { isEmpty } from 'util/object';
|
||||
|
||||
export const doFetchNoSourceClaims = (channelId: string) => async (dispatch: Dispatch, getState: GetState) => {
|
||||
|
@ -116,20 +115,11 @@ const findActiveStreams = async (
|
|||
};
|
||||
|
||||
export const doFetchChannelLiveStatus = (channelId: string) => async (dispatch: Dispatch) => {
|
||||
const statusForId = LS.CHANNEL_LIVE_STATUS;
|
||||
const localStatus = LocalStorage.getItem(statusForId);
|
||||
|
||||
try {
|
||||
const { channelStatus, channelData } = await fetchLiveChannel(channelId);
|
||||
// store live state locally, and force 2 non-live statuses before returninig NOT LIVE. This allows for the stream to finish before disposing player.
|
||||
if (localStatus === LiveStatus.LIVE && channelStatus === LiveStatus.NOT_LIVE) {
|
||||
LocalStorage.removeItem(statusForId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (channelStatus === LiveStatus.NOT_LIVE && !localStatus) {
|
||||
if (channelStatus === LiveStatus.NOT_LIVE) {
|
||||
dispatch({ type: ACTIONS.REMOVE_CHANNEL_FROM_ACTIVE_LIVESTREAMS, data: { channelId } });
|
||||
LocalStorage.removeItem(statusForId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -145,11 +135,8 @@ export const doFetchChannelLiveStatus = (channelId: string) => async (dispatch:
|
|||
channelData[channelId].claimUri = liveClaim.stream.canonical_url;
|
||||
dispatch({ type: ACTIONS.ADD_CHANNEL_TO_ACTIVE_LIVESTREAMS, data: { ...channelData } });
|
||||
}
|
||||
|
||||
LocalStorage.setItem(statusForId, channelStatus);
|
||||
} catch (err) {
|
||||
dispatch({ type: ACTIONS.REMOVE_CHANNEL_FROM_ACTIVE_LIVESTREAMS, data: { channelId } });
|
||||
LocalStorage.removeItem(statusForId);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue