Improve live detection on channel page

Call bitwave live API immediately on page load.
Reduce poll to 15 second interval
Fix incorrect data parsing
This commit is contained in:
DispatchCommit 2021-03-21 22:06:11 -07:00
parent 76ac4c19b9
commit 816bd07570

View file

@ -35,7 +35,7 @@ export default function LivestreamLink(props: Props) {
fetch(`${BITWAVE_API}/${livestreamChannelId}`)
.then((res) => res.json())
.then((res) => {
if (res && res.data && res.data.success && res.data.data && res.data.data.live) {
if (res && res.success && res.data && res.data.live) {
setIsLivestreaming(true);
} else {
setIsLivestreaming(false);
@ -45,7 +45,8 @@ export default function LivestreamLink(props: Props) {
}
let interval;
if (livestreamChannelId) {
interval = setInterval(fetchIsStreaming, 5000);
if (!interval) fetchIsStreaming();
interval = setInterval(fetchIsStreaming, 15 * 1000);
}
return () => {
if (interval) {