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,
|
2022-06-09 20:43:45 +02:00
|
|
|
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();
|
|
|
|
|
2022-06-09 20:43:45 +02:00
|
|
|
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
|
|
|
|
2022-06-09 20:43:45 +02:00
|
|
|
return () => clearInterval(intervalId);
|
|
|
|
}
|
|
|
|
}, [channelClaimId, doFetchChannelLiveStatus, fasterPoll, poll]);
|
2022-03-16 18:35:27 +01:00
|
|
|
}
|