mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-12-06 21:44:13 +03:00
* config file changes * config migrator * stream selection on single camera live view * camera streaming settings dialog * manage persistent group streaming settings * apply streaming settings in camera groups * add ability to clear all streaming settings from settings * docs * update reference config * fixes * clarify docs * use first stream as default in dialog * ensure still image is visible after switching stream type to none * docs * clarify docs * add ability to continue playing stream in background * fix props * put stream selection inside dropdown on desktop * add capabilities to live mode hook * live context menu component * resize observer: only return new dimensions if they've actually changed * pass volume prop to players * fix slider bug, https://github.com/shadcn-ui/ui/issues/1448 * update react-grid-layout * prevent animated transitions on draggable grid layout * add context menu to dashboards * use provider * streaming dialog from context menu * docs * add jsmpeg warning to context menu * audio and two way talk indicators in single camera view * add link to debug view * don't use hook * create manual events from live camera view * maintain grow classes on grid items * fix initial volume state on default dashboard * fix pointer events causing context menu to end up underneath image on iOS * mobile drawer tweaks * stream stats * show settings menu for non-restreamed cameras * consistent settings icon * tweaks * optional stats to fix birdseye player * add toaster to live camera view * fix crash on initial save in streaming dialog * don't require restreaming for context menu streaming settings * add debug view to context menu * stats fixes * update docs * always show stream info when restreamed * update camera streaming dialog * make note of no h265 support for webrtc * docs clarity * ensure docs show streams as a dict * docs clarity * fix css file * tweaks
70 lines
1.7 KiB
TypeScript
70 lines
1.7 KiB
TypeScript
import { MutableRefObject, useEffect, useMemo, useState } from "react";
|
|
|
|
type RefType = MutableRefObject<Element | null> | Window;
|
|
|
|
export function useResizeObserver(...refs: RefType[]) {
|
|
const [dimensions, setDimensions] = useState<
|
|
{ width: number; height: number; x: number; y: number }[]
|
|
>(
|
|
new Array(refs.length).fill({
|
|
width: 0,
|
|
height: 0,
|
|
x: -Infinity,
|
|
y: -Infinity,
|
|
}),
|
|
);
|
|
const resizeObserver = useMemo(
|
|
() =>
|
|
new ResizeObserver((entries) => {
|
|
window.requestAnimationFrame(() => {
|
|
setDimensions((prevDimensions) => {
|
|
const newDimensions = entries.map((entry) => entry.contentRect);
|
|
if (
|
|
JSON.stringify(prevDimensions) !== JSON.stringify(newDimensions)
|
|
) {
|
|
return newDimensions;
|
|
}
|
|
return prevDimensions;
|
|
});
|
|
});
|
|
}),
|
|
[],
|
|
);
|
|
|
|
useEffect(() => {
|
|
refs.forEach((ref) => {
|
|
if (ref instanceof Window) {
|
|
resizeObserver.observe(document.body);
|
|
} else if (ref.current) {
|
|
resizeObserver.observe(ref.current);
|
|
}
|
|
});
|
|
|
|
return () => {
|
|
refs.forEach((ref) => {
|
|
if (ref instanceof Window) {
|
|
resizeObserver.unobserve(document.body);
|
|
} else if (ref.current) {
|
|
resizeObserver.unobserve(ref.current);
|
|
}
|
|
});
|
|
};
|
|
}, [refs, resizeObserver]);
|
|
|
|
if (dimensions.length == refs.length) {
|
|
return dimensions;
|
|
} else {
|
|
const items = [...dimensions];
|
|
for (let i = dimensions.length; i < refs.length; i++) {
|
|
items.push({
|
|
width: 0,
|
|
height: 0,
|
|
x: -Infinity,
|
|
y: -Infinity,
|
|
});
|
|
}
|
|
|
|
return items;
|
|
}
|
|
}
|