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

27 lines
837 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,
poll?: boolean,
2022-03-16 18:35:27 +01:00
fasterPoll?: boolean
) {
// Find out current channels status + active live claim every 30 seconds
React.useEffect(() => {
if (!channelClaimId) return;
const fetch = () => doFetchChannelLiveStatus(channelClaimId || '');
fetch();
if (poll) {
const interval = fasterPoll ? LIVESTREAM_STATUS_CHECK_INTERVAL_SOON : LIVESTREAM_STATUS_CHECK_INTERVAL;
const intervalId = setInterval(fetch, interval);
2022-03-16 18:35:27 +01:00
return () => clearInterval(intervalId);
}
}, [channelClaimId, doFetchChannelLiveStatus, fasterPoll, poll]);
2022-03-16 18:35:27 +01:00
}