mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 17:40:46 -04:00
guh
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -5,7 +5,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>webui</title>
|
<title>webui</title>
|
||||||
<script type="module" crossorigin src="/assets/index-CJa482Eg.js"></script>
|
<script type="module" crossorigin src="/assets/index-CXibTtk4.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-BUE8ypH_.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-BUE8ypH_.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -1,17 +1,24 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useSocket } from '../context/SocketContext.jsx';
|
import { useSocket } from '../context/SocketContext.jsx';
|
||||||
|
|
||||||
export function useVideoRequests(roverIds = []) {
|
export function useVideoRequests(roverIds = []) {
|
||||||
const socket = useSocket();
|
const socket = useSocket();
|
||||||
const [sources, setSources] = useState({});
|
const [sources, setSources] = useState({});
|
||||||
const normalizedKey = Array.isArray(roverIds) ? roverIds.filter(Boolean).join('|') : '';
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!normalizedKey) {
|
const ids = Array.from(new Set(roverIds.filter(Boolean)));
|
||||||
return undefined;
|
if (!ids.length) {
|
||||||
|
setSources({});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const ids = normalizedKey.split('|');
|
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
setSources((prev) => {
|
||||||
|
const next = {};
|
||||||
|
ids.forEach((id) => {
|
||||||
|
if (prev[id]) next[id] = prev[id];
|
||||||
|
});
|
||||||
|
return next;
|
||||||
|
});
|
||||||
ids.forEach((roverId) => {
|
ids.forEach((roverId) => {
|
||||||
socket.emit('video:request', { roverId }, (resp = {}) => {
|
socket.emit('video:request', { roverId }, (resp = {}) => {
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
@@ -25,19 +32,7 @@ export function useVideoRequests(roverIds = []) {
|
|||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [socket, normalizedKey]);
|
}, [socket, roverIds.join('|')]);
|
||||||
|
|
||||||
const filtered = useMemo(() => {
|
return sources;
|
||||||
if (!normalizedKey) return {};
|
|
||||||
const ids = normalizedKey.split('|');
|
|
||||||
const next = {};
|
|
||||||
ids.forEach((id) => {
|
|
||||||
if (sources[id]) {
|
|
||||||
next[id] = sources[id];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return next;
|
|
||||||
}, [normalizedKey, sources]);
|
|
||||||
|
|
||||||
return filtered;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user