import { Modal } from "antd"; import { inject, observer } from "mobx-react"; import { useEffect, useState } from "react"; import Config from "@/util/config"; import EasyPlayer from "../videoTow"; const WhichVideo = (props) => { const { homeStore } = props; const [isModalOpen, setIsModalOpen] = useState(false); const [deviceList, setDeviceList] = useState>([]); const [channelList, setChannelList] = useState>([]); const [deviceId, setDeviceId] = useState(0); const [channelId, setChannelId] = useState(0); const [videoUrl, setVideoUrl] = useState(""); let timer: any = null; const openDispatch = async () => { setIsModalOpen(true); let req = await homeStore.getVideoUrlList(); setDeviceList(req.EasyDarwin.Body.Devices); }; const getChannerList = async (id) => { let reqs = await homeStore.getChannerUrlList(id); setChannelList(reqs.EasyDarwin.Body.Channels); }; const getUrl = async (id) => { if (timer) { clearInterval(timer); } const fetchUrl = async () => { try { const reqs = await homeStore.getChannerStrem(deviceId, id); if (!reqs.EasyDarwin) return; const url = Config.videoApis + reqs.EasyDarwin.Body.URL; setVideoUrl(url); } catch (error) { console.error("Error fetching video URL:", error); } }; fetchUrl(); timer = setInterval(() => { fetchUrl(); }, 35000); }; useEffect(() => { return () => { clearInterval(timer); }; }, []); return ( <> 视频查看 { setDeviceList([]); setChannelList([]); setVideoUrl(null); setChannelId(0); }} onOk={() => {}} footer={null} onCancel={() => { setIsModalOpen(false); }} >
{deviceList.map((item, index) => { return (
{ setDeviceId(item.DeviceID); getChannerList(item.DeviceID); }} >

{item.DeviceName}

); })}
{channelList.map((item, index) => { return (
{ setChannelId(item.ChannelID); getUrl(item.ChannelID); }} >

{item.Name}

); })}
{}
); }; // export default WhichVideo; export default inject("homeStore")(observer(WhichVideo));