import { h } from 'preact';
import ActivityIndicator from '../components/ActivityIndicator';
import Button from '../components/Button';
import Heading from '../components/Heading';
import Link from '../components/Link';
import { useConfig, useStats } from '../api';
import { Table, Tbody, Thead, Tr, Th, Td } from '../components/Table';
import { useCallback, useEffect, useState } from 'preact/hooks';
const emptyObject = Object.freeze({});
export default function Debug() {
const config = useConfig();
const [timeoutId, setTimeoutId] = useState(null);
const { data: stats } = useStats(null, timeoutId);
const forceUpdate = useCallback(() => {
const timeoutId = setTimeout(forceUpdate, 1000);
setTimeoutId(timeoutId);
}, []);
useEffect(() => {
forceUpdate();
}, [forceUpdate]);
useEffect(() => {
return () => {
clearTimeout(timeoutId);
};
}, [timeoutId]);
const { detectors, service, detection_fps, ...cameras } = stats || emptyObject;
const detectorNames = Object.keys(detectors || emptyObject);
const detectorDataKeys = Object.keys(detectors ? detectors[detectorNames[0]] : emptyObject);
const cameraNames = Object.keys(cameras || emptyObject);
const cameraDataKeys = Object.keys(cameras[cameraNames[0]] || emptyObject);
const handleCopyConfig = useCallback(() => {
async function copy() {
await window.navigator.clipboard.writeText(JSON.stringify(config, null, 2));
}
copy();
}, [config]);
return stats === null ? (
) : (
Debug {service.version}
detector |
{detectorDataKeys.map((name) => (
{name.replace('_', ' ')} |
))}
{detectorNames.map((detector, i) => (
{detector} |
{detectorDataKeys.map((name) => (
{detectors[detector][name]} |
))}
))}
camera |
{cameraDataKeys.map((name) => (
{name.replace('_', ' ')} |
))}
{cameraNames.map((camera, i) => (
{camera}
|
{cameraDataKeys.map((name) => (
{cameras[camera][name]} |
))}
))}
Config
{JSON.stringify(config, null, 2)}
);
}