import Navbar from "../components/Navbar/Navbar"; import VideoPlayer from "../components/VideoPlayer/VideoPlayer"; import VodCardController from "../components/VodCardController"; import styles from "./Home.module.css"; import * as config from "../config"; import LiveAPI from "../live-stream-api"; import React, { useEffect, useState } from "react"; function LiveComponent(props) { return ( <> { props.isLive === "Yes" ? (

{props.title}

{props.subtitle} • {`${props.viewers} viewers`}

) : ( <>

Channel Offline

)} ); } function Home() { const [response, setResponse] = useState(false); const [timerID, setTimerID] = useState(false); const fetchAPI = () => { if (config.USE_MOCK_DATA === true){ const API_RETURN = LiveAPI.data; setResponse(API_RETURN); } else { // Call API and set the matched value if we're mounted const getLiveChannelUrl = `${config.API_URL}/live`; fetch(getLiveChannelUrl) .then(response => response.json()) .then((res) => { setResponse(res.data); }) .catch((error) => { console.error(error); }); } } useEffect(() => { // Set mounted to true so that we know when first mount has happened let mounted = true; if (!timerID && mounted) { fetchAPI(); const timer = setInterval(() => { fetchAPI(); }, config.POLL_DELAY_MS) setTimerID(timer); } // Set mounted to false & clear the interval when the component is unmounted return () => { mounted = false; clearInterval(timerID); } }, [timerID]) return ( <>

Recorded streams

); } export default Home;