mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 17:40:46 -04:00
vieo
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useSocket } from '../context/SocketContext.jsx';
|
||||
|
||||
export function useSensorFeed() {
|
||||
const socket = useSocket();
|
||||
const [frames, setFrames] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
function handleFrame({ roverId, sensors = {}, frame = {} }) {
|
||||
if (!roverId) return;
|
||||
setFrames((prev) => ({
|
||||
...prev,
|
||||
[roverId]: {
|
||||
roverId,
|
||||
sensors,
|
||||
raw: frame?.data || null,
|
||||
receivedAt: Date.now(),
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
socket.on('sensorFrame', handleFrame);
|
||||
return () => {
|
||||
socket.off('sensorFrame', handleFrame);
|
||||
};
|
||||
}, [socket]);
|
||||
|
||||
return frames;
|
||||
}
|
||||
@@ -7,9 +7,18 @@ export function useVideoRequests(roverIds = []) {
|
||||
|
||||
useEffect(() => {
|
||||
const ids = Array.from(new Set(roverIds.filter(Boolean)));
|
||||
if (!ids.length) return;
|
||||
if (!ids.length) {
|
||||
setSources({});
|
||||
return;
|
||||
}
|
||||
let cancelled = false;
|
||||
|
||||
setSources((prev) => {
|
||||
const next = {};
|
||||
ids.forEach((id) => {
|
||||
if (prev[id]) next[id] = prev[id];
|
||||
});
|
||||
return next;
|
||||
});
|
||||
ids.forEach((roverId) => {
|
||||
socket.emit('video:request', { roverId }, (resp = {}) => {
|
||||
if (cancelled) return;
|
||||
|
||||
Reference in New Issue
Block a user