lbry-desktop/ui/effects/use-fetch-live.js

24 lines
785 B
JavaScript
Raw Normal View History

2022-03-16 18:35:27 +01:00
// @flow
import React from 'react';
import { LIVESTREAM_STATUS_CHECK_INTERVAL_SOON, LIVESTREAM_STATUS_CHECK_INTERVAL } from 'constants/livestream';
export default function useFetchLiveStatus(
channelClaimId: ?string,
doFetchChannelLiveStatus: (string) => void,
fasterPoll?: boolean
) {
// Find out current channels status + active live claim every 30 seconds
React.useEffect(() => {
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);
return () => clearInterval(intervalId);
}, [channelClaimId, doFetchChannelLiveStatus, fasterPoll]);
}