Improve thumbnails and live player (#9828)

* Don't show gif until event is over and fix aspect

* Be more efficient about updating events

* ensure previews are sorted

* Don't show live view when window is not visible

* Move debug camera to separate view

* Improve jpg loading

* Ensure still is updated on player live finish

* Don't reload when window not visible

* Only disconnect instead of full remove

* Use start time instead of event over to determine gif
This commit is contained in:
Nicolas Mowen
2024-02-12 18:28:36 -07:00
committed by GitHub
parent f54cb21bd0
commit 63bc1b1582
8 changed files with 298 additions and 167 deletions

View File

@@ -1,4 +1,4 @@
import { useCallback, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import CameraImage from "./CameraImage";
type AutoUpdatingCameraImageProps = {
@@ -20,19 +20,41 @@ export default function AutoUpdatingCameraImage({
}: AutoUpdatingCameraImageProps) {
const [key, setKey] = useState(Date.now());
const [fps, setFps] = useState<string>("0");
const [timeoutId, setTimeoutId] = useState<NodeJS.Timeout>();
useEffect(() => {
if (reloadInterval == -1) {
return;
}
setKey(Date.now());
return () => {
if (timeoutId) {
clearTimeout(timeoutId);
setTimeoutId(undefined);
}
};
}, [reloadInterval]);
const handleLoad = useCallback(() => {
if (reloadInterval == -1) {
return;
}
const loadTime = Date.now() - key;
if (showFps) {
setFps((1000 / Math.max(loadTime, reloadInterval)).toFixed(1));
}
setTimeout(
() => {
setKey(Date.now());
},
loadTime > reloadInterval ? 1 : reloadInterval
setTimeoutId(
setTimeout(
() => {
setKey(Date.now());
},
loadTime > reloadInterval ? 1 : reloadInterval
)
);
}, [key, setFps]);