This commit is contained in:
legop3
2025-12-02 00:25:00 -05:00
parent c94abeca07
commit 1c4b9b8c3d
3 changed files with 42 additions and 10 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -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-BnAIu6Ae.js"></script> <script type="module" crossorigin src="/assets/index-CnvHZcbU.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-B1UrCI1T.css"> <link rel="stylesheet" crossorigin href="/assets/index-B1UrCI1T.css">
</head> </head>
<body> <body>
+33 -1
View File
@@ -8,6 +8,7 @@ export function useRoomCameraSnapshots(sourceList = []) {
const ids = useMemo(() => sourceList.map((e) => (typeof e === 'string' ? e : e.id)), [sourceList]); const ids = useMemo(() => sourceList.map((e) => (typeof e === 'string' ? e : e.id)), [sourceList]);
const idsKey = useMemo(() => ids.join('|'), [ids]); const idsKey = useMemo(() => ids.join('|'), [ids]);
const idsRef = useRef([]); const idsRef = useRef([]);
const retryTimer = useRef(null);
useEffect(() => { useEffect(() => {
idsRef.current = ids; idsRef.current = ids;
@@ -17,6 +18,10 @@ export function useRoomCameraSnapshots(sourceList = []) {
objectUrls.current.forEach((url) => URL.revokeObjectURL(url)); objectUrls.current.forEach((url) => URL.revokeObjectURL(url));
objectUrls.current.clear(); objectUrls.current.clear();
setFeeds({}); setFeeds({});
if (retryTimer.current) {
clearTimeout(retryTimer.current);
retryTimer.current = null;
}
}, [idsKey]); }, [idsKey]);
useEffect(() => { useEffect(() => {
@@ -60,12 +65,35 @@ export function useRoomCameraSnapshots(sourceList = []) {
objectUrl: prev[meta.id]?.objectUrl || null, objectUrl: prev[meta.id]?.objectUrl || null,
}, },
})); }));
if (meta.error && !cancelled) {
scheduleRetry();
}
};
const scheduleRetry = (delay = 5000) => {
if (retryTimer.current) {
clearTimeout(retryTimer.current);
}
retryTimer.current = setTimeout(() => {
retryTimer.current = null;
if (!cancelled) {
socket.emit('roomCamera:subscribe', { ids: currentIds }, (resp = {}) => {
if (resp.error && !retryTimer.current) {
scheduleRetry();
}
});
}
}, delay);
}; };
socket.on('roomCamera:frame', handleFrame); socket.on('roomCamera:frame', handleFrame);
socket.on('roomCamera:status', handleStatus); socket.on('roomCamera:status', handleStatus);
socket.emit('roomCamera:subscribe', { ids: currentIds }); socket.emit('roomCamera:subscribe', { ids: currentIds }, (resp = {}) => {
if (resp.error) {
scheduleRetry();
}
});
return () => { return () => {
cancelled = true; cancelled = true;
@@ -74,6 +102,10 @@ export function useRoomCameraSnapshots(sourceList = []) {
socket.off('roomCamera:status', handleStatus); socket.off('roomCamera:status', handleStatus);
objectUrls.current.forEach((url) => URL.revokeObjectURL(url)); objectUrls.current.forEach((url) => URL.revokeObjectURL(url));
objectUrls.current.clear(); objectUrls.current.clear();
if (retryTimer.current) {
clearTimeout(retryTimer.current);
retryTimer.current = null;
}
}; };
}, [socket, idsKey]); }, [socket, idsKey]);