import { h, Fragment } from 'preact'; import AutoUpdatingCameraImage from '../components/AutoUpdatingCameraImage'; import ActivityIndicator from '../components/ActivityIndicator'; import JSMpegPlayer from '../components/JSMpegPlayer'; import Button from '../components/Button'; import Card from '../components/Card'; import Heading from '../components/Heading'; import Link from '../components/Link'; import SettingsIcon from '../icons/Settings'; import Switch from '../components/Switch'; import ButtonsTabbed from '../components/ButtonsTabbed'; import { usePersistence } from '../context'; import { useCallback, useMemo, useState } from 'preact/hooks'; import { useApiHost } from '../api'; import useSWR from 'swr'; import WebRtcPlayer from '../components/WebRtcPlayer'; import MsePlayer from '../components/MsePlayer'; const emptyObject = Object.freeze({}); export default function Camera({ camera }) { const { data: config } = useSWR('config'); const apiHost = useApiHost(); const [showSettings, setShowSettings] = useState(false); const [viewMode, setViewMode] = useState('live'); const cameraConfig = config?.cameras[camera]; const jsmpegWidth = cameraConfig ? Math.round(cameraConfig.restream.jsmpeg.height * (cameraConfig.detect.width / cameraConfig.detect.height)) : 0; const [viewSource, setViewSource, sourceIsLoaded] = usePersistence(`${camera}-source`, 'mse'); const sourceValues = cameraConfig && cameraConfig.restream.enabled ? ['mse', 'webrtc', 'jsmpeg'] : ['mse']; const [options, setOptions] = usePersistence(`${camera}-feed`, emptyObject); const handleSetOption = useCallback( (id, value) => { const newOptions = { ...options, [id]: value }; setOptions(newOptions); }, [options, setOptions] ); const searchParams = useMemo( () => new URLSearchParams( Object.keys(options).reduce((memo, key) => { memo.push([key, options[key] === true ? '1' : '0']); return memo; }, []) ), [options] ); const handleToggleSettings = useCallback(() => { setShowSettings(!showSettings); }, [showSettings, setShowSettings]); if (!cameraConfig || !sourceIsLoaded) { return ; } const optionContent = showSettings ? (
Mask & Zone creator
) : null; let player; if (viewMode === 'live') { if (viewSource == 'mse') { player = (
); } else if (viewSource == 'webrtc') { player = (
); } else { player = (
); } } else if (viewMode === 'debug') { player = (
{showSettings ? : null}
); } return (
{camera.replaceAll('_', ' ')}
{player}
Tracked objects
{cameraConfig.objects.track.map((objectType) => ( } /> ))}
); }