forked from Github/frigate
feat(web): AutoUpdatingCameraImage to replace MJPEG feed
This commit is contained in:
committed by
Blake Blackshear
parent
633d45d02f
commit
a862ba8348
27
web/src/components/AutoUpdatingCameraImage.jsx
Normal file
27
web/src/components/AutoUpdatingCameraImage.jsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { h } from 'preact';
|
||||
import { ApiHost, Config } from '../context';
|
||||
import { useCallback, useEffect, useContext, useState } from 'preact/hooks';
|
||||
|
||||
export default function AutoUpdatingCameraImage({ camera, searchParams }) {
|
||||
const config = useContext(Config);
|
||||
const apiHost = useContext(ApiHost);
|
||||
const cameraConfig = config.cameras[camera];
|
||||
|
||||
const [key, setKey] = useState(Date.now());
|
||||
useEffect(() => {
|
||||
const timeoutId = setTimeout(() => {
|
||||
setKey(Date.now());
|
||||
}, 500);
|
||||
return () => {
|
||||
clearTimeout(timeoutId);
|
||||
};
|
||||
}, [key, searchParams]);
|
||||
|
||||
return (
|
||||
<img
|
||||
className="w-full"
|
||||
src={`${apiHost}/api/${camera}/latest.jpg?cache=${key}&${searchParams}`}
|
||||
alt={`Auto-updating ${camera} image`}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user