mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
auh
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -11,7 +11,7 @@
|
|||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||||
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
|
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
|
||||||
<title>Multi Roomba Rover</title>
|
<title>Multi Roomba Rover</title>
|
||||||
<script type="module" crossorigin src="/assets/index-Bm6FTwrt.js"></script>
|
<script type="module" crossorigin src="/assets/index-CAsUvZ8l.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-B1UrCI1T.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-B1UrCI1T.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ export function useRoomCameraSnapshots(sourceList = []) {
|
|||||||
const normalizedEntries = useMemo(() => dedupe(sourceList.map(normalizeCamera).filter(Boolean)), [sourceList]);
|
const normalizedEntries = useMemo(() => dedupe(sourceList.map(normalizeCamera).filter(Boolean)), [sourceList]);
|
||||||
const entriesKey = useMemo(() => normalizedEntries.map((e) => e.key).join('|'), [normalizedEntries]);
|
const entriesKey = useMemo(() => normalizedEntries.map((e) => e.key).join('|'), [normalizedEntries]);
|
||||||
const retryTimers = useRef(new Map());
|
const retryTimers = useRef(new Map());
|
||||||
|
const entriesRef = useRef([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
entriesRef.current = normalizedEntries;
|
||||||
|
}, [normalizedEntries]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
objectUrls.current.forEach((url) => URL.revokeObjectURL(url));
|
objectUrls.current.forEach((url) => URL.revokeObjectURL(url));
|
||||||
@@ -42,10 +47,11 @@ export function useRoomCameraSnapshots(sourceList = []) {
|
|||||||
}, [entriesKey]);
|
}, [entriesKey]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!normalizedEntries.length || !socket) {
|
if (!entriesKey || !socket) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
const entries = entriesRef.current;
|
||||||
|
|
||||||
const clearRetry = (id) => {
|
const clearRetry = (id) => {
|
||||||
const timer = retryTimers.current.get(id);
|
const timer = retryTimers.current.get(id);
|
||||||
@@ -101,7 +107,7 @@ export function useRoomCameraSnapshots(sourceList = []) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const requestSubscribe = (id) => {
|
const requestSubscribe = (id) => {
|
||||||
const entry = normalizedEntries.find((e) => e.id === id);
|
const entry = entries.find((e) => e.id === id);
|
||||||
if (!entry) return;
|
if (!entry) return;
|
||||||
socket.emit('roomCamera:subscribe', { roomCameraId: entry.id }, (resp = {}) => {
|
socket.emit('roomCamera:subscribe', { roomCameraId: entry.id }, (resp = {}) => {
|
||||||
if (resp.error) {
|
if (resp.error) {
|
||||||
@@ -117,11 +123,11 @@ export function useRoomCameraSnapshots(sourceList = []) {
|
|||||||
socket.on('roomCamera:frame', handleFrame);
|
socket.on('roomCamera:frame', handleFrame);
|
||||||
socket.on('roomCamera:status', handleStatus);
|
socket.on('roomCamera:status', handleStatus);
|
||||||
|
|
||||||
normalizedEntries.forEach((entry) => requestSubscribe(entry.id));
|
entries.forEach((entry) => requestSubscribe(entry.id));
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
normalizedEntries.forEach((entry) => {
|
entries.forEach((entry) => {
|
||||||
socket.emit('roomCamera:unsubscribe', { roomCameraId: entry.id });
|
socket.emit('roomCamera:unsubscribe', { roomCameraId: entry.id });
|
||||||
});
|
});
|
||||||
socket.off('roomCamera:frame', handleFrame);
|
socket.off('roomCamera:frame', handleFrame);
|
||||||
@@ -131,7 +137,7 @@ export function useRoomCameraSnapshots(sourceList = []) {
|
|||||||
retryTimers.current.forEach((timer) => clearTimeout(timer));
|
retryTimers.current.forEach((timer) => clearTimeout(timer));
|
||||||
retryTimers.current.clear();
|
retryTimers.current.clear();
|
||||||
};
|
};
|
||||||
}, [socket, normalizedEntries, entriesKey]);
|
}, [socket, entriesKey]);
|
||||||
|
|
||||||
const filtered = useMemo(() => {
|
const filtered = useMemo(() => {
|
||||||
if (!entriesKey) return {};
|
if (!entriesKey) return {};
|
||||||
|
|||||||
Reference in New Issue
Block a user