声网视频组件完成 总览界面和 任务规划界面 都显示 了 根据机器配备的几路视频 显示
This commit is contained in:
@@ -1,281 +1,346 @@
|
|||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import AgoraRTC, { IAgoraRTCClient, IRemoteVideoTrack } from "agora-rtc-sdk-ng";
|
import AgoraRTC, { IAgoraRTCClient, IRemoteVideoTrack } from 'agora-rtc-sdk-ng';
|
||||||
import { Badge, message } from "antd";
|
import { Badge, message } from 'antd';
|
||||||
|
|
||||||
AgoraRTC.setLogLevel(2); // 2=只输出warning/error,屏蔽debug日志
|
// 日志等级:2=仅 warning/error,屏蔽 debug 噪点
|
||||||
|
AgoraRTC.setLogLevel(2);
|
||||||
|
|
||||||
const APP_ID = "5afc6f096ddf433aa690df6f251274a4";
|
const APP_ID = '5afc6f096ddf433aa690df6f251274a4';
|
||||||
const TOKEN = "007eJxTYHj/XqzNYP1utbUqvUkLly0/ypRz8liNgdKBqBeqqzX3+WgqMJgmpiWbpRlYmqWkpJkYGycmmlkapKSZpRmZGhqZmySaRH37ndUQyMjgu3k5KyMDBIL47AzJiblGuobmDAwA6vwg4g==";
|
const TOKEN =
|
||||||
|
'007eJxTYHj/XqzNYP1utbUqvUkLly0/ypRz8liNgdKBqBeqqzX3+WgqMJgmpiWbpRlYmqWkpJkYGycmmlkapKSZpRmZGhqZmySaRH37ndUQyMjgu3k5KyMDBIL47AzJiblGuobmDAwA6vwg4g==';
|
||||||
|
|
||||||
export default function AgrtcRoomRobot({ CHANNEL }: { CHANNEL: string }) {
|
/**
|
||||||
const [uid] = useState(() => Number(Math.floor(Math.random() * 100000)));
|
* 每路摄像头在 Agora 频道内用固定 UID 区分:
|
||||||
|
* 101 = cam0 (GMSL A) = 前视
|
||||||
|
* 102 = cam1 (GMSL B) = 左视
|
||||||
|
* 103 = cam2 (GMSL C) = 后视
|
||||||
|
* 104 = cam3 (GMSL D) = 右视
|
||||||
|
*/
|
||||||
|
/** 按摄像头路数选默认 UID:2 路时优先前+后 */
|
||||||
|
export const DEFAULT_UIDS_BY_COUNT: Record<number, number[]> = {
|
||||||
|
1: [101],
|
||||||
|
2: [101, 103],
|
||||||
|
3: [101, 102, 103],
|
||||||
|
4: [101, 102, 103, 104],
|
||||||
|
};
|
||||||
|
export const DEFAULT_CAMERA_UIDS = [101, 102, 103, 104];
|
||||||
|
export const CAMERA_UID_LABEL: Record<number, string> = {
|
||||||
|
101: '前视',
|
||||||
|
102: '左视',
|
||||||
|
|
||||||
|
103: '后视',
|
||||||
|
104: '右视',
|
||||||
|
};
|
||||||
|
|
||||||
|
interface AgrtcRoomRobotProps {
|
||||||
|
/** 机器人 SN → 一个 Agora 频道 */
|
||||||
|
channel?: string;
|
||||||
|
/** 向后兼容:channel 的别名 */
|
||||||
|
CHANNEL?: string;
|
||||||
|
/** 当前机器人有几路摄像头(从 deviceRunParamSelectByDeviceId 的 cameraNum 字段取),1-4 */
|
||||||
|
cameraCount?: number;
|
||||||
|
/**
|
||||||
|
* 显式指定本次只订阅哪些 UID(单路视图模式:front/back/left/right 各传一个 UID;all/grid 不传则按 cameraCount 取前 N 个默认 UID)
|
||||||
|
* 留空时取 DEFAULT_CAMERA_UIDS.slice(0, cameraCount)
|
||||||
|
*/
|
||||||
|
slotUids?: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SlotRuntime {
|
||||||
|
uid: number;
|
||||||
|
containerRef: React.RefObject<HTMLDivElement>;
|
||||||
|
track: IRemoteVideoTrack | null;
|
||||||
|
subscribedUid: number | null;
|
||||||
|
hasVideo: boolean;
|
||||||
|
unpublishTimer: NodeJS.Timeout | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AgrtcRoomRobot(props: AgrtcRoomRobotProps) {
|
||||||
|
const channel = "cam2-17" || props.channel || props.CHANNEL || '';
|
||||||
|
const cameraCount = Math.max(1, Math.min(4, Number(props.cameraCount) || 1));
|
||||||
|
|
||||||
|
// 订阅 UID 列表:外部显式 slotUids > 默认按 cameraCount 截断
|
||||||
|
const slotUids = useMemo(() => {
|
||||||
|
if (Array.isArray(props.slotUids) && props.slotUids.length > 0) {
|
||||||
|
return props.slotUids.filter((n) => Number.isFinite(n) && n >= 1);
|
||||||
|
}
|
||||||
|
return DEFAULT_UIDS_BY_COUNT[cameraCount] || [101];
|
||||||
|
}, [props.slotUids, cameraCount]);
|
||||||
|
|
||||||
|
const [mountKey, setMountKey] = useState(0);
|
||||||
const [connected, setConnected] = useState(false);
|
const [connected, setConnected] = useState(false);
|
||||||
const [joined, setJoined] = useState(false);
|
const [joined, setJoined] = useState(false);
|
||||||
const [hasRemoteVideo, setHasRemoteVideo] = useState(false);
|
|
||||||
|
|
||||||
const remoteVideoRef = useRef<HTMLDivElement>(null);
|
|
||||||
const clientRef = useRef<IAgoraRTCClient | null>(null);
|
|
||||||
const remoteVideoTrackRef = useRef<IRemoteVideoTrack | null>(null);
|
|
||||||
const joiningRef = useRef(false);
|
|
||||||
const reconnectTimerRef = useRef<NodeJS.Timeout | null>(null);
|
|
||||||
const subscribedUidRef = useRef<number | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const client = AgoraRTC.createClient({
|
setMountKey((k) => k + 1);
|
||||||
mode: "live",
|
}, [channel, slotUids.join(',')]);
|
||||||
codec: "h264",
|
|
||||||
});
|
|
||||||
clientRef.current = client;
|
|
||||||
client.setClientRole("audience");
|
|
||||||
// ========= 删掉了 setParameters,Web NG不支持!========
|
|
||||||
|
|
||||||
let isUnmounted = false;
|
if (!channel) {
|
||||||
let videoWatchDogTimer: NodeJS.Timeout | null = null;
|
return (
|
||||||
let unpublishTimer: NodeJS.Timeout | null = null;
|
<div style={{ width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#aaa', background: '#000', borderRadius: 8 }}>
|
||||||
|
无可订阅频道
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const clearRemoteVideo = () => {
|
return (
|
||||||
if (remoteVideoTrackRef.current) {
|
<AgrtcSingleChannel
|
||||||
|
key={mountKey}
|
||||||
|
channel={channel}
|
||||||
|
slotUids={slotUids}
|
||||||
|
onConnect={setConnected}
|
||||||
|
onJoin={setJoined}
|
||||||
|
>
|
||||||
|
{(renderProps) => {
|
||||||
|
const gridStyle = pickGridStyle(slotUids.length);
|
||||||
|
return (
|
||||||
|
<div style={{ width: '100%', height: '100%', display: 'flex', flexDirection: 'column', borderRadius: 8, overflow: 'hidden', background: '#000' }}>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center', gap: 12, padding: '4px 8px', background: 'rgba(255,255,255,0.08)', flexShrink: 0, flexWrap: 'wrap' }}>
|
||||||
|
<Badge
|
||||||
|
color={connected ? 'green' : 'red'}
|
||||||
|
text={connected ? 'RTC已连接' : 'RTC未连接'}
|
||||||
|
style={{ content: { color: '#ffffff' } }}
|
||||||
|
className={'badge-rtc-connected'}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Badge
|
||||||
|
color={joined ? 'green' : 'orange'}
|
||||||
|
text={joined ? '已加入频道' : '未加入频道'}
|
||||||
|
styles={{ content: { color: '#ffffff' } }}
|
||||||
|
className={'badge-rtc-connected'}
|
||||||
|
|
||||||
|
/>
|
||||||
|
<span style={{ fontSize: 11, color: '#888' }}>共 {slotUids.length} 路</span>
|
||||||
|
</div>
|
||||||
|
<div style={{ flex: 1, width: '100%', minHeight: 0, position: 'relative', padding: 4 }}>
|
||||||
|
<div style={{ width: '100%', height: '100%', ...gridStyle }}>
|
||||||
|
{slotUids.map((uid) => {
|
||||||
|
const slot = renderProps.slotsByUid.get(uid);
|
||||||
|
const hasVideo = slot?.hasVideo || false;
|
||||||
|
const label = CAMERA_UID_LABEL[uid] || `UID ${uid}`;
|
||||||
|
return (
|
||||||
|
<div key={uid} style={{ position: 'relative', width: '100%', height: '100%', background: '#000', borderRadius: 6, overflow: 'hidden' }}>
|
||||||
|
<div style={{ position: 'absolute', top: 4, left: 6, zIndex: 3, fontSize: 11, color: '#fff', background: 'rgba(0,0,0,0.5)', padding: '2px 6px', borderRadius: 4, maxWidth: '80%', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
||||||
|
{label}
|
||||||
|
</div>
|
||||||
|
<div ref={slot?.containerRef} style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', zIndex: 1 }} />
|
||||||
|
{!hasVideo && (
|
||||||
|
<div style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#aaa', fontSize: 12, background: '#000', zIndex: 2 }}>
|
||||||
|
等待推流 (UID {uid})…
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</AgrtcSingleChannel>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickGridStyle(count: number): React.CSSProperties {
|
||||||
|
if (count <= 1) return { display: 'grid', gridTemplateColumns: '1fr', gridTemplateRows: '1fr', gap: 4 };
|
||||||
|
if (count === 2) return { display: 'grid', gridTemplateColumns: '1fr', gridTemplateRows: '1fr 1fr', gap: 4 };
|
||||||
|
return { display: 'grid', gridTemplateColumns: '1fr 1fr', gridTemplateRows: '1fr 1fr', gap: 4 };
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AgrtcSingleChannelProps {
|
||||||
|
channel: string;
|
||||||
|
slotUids: number[];
|
||||||
|
onConnect: (c: boolean) => void;
|
||||||
|
onJoin: (j: boolean) => void;
|
||||||
|
children: (renderProps: { slotsByUid: Map<number, SlotRuntime> }) => React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
function AgrtcSingleChannel({ channel, slotUids, onConnect, onJoin, children }: AgrtcSingleChannelProps) {
|
||||||
|
// 用 Map 做按 UID 索引的 slot,避免 React 重建循环引用
|
||||||
|
const slotsRef = useRef<Map<number, SlotRuntime>>(new Map());
|
||||||
|
const [, forceTick] = useState(0);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const slotsByUid = new Map<number, SlotRuntime>();
|
||||||
|
const containerKeyByUid = new Map<number, React.RefObject<HTMLDivElement>>();
|
||||||
|
for (const uid of slotUids) {
|
||||||
|
containerKeyByUid.set(uid, React.createRef<HTMLDivElement>());
|
||||||
|
slotsByUid.set(uid, {
|
||||||
|
uid,
|
||||||
|
containerRef: containerKeyByUid.get(uid)!,
|
||||||
|
track: null,
|
||||||
|
subscribedUid: null,
|
||||||
|
hasVideo: false,
|
||||||
|
unpublishTimer: null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
slotsRef.current = slotsByUid;
|
||||||
|
forceTick((v) => v + 1);
|
||||||
|
|
||||||
|
const client: IAgoraRTCClient = AgoraRTC.createClient({ mode: 'live', codec: 'h264' });
|
||||||
|
console.log('[AGRTC] init channel=' + channel + ', slotUids=' + JSON.stringify(slotUids));
|
||||||
|
client.setClientRole('audience');
|
||||||
|
|
||||||
|
const localUid = Number(Math.floor(Math.random() * 100000) + 1);
|
||||||
|
let unmounted = false;
|
||||||
|
|
||||||
|
const clearSlotTrack = (uid: number) => {
|
||||||
|
const slot = slotsRef.current.get(uid);
|
||||||
|
if (!slot) return;
|
||||||
|
if (slot.track) {
|
||||||
try {
|
try {
|
||||||
remoteVideoTrackRef.current.stop();
|
slot.track.stop();
|
||||||
} catch (e) {
|
} catch { }
|
||||||
console.warn("stop track error", e);
|
slot.track = null;
|
||||||
}
|
|
||||||
remoteVideoTrackRef.current = null;
|
|
||||||
}
|
}
|
||||||
subscribedUidRef.current = null;
|
slot.subscribedUid = null;
|
||||||
setHasRemoteVideo(false);
|
slot.hasVideo = false;
|
||||||
if (videoWatchDogTimer) clearInterval(videoWatchDogTimer);
|
if (slot.unpublishTimer) {
|
||||||
|
clearTimeout(slot.unpublishTimer);
|
||||||
|
slot.unpublishTimer = null;
|
||||||
|
}
|
||||||
|
forceTick((v) => v + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
const startVideoWatchDog = () => {
|
const playIntoSlot = async (uid: number, track: IRemoteVideoTrack) => {
|
||||||
if (videoWatchDogTimer) clearInterval(videoWatchDogTimer);
|
const slot = slotsRef.current.get(uid);
|
||||||
videoWatchDogTimer = setInterval(async () => {
|
if (!slot || !slot.containerRef.current) return;
|
||||||
const track = remoteVideoTrackRef.current;
|
|
||||||
const dom = remoteVideoRef.current;
|
|
||||||
if (!track || !dom) return;
|
|
||||||
const videoEl = dom.querySelector("video") as HTMLVideoElement;
|
|
||||||
if (!videoEl) return;
|
|
||||||
if (videoEl.readyState < 2) {
|
|
||||||
console.warn("看门狗检测视频无画面,尝试重新play");
|
|
||||||
try {
|
|
||||||
await track.play(dom);
|
|
||||||
} catch (e) {
|
|
||||||
console.warn("看门狗play异常", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 3000);
|
|
||||||
};
|
|
||||||
|
|
||||||
const playRemoteTrack = async (track: IRemoteVideoTrack) => {
|
|
||||||
const dom = remoteVideoRef.current;
|
|
||||||
if (!dom || !track) return;
|
|
||||||
try {
|
try {
|
||||||
await track.play(dom);
|
await track.play(slot.containerRef.current);
|
||||||
console.log("远端视频播放成功");
|
slot.track = track;
|
||||||
setHasRemoteVideo(true);
|
slot.hasVideo = true;
|
||||||
startVideoWatchDog();
|
forceTick((v) => v + 1);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.name === "AbortError") {
|
if (err?.name === 'AbortError') return;
|
||||||
console.warn("播放请求被中断 AbortError,忽略", err);
|
console.error('[AGRTC] play failed', channel, uid, err);
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.error("视频播放失败", err);
|
|
||||||
message.error("视频播放失败");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const doReconnect = async () => {
|
const onUserPublished = async (user: any, mediaType: 'video' | 'audio') => {
|
||||||
if (isUnmounted || joiningRef.current) return;
|
if (unmounted || mediaType !== 'video') return;
|
||||||
console.log("执行RTC重连(信令断开)");
|
const uid = Number(user.uid);
|
||||||
clearRemoteVideo();
|
if (!slotUids.includes(uid)) return; // 只关心我们订阅的摄像头 UID
|
||||||
setJoined(false);
|
const slot = slotsRef.current.get(uid);
|
||||||
|
if (!slot || slot.subscribedUid === user.uid) return;
|
||||||
|
if (slot.unpublishTimer) {
|
||||||
|
clearTimeout(slot.unpublishTimer);
|
||||||
|
slot.unpublishTimer = null;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
joiningRef.current = true;
|
await client.subscribe(user, 'video');
|
||||||
await client.join(APP_ID, CHANNEL, TOKEN, uid);
|
slot.subscribedUid = user.uid;
|
||||||
if (isUnmounted) return;
|
if (user.videoTrack) {
|
||||||
setJoined(true);
|
await playIntoSlot(uid, user.videoTrack);
|
||||||
message.info("RTC重连成功");
|
|
||||||
for (const remoteUser of client.remoteUsers) {
|
|
||||||
if (isUnmounted) break;
|
|
||||||
if (remoteUser.hasVideo && subscribedUidRef.current !== remoteUser.uid) {
|
|
||||||
await client.subscribe(remoteUser, "video");
|
|
||||||
remoteVideoTrackRef.current = remoteUser.videoTrack;
|
|
||||||
subscribedUidRef.current = remoteUser.uid;
|
|
||||||
await playRemoteTrack(remoteUser.videoTrack!);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (e) {
|
||||||
if (err?.code !== "OPERATION_ABORTED") {
|
console.error('[AGRTC] subscribe failed', channel, uid, e);
|
||||||
console.error("重连失败", err);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
joiningRef.current = false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onConnStateChange = (curState: string, prevState: string) => {
|
const onUserUnpublished = (user: any, mediaType: 'video' | 'audio') => {
|
||||||
if (isUnmounted) return;
|
if (unmounted || mediaType !== 'video') return;
|
||||||
console.log("连接状态变更", prevState, "→", curState);
|
const uid = Number(user.uid);
|
||||||
setConnected(curState === "CONNECTED");
|
if (!slotUids.includes(uid)) return;
|
||||||
if (curState === "DISCONNECTED") {
|
const slot = slotsRef.current.get(uid);
|
||||||
clearRemoteVideo();
|
if (!slot || slot.subscribedUid !== user.uid) return;
|
||||||
if (reconnectTimerRef.current) clearTimeout(reconnectTimerRef.current);
|
if (slot.unpublishTimer) clearTimeout(slot.unpublishTimer);
|
||||||
reconnectTimerRef.current = setTimeout(() => {
|
slot.unpublishTimer = setTimeout(() => clearSlotTrack(uid), 2000);
|
||||||
doReconnect();
|
|
||||||
}, 2000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onUserPublished = async (user: any, mediaType: "video" | "audio") => {
|
|
||||||
if (isUnmounted) return;
|
|
||||||
console.log("user-published", user.uid, mediaType);
|
|
||||||
if (mediaType !== "video") return;
|
|
||||||
if (subscribedUidRef.current === user.uid) {
|
|
||||||
console.log("该用户已订阅,跳过");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 取消待执行的清空定时器
|
|
||||||
if (unpublishTimer) clearTimeout(unpublishTimer);
|
|
||||||
|
|
||||||
await client.subscribe(user, mediaType);
|
|
||||||
remoteVideoTrackRef.current = user.videoTrack;
|
|
||||||
subscribedUidRef.current = user.uid;
|
|
||||||
await playRemoteTrack(user.videoTrack);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onUserUnpublished = (user: any, mediaType: "video" | "audio") => {
|
|
||||||
if (isUnmounted) return;
|
|
||||||
console.log("user-unpublished", user.uid, mediaType, subscribedUidRef.current);
|
|
||||||
if (mediaType === "video" && subscribedUidRef.current === user.uid) {
|
|
||||||
if (unpublishTimer) clearTimeout(unpublishTimer);
|
|
||||||
// 延迟2s清空,短闪断自动恢复不黑屏
|
|
||||||
unpublishTimer = setTimeout(() => {
|
|
||||||
clearRemoteVideo();
|
|
||||||
}, 2000);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onUserLeft = (user: any) => {
|
const onUserLeft = (user: any) => {
|
||||||
if (isUnmounted) return;
|
if (unmounted) return;
|
||||||
console.log("user-left", user.uid);
|
const uid = Number(user.uid);
|
||||||
if (subscribedUidRef.current === user.uid) {
|
if (!slotUids.includes(uid)) return;
|
||||||
if (unpublishTimer) clearTimeout(unpublishTimer);
|
const slot = slotsRef.current.get(uid);
|
||||||
clearRemoteVideo();
|
if (!slot || slot.subscribedUid !== user.uid) return;
|
||||||
|
clearSlotTrack(uid);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onConnStateChange = (cur: string, prev: string) => {
|
||||||
|
if (unmounted) return;
|
||||||
|
onConnect(cur === 'CONNECTED');
|
||||||
|
if (cur === 'CONNECTED') onJoin(true);
|
||||||
|
else if (cur === 'DISCONNECTED') {
|
||||||
|
onJoin(false);
|
||||||
|
// 断线时清空所有槽位,重连成功后 onUserPublished 会重新走一遍
|
||||||
|
for (const uid of slotUids) clearSlotTrack(uid);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onUserJoined = (user: any) => {
|
client.on('connection-state-change', onConnStateChange);
|
||||||
if (!isUnmounted) console.log("远端用户进入频道:", user.uid);
|
client.on('user-published', onUserPublished);
|
||||||
};
|
client.on('user-unpublished', onUserUnpublished);
|
||||||
|
client.on('user-left', onUserLeft);
|
||||||
|
|
||||||
const onTokenWillExpire = () => {
|
const doJoin = async () => {
|
||||||
console.warn("token即将过期,请更新token");
|
|
||||||
message.warning("Token即将过期,视频可能很快断开");
|
|
||||||
};
|
|
||||||
|
|
||||||
client.on("connection-state-change", onConnStateChange);
|
|
||||||
client.on("user-published", onUserPublished);
|
|
||||||
client.on("user-unpublished", onUserUnpublished);
|
|
||||||
client.on("user-left", onUserLeft);
|
|
||||||
client.on("user-joined", onUserJoined);
|
|
||||||
client.on("token-privilege-will-expire", onTokenWillExpire);
|
|
||||||
|
|
||||||
const init = async () => {
|
|
||||||
if (joiningRef.current) return;
|
|
||||||
joiningRef.current = true;
|
|
||||||
try {
|
try {
|
||||||
await client.join(APP_ID, CHANNEL, TOKEN, uid);
|
console.log('[AGRTC] joining channel=' + channel + ', localUid=' + localUid + ', appId=' + APP_ID);
|
||||||
if (isUnmounted) {
|
console.log('[AGRTC] joined ' + channel + ', remoteUsers=', (client.remoteUsers || []).map(u => u.uid));
|
||||||
console.log("组件已卸载,丢弃join结果");
|
await client.join(APP_ID, channel, TOKEN, localUid);
|
||||||
return;
|
if (unmounted) return;
|
||||||
}
|
onJoin(true);
|
||||||
console.log("加入频道成功");
|
// 加入后立刻把已在频道内的远端摄像头扫一遍,避免错过 onUserPublished
|
||||||
setJoined(true);
|
for (const remote of client.remoteUsers) {
|
||||||
message.success("RTC已加入频道");
|
if (unmounted) break;
|
||||||
for (const remoteUser of client.remoteUsers) {
|
if (!remote.hasVideo) continue;
|
||||||
if (isUnmounted) break;
|
const uid = Number(remote.uid);
|
||||||
console.log("发现已有远端用户:", remoteUser.uid);
|
if (!slotUids.includes(uid)) continue;
|
||||||
if (remoteUser.hasVideo && subscribedUidRef.current !== remoteUser.uid) {
|
const slot = slotsRef.current.get(uid);
|
||||||
await client.subscribe(remoteUser, "video");
|
if (!slot || slot.subscribedUid === remote.uid) continue;
|
||||||
remoteVideoTrackRef.current = remoteUser.videoTrack;
|
try {
|
||||||
subscribedUidRef.current = remoteUser.uid;
|
await client.subscribe(remote, 'video');
|
||||||
await playRemoteTrack(remoteUser.videoTrack!);
|
slot.subscribedUid = remote.uid;
|
||||||
}
|
if (remote.videoTrack) await playIntoSlot(uid, remote.videoTrack);
|
||||||
|
} catch { /* ignore */ }
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err?.code === "OPERATION_ABORTED") {
|
if (err?.code !== 'OPERATION_ABORTED') {
|
||||||
console.log("join操作被取消,忽略");
|
console.error('[AGRTC] join failed', channel, err);
|
||||||
return;
|
message.error(`加入 ${channel} 失败`);
|
||||||
}
|
}
|
||||||
console.error("加入频道失败:", err);
|
|
||||||
if (!isUnmounted) {
|
|
||||||
message.error("加入频道失败,请检查appid/token/channel");
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
joiningRef.current = false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
doJoin();
|
||||||
|
|
||||||
init();
|
// Watchdog:每 3s 检查每个 video 元素,readyState 未到 HAVE_CURRENT_DATA 时重新 .play()
|
||||||
|
const watchdog = setInterval(() => {
|
||||||
|
if (unmounted) return;
|
||||||
|
for (const [uid, slot] of slotsRef.current.entries()) {
|
||||||
|
if (!slot.track || !slot.containerRef.current) continue;
|
||||||
|
const videoEl = slot.containerRef.current.querySelector('video') as HTMLVideoElement | null;
|
||||||
|
if (!videoEl) continue;
|
||||||
|
if (videoEl.readyState < 2) {
|
||||||
|
try {
|
||||||
|
slot.track.play(slot.containerRef.current);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('[AGRTC] watchdog replay error', channel, uid, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 3000);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
isUnmounted = true;
|
unmounted = true;
|
||||||
if (reconnectTimerRef.current) clearTimeout(reconnectTimerRef.current);
|
clearInterval(watchdog);
|
||||||
if (unpublishTimer) clearTimeout(unpublishTimer);
|
for (const slot of slotsRef.current.values()) {
|
||||||
if (videoWatchDogTimer) clearInterval(videoWatchDogTimer);
|
if (slot.unpublishTimer) clearTimeout(slot.unpublishTimer);
|
||||||
clearRemoteVideo();
|
if (slot.track) {
|
||||||
const c = clientRef.current;
|
try { slot.track.stop(); } catch { }
|
||||||
if (!c) return;
|
}
|
||||||
c.off("connection-state-change", onConnStateChange);
|
}
|
||||||
c.off("user-published", onUserPublished);
|
try {
|
||||||
c.off("user-unpublished", onUserUnpublished);
|
client.off('connection-state-change');
|
||||||
c.off("user-left", onUserLeft);
|
client.off('user-published');
|
||||||
c.off("user-joined", onUserJoined);
|
client.off('user-unpublished');
|
||||||
c.off("token-privilege-will-expire", onTokenWillExpire);
|
client.off('user-left');
|
||||||
c.leave();
|
client.leave();
|
||||||
clientRef.current = null;
|
} catch { }
|
||||||
|
slotsRef.current.clear();
|
||||||
|
onConnect(false);
|
||||||
|
onJoin(false);
|
||||||
};
|
};
|
||||||
}, [CHANNEL]);
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [channel, slotUids.join(',')]);
|
||||||
|
|
||||||
return (
|
return <>{children({ slotsByUid: slotsRef.current })}</>;
|
||||||
<div style={{ width: "100%", height: "95%", display: "flex", flexDirection: "column", borderRadius: 8, overflow: "hidden", background: "#000" }}>
|
|
||||||
<div style={{ display: "flex", justifyContent: "end", alignItems: "center", gap: 12, padding: "4px 8px", background: "rgba(255,255,255,0.08)", flexShrink: 0 }}>
|
|
||||||
<Badge
|
|
||||||
color={connected ? "green" : "red"}
|
|
||||||
text={connected ? "RTC已连接" : "RTC未连接"}
|
|
||||||
styles={{ content: { color: '#888' } }}
|
|
||||||
/>
|
|
||||||
<Badge
|
|
||||||
color={joined ? "green" : "orange"}
|
|
||||||
text={joined ? "已加入频道" : "未加入频道"}
|
|
||||||
styles={{ content: { color: '#888' } }}
|
|
||||||
/>
|
|
||||||
<span style={{ fontSize: 11, color: "#888" }}>频道:{CHANNEL}</span>
|
|
||||||
</div>
|
|
||||||
<div style={{ flex: 1, width: "100%", minHeight: 0, position: "relative" }}>
|
|
||||||
{!hasRemoteVideo && (
|
|
||||||
<div style={{
|
|
||||||
position: "absolute",
|
|
||||||
inset: 0,
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
color: "#aaa",
|
|
||||||
fontSize: 14,
|
|
||||||
background: "#000",
|
|
||||||
zIndex: 2
|
|
||||||
}}>
|
|
||||||
视频加载中,等待远端推流...
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div ref={remoteVideoRef} style={{
|
|
||||||
position: "absolute",
|
|
||||||
inset: 0,
|
|
||||||
width: "100%",
|
|
||||||
height: "100%",
|
|
||||||
zIndex: 1
|
|
||||||
}} />
|
|
||||||
</div>
|
|
||||||
</div >
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
message,
|
message,
|
||||||
Modal,
|
Modal,
|
||||||
Switch,
|
Switch,
|
||||||
|
DatePicker
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import {
|
import {
|
||||||
DashboardOutlined,
|
DashboardOutlined,
|
||||||
@@ -65,7 +66,8 @@ import VideoPlayer from '../VideoPlayer.tsx';
|
|||||||
import SteerButton from './SteerButton';
|
import SteerButton from './SteerButton';
|
||||||
import AgrtcRoomRobot from '../AgrtcRoomRobot';
|
import AgrtcRoomRobot from '../AgrtcRoomRobot';
|
||||||
import DeviceController from './DeviceController';
|
import DeviceController from './DeviceController';
|
||||||
import { DatePicker } from 'antd';
|
|
||||||
|
import { deviceRunParamSelectByDeviceId } from '@/api/stationManage/index';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { MowerAllView } from './MowerAllView';
|
import { MowerAllView } from './MowerAllView';
|
||||||
import { useMqtt } from '@/hooks/useMqtt';
|
import { useMqtt } from '@/hooks/useMqtt';
|
||||||
@@ -87,15 +89,7 @@ const ConsoleBadge = ({ online, text, color }: any) => (
|
|||||||
{text}
|
{text}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
const ConsoleRow = ({ icon, label, value }: any) => (
|
|
||||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 }}>
|
|
||||||
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 12, color: '#8c8c8c', whiteSpace: 'nowrap' }}>
|
|
||||||
{icon}
|
|
||||||
{label}
|
|
||||||
</span>
|
|
||||||
<span style={{ fontSize: 12, color: '#262626', textAlign: 'right', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{value}</span>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
// 暗色控制台面板(参考图样式:细边框、小圆角、蓝色竖条标题、右侧状态 badge)
|
// 暗色控制台面板(参考图样式:细边框、小圆角、蓝色竖条标题、右侧状态 badge)
|
||||||
const ConsolePanel = ({ title, extra, badge, children, style, bodyStyle }: any) => (
|
const ConsolePanel = ({ title, extra, badge, children, style, bodyStyle }: any) => (
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', background: '#fff', borderRadius: 10, overflow: 'hidden', ...style }}>
|
<div style={{ display: 'flex', flexDirection: 'column', background: '#fff', borderRadius: 10, overflow: 'hidden', ...style }}>
|
||||||
@@ -109,76 +103,7 @@ const ConsolePanel = ({ title, extra, badge, children, style, bodyStyle }: any)
|
|||||||
<div style={{ flex: 1, minHeight: 0, padding: 10, ...bodyStyle }}>{children}</div>
|
<div style={{ flex: 1, minHeight: 0, padding: 10, ...bodyStyle }}>{children}</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
// 方向盘功能按钮(暗色小方块,样式参考参考图)
|
|
||||||
// SteerButton:支持长按持续发送(与 DPadControl 方向键行为一致)
|
|
||||||
//const SteerButton = ({ icon, label, color, onPressStart, onPressEnd }: any) => {
|
|
||||||
// const [pressed, setPressed] = useState(false);
|
|
||||||
// const holdingRef = useRef(false);
|
|
||||||
// const intervalRef = useRef<number | null>(null);
|
|
||||||
// const emitEndedRef = useRef(false);
|
|
||||||
// const stopHold = useCallback(() => {
|
|
||||||
// if (intervalRef.current !== null) { window.clearInterval(intervalRef.current); intervalRef.current = null; }
|
|
||||||
// if (!holdingRef.current) return;
|
|
||||||
// holdingRef.current = false;
|
|
||||||
// emitEndedRef.current = false;
|
|
||||||
// setPressed(false);
|
|
||||||
// onPressEnd?.();
|
|
||||||
// }, [onPressEnd]);
|
|
||||||
// const startHold = useCallback(() => {
|
|
||||||
// if (holdingRef.current) return;
|
|
||||||
// holdingRef.current = true;
|
|
||||||
// emitEndedRef.current = false;
|
|
||||||
// setPressed(true);
|
|
||||||
// if (intervalRef.current !== null) window.clearInterval(intervalRef.current);
|
|
||||||
// // 立即首帧 + 每 100ms 持续(DPadControl 也是 100ms)
|
|
||||||
// onPressStart?.();
|
|
||||||
// intervalRef.current = window.setInterval(() => {
|
|
||||||
// if (!holdingRef.current) return;
|
|
||||||
// onPressStart?.();
|
|
||||||
// }, 100);
|
|
||||||
// }, [onPressStart]);
|
|
||||||
// useEffect(() => () => {
|
|
||||||
// if (intervalRef.current !== null) window.clearInterval(intervalRef.current);
|
|
||||||
// if (holdingRef.current) stopHold();
|
|
||||||
// }, [stopHold]);
|
|
||||||
// return (
|
|
||||||
// <button
|
|
||||||
// type="button"
|
|
||||||
// aria-label={label}
|
|
||||||
// onMouseDown={(e) => { e.preventDefault(); e.stopPropagation(); startHold(); }}
|
|
||||||
// onMouseUp={(e) => { e.preventDefault(); e.stopPropagation(); stopHold(); }}
|
|
||||||
// onMouseLeave={() => { if (holdingRef.current) stopHold(); }}
|
|
||||||
// onTouchStart={(e) => { e.preventDefault(); startHold(); }}
|
|
||||||
// onTouchEnd={(e) => { e.preventDefault(); stopHold(); }}
|
|
||||||
// onTouchCancel={() => { if (holdingRef.current) stopHold(); }}
|
|
||||||
// onContextMenu={(e) => e.preventDefault()}
|
|
||||||
// onClick={(e) => e.preventDefault()}
|
|
||||||
// style={{
|
|
||||||
// flex: '1 1 0',
|
|
||||||
// display: 'flex',
|
|
||||||
// flexDirection: 'column',
|
|
||||||
// alignItems: 'center',
|
|
||||||
// justifyContent: 'center',
|
|
||||||
// gap: 4,
|
|
||||||
// minHeight: 46,
|
|
||||||
// padding: '6px 4px',
|
|
||||||
// borderRadius: 8,
|
|
||||||
// background: pressed ? color + '30' : '#1e293b',
|
|
||||||
// border: '1px solid ' + (pressed ? color : color + '55'),
|
|
||||||
// color: color,
|
|
||||||
// cursor: 'pointer',
|
|
||||||
// userSelect: 'none',
|
|
||||||
// touchAction: 'none',
|
|
||||||
// transform: pressed ? 'scale(0.94)' : 'scale(1)',
|
|
||||||
// boxShadow: pressed ? '0 0 14px ' + color + '66' : 'none',
|
|
||||||
// transition: 'transform .08s, background .12s, border-color .12s, box-shadow .12s',
|
|
||||||
// }}
|
|
||||||
// >
|
|
||||||
// <span style={{ display: 'inline-flex', fontSize: 16, lineHeight: 1 }}>{icon}</span>
|
|
||||||
// <span style={{ fontSize: 11, fontWeight: 600, whiteSpace: 'nowrap' }}>{label}</span>
|
|
||||||
// </button>
|
|
||||||
// );
|
|
||||||
//};
|
|
||||||
export default function DeviceStatusPage() {
|
export default function DeviceStatusPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||||
@@ -199,9 +124,20 @@ export default function DeviceStatusPage() {
|
|||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
// 视频播放开关
|
// 视频播放开关
|
||||||
const [isVideoPlaying, setIsVideoPlaying] = useState(false);
|
const [isVideoPlaying, setIsVideoPlaying] = useState(false);
|
||||||
|
|
||||||
|
// 当前机器人摄像头路数(接口返回 cameraNum,1-4)
|
||||||
|
const [cameraNum, setCameraNum] = useState<number>(1);
|
||||||
|
// 行车辅助线开关(仅前视/后视单路叠加)
|
||||||
|
const [showGuideLine, setShowGuideLine] = useState<boolean>(true);
|
||||||
|
// 设备 Agora 视频频道号(后端 paramData 或 device 字段;最终兜底 SN)
|
||||||
const toggleVideoPlay = useCallback(() => {
|
const toggleVideoPlay = useCallback(() => {
|
||||||
setIsVideoPlaying(prev => !prev);
|
setIsVideoPlaying(prev => !prev);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// 选中机器人变化 → 拉设备参数,取 cameraNum 决定视频网格布局(1/2/4 路)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const [isControlled, setIsControlled] = useState(false);
|
const [isControlled, setIsControlled] = useState(false);
|
||||||
const [hasControlRight, setHasControlRight] = useState(false);
|
const [hasControlRight, setHasControlRight] = useState(false);
|
||||||
const [connecting, setConnecting] = useState(false);
|
const [connecting, setConnecting] = useState(false);
|
||||||
@@ -272,6 +208,15 @@ export default function DeviceStatusPage() {
|
|||||||
const handleFinishEdPoint = (point) => {
|
const handleFinishEdPoint = (point) => {
|
||||||
setArrivedPoint(point);
|
setArrivedPoint(point);
|
||||||
}
|
}
|
||||||
|
const ConsoleRow = ({ icon, label, value }: any) => (
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 }}>
|
||||||
|
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 12, color: '#8c8c8c', whiteSpace: 'nowrap' }}>
|
||||||
|
{icon}
|
||||||
|
{label}
|
||||||
|
</span>
|
||||||
|
<span style={{ fontSize: 12, color: '#262626', textAlign: 'right', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{value}</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchAllData();
|
fetchAllData();
|
||||||
}, [userInfo, stationId]);
|
}, [userInfo, stationId]);
|
||||||
@@ -437,6 +382,50 @@ export default function DeviceStatusPage() {
|
|||||||
onMessage: handleMqttMessage,
|
onMessage: handleMqttMessage,
|
||||||
enabled: mqttTopics.length > 0,
|
enabled: mqttTopics.length > 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const id = device?.device_sn || device?.serialNumber || selectedSn;
|
||||||
|
if (!id || !stationId) {
|
||||||
|
setCameraNum(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let cancelled = false;
|
||||||
|
deviceRunParamSelectByDeviceId({ deviceId: id }).then((res) => {
|
||||||
|
if (cancelled) return;
|
||||||
|
if (res?.code === 200) {
|
||||||
|
const n = Number(res.data?.cameraNum);
|
||||||
|
// channel 字段:videoChannel / cameraChannel / agoraChannel / rtcChannel / channel
|
||||||
|
|
||||||
|
setCameraNum(Number.isFinite(n) && n >= 1 && n <= 4 ? n : 1);
|
||||||
|
console.log('[DSP] deviceRunParam res.data=', res.data);
|
||||||
|
} else {
|
||||||
|
setCameraNum(1);
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
if (!cancelled) setCameraNum(1);
|
||||||
|
});
|
||||||
|
return () => { cancelled = true; };
|
||||||
|
}, [device?.device_sn, device?.serialNumber, selectedSn, stationId]);
|
||||||
|
|
||||||
|
// 视角按钮:按摄像头路数动态裁剪
|
||||||
|
const viewButtons = useMemo(() => {
|
||||||
|
const all = [
|
||||||
|
{ key: 'all', label: t('devices.panorama') },
|
||||||
|
{ key: 'front', label: t('devices.frontView'), minCams: 1 },
|
||||||
|
{ key: 'back', label: t('devices.backView'), minCams: 1 },
|
||||||
|
{ key: 'left', label: t('devices.leftView'), minCams: 3 },
|
||||||
|
{ key: 'right', label: t('devices.rightView'), minCams: 3 },
|
||||||
|
];
|
||||||
|
const n = Number(cameraNum) || 1;
|
||||||
|
return all.filter((b) => !b.minCams || n >= b.minCams);
|
||||||
|
}, [cameraNum, t]);
|
||||||
|
|
||||||
|
// cameraNum 变化时自动把非法视角回退到 front
|
||||||
|
useEffect(() => {
|
||||||
|
const n = Number(cameraNum) || 1;
|
||||||
|
if (n <= 2 && (mowerView === 'left' || mowerView === 'right')) setMowerView('front');
|
||||||
|
}, [cameraNum, mowerView]);
|
||||||
|
|
||||||
// 合并无人机和机场数据
|
// 合并无人机和机场数据
|
||||||
const currentDroneData = React.useMemo(() => {
|
const currentDroneData = React.useMemo(() => {
|
||||||
return { ...persistentHostData, ...persistentDroneData };
|
return { ...persistentHostData, ...persistentDroneData };
|
||||||
@@ -1406,51 +1395,57 @@ export default function DeviceStatusPage() {
|
|||||||
bodyStyle={{ padding: 8, display: 'flex', flexDirection: 'column', gap: 8 }}
|
bodyStyle={{ padding: 8, display: 'flex', flexDirection: 'column', gap: 8 }}
|
||||||
>
|
>
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexShrink: 0, overflowX: 'auto' }}>
|
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexShrink: 0, overflowX: 'auto' }}>
|
||||||
{[{ key: 'front', label: t('devices.frontView') }, { key: 'left', label: t('devices.leftView') }, { key: 'right', label: t('devices.rightView') }, { key: 'back', label: t('devices.backView') }, { key: 'all', label: t('devices.panorama') }].map((v) => (
|
{viewButtons.map((v) => (
|
||||||
<Button key={v.key} type={mowerView === v.key ? 'primary' : 'default'} size="small" onClick={() => setMowerView(v.key)}>
|
<Button key={v.key} type={mowerView === v.key ? 'primary' : 'default'} size="small" onClick={() => setMowerView(v.key)}>
|
||||||
{v.label}
|
{v.label}
|
||||||
</Button>
|
</Button>
|
||||||
))}
|
))}
|
||||||
|
<span style={{ marginLeft: 'auto', display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 12, color: '#555' }}>
|
||||||
|
{t('devices.showGuideLine')}
|
||||||
|
<Switch size="small" checked={showGuideLine} onChange={setShowGuideLine} />
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ position: 'relative', flex: 1, minHeight: 0, borderRadius: 8, overflow: 'hidden', }}>
|
<div style={{ position: 'relative', flex: 1, minHeight: 0, borderRadius: 8, overflow: 'hidden', }}>
|
||||||
{isVideoPlaying && (
|
{isVideoPlaying && (
|
||||||
mowerView === 'all' ? (
|
mowerView === 'all' ? (
|
||||||
|
// 全景/网格视图:单频道多 UID,按 cameraNum 决定 1/2/4 路布局
|
||||||
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
|
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
|
||||||
<MowerAllView serialNumber={device?.serialNumber} robotVideo={robotVideo} error={error} ready={ready} />
|
<AgrtcRoomRobot channel={device?.serialNumber || device?.device_sn || ""} cameraCount={cameraNum} />
|
||||||
</div>
|
</div>
|
||||||
) : mowerView === 'front' ? (
|
) : mowerView === 'front' ? (
|
||||||
|
// 前视:单路 UID 101
|
||||||
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
|
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
|
||||||
<AgrtcRoomRobot CHANNEL={"cam2-17"} />
|
<AgrtcRoomRobot channel={device?.serialNumber || device?.device_sn || ""} slotUids={[101]} />
|
||||||
<CarReverseGuideLine
|
<CarReverseGuideLine
|
||||||
direction="forward"
|
direction="forward"
|
||||||
steer={steerXY.x * 45}
|
steer={steerXY.x * 45}
|
||||||
linearSpeed={Number(runningStatus?.linear_speed ?? runningStatus?.linearSpeed)}
|
linearSpeed={Number(runningStatus?.linear_speed ?? runningStatus?.linearSpeed)}
|
||||||
angularSpeed={Number(runningStatus?.angular_speed ?? runningStatus?.angularSpeed)}
|
angularSpeed={Number(runningStatus?.angular_speed ?? runningStatus?.angularSpeed)}
|
||||||
visible={isVideoPlaying}
|
visible={isVideoPlaying && showGuideLine}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
) : mowerView === 'back' ? (
|
||||||
|
// 后视:单路 UID 103 + 倒车辅助线
|
||||||
|
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
|
||||||
|
<AgrtcRoomRobot channel={device?.serialNumber || device?.device_sn || ""} slotUids={[103]} />
|
||||||
|
<CarReverseGuideLine
|
||||||
|
direction="reverse"
|
||||||
|
steer={steerXY.x * 45}
|
||||||
|
linearSpeed={Number(runningStatus?.linear_speed ?? runningStatus?.linearSpeed)}
|
||||||
|
angularSpeed={Number(runningStatus?.angular_speed ?? runningStatus?.angularSpeed)}
|
||||||
|
visible={isVideoPlaying && showGuideLine}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : mowerView === 'left' ? (
|
||||||
|
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
|
||||||
|
<AgrtcRoomRobot channel={device?.serialNumber || device?.device_sn || ""} slotUids={[102]} />
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
// 右视:单路 UID 104
|
||||||
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
|
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
|
||||||
<VideoPlayer
|
<AgrtcRoomRobot channel={device?.serialNumber || device?.device_sn || ""} slotUids={[104]} />
|
||||||
deviceId={device?.serialNumber}
|
|
||||||
idx={mowerView === 'back' ? 2 : mowerView === 'left' ? 3 : 4}
|
|
||||||
className="w-full h-full object-contain"
|
|
||||||
video={robotVideo}
|
|
||||||
error={error}
|
|
||||||
ready={ready}
|
|
||||||
/>
|
|
||||||
{mowerView === 'back' && (
|
|
||||||
<CarReverseGuideLine
|
|
||||||
direction="reverse"
|
|
||||||
steer={steerXY.x * 45}
|
|
||||||
linearSpeed={Number(runningStatus?.linear_speed ?? runningStatus?.linearSpeed)}
|
|
||||||
angularSpeed={Number(runningStatus?.angular_speed ?? runningStatus?.angularSpeed)}
|
|
||||||
visible={isVideoPlaying}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
))}
|
||||||
)}
|
|
||||||
{!isVideoPlaying && (
|
{!isVideoPlaying && (
|
||||||
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', flexDirection: 'column', gap: 12, color: 'rgba(14, 78, 198, 0.55)' }}>
|
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', flexDirection: 'column', gap: 12, color: 'rgba(14, 78, 198, 0.55)' }}>
|
||||||
<VideoCameraOutlined style={{ fontSize: 56, opacity: 0.6 }} />
|
<VideoCameraOutlined style={{ fontSize: 56, opacity: 0.6 }} />
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ import { MapEditorView } from './MapEditorView';
|
|||||||
import type { ViewStats } from './WayLineView';
|
import type { ViewStats } from './WayLineView';
|
||||||
import { backToRestPointCommand } from '@/api/mapEdit';
|
import { backToRestPointCommand } from '@/api/mapEdit';
|
||||||
import { sendEmergencyStop, subscribeEmergencyStop, syncEmergencyStop } from './emergencyStopControl';
|
import { sendEmergencyStop, subscribeEmergencyStop, syncEmergencyStop } from './emergencyStopControl';
|
||||||
|
import AgrtcRoomRobot from '../AgrtcRoomRobot.js';
|
||||||
|
import { deviceRunParamSelectByDeviceId } from '@/api/stationManage/index.js';
|
||||||
|
|
||||||
|
|
||||||
const { Text, Title } = Typography;
|
const { Text, Title } = Typography;
|
||||||
@@ -109,6 +111,7 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
|
|||||||
|
|
||||||
// 当前激活的Tab
|
// 当前激活的Tab
|
||||||
const [activeTab, setActiveTab] = useState('pool'); // 'task' for 任务列表, 'pool' for 任务池, 'history' for 历史任务
|
const [activeTab, setActiveTab] = useState('pool'); // 'task' for 任务列表, 'pool' for 任务池, 'history' for 历史任务
|
||||||
|
const [cameraNum, setCameraNum] = useState(0);
|
||||||
|
|
||||||
// 任务池和历史任务筛选表单
|
// 任务池和历史任务筛选表单
|
||||||
const [poolFilterForm, setPoolFilterForm] = useState({
|
const [poolFilterForm, setPoolFilterForm] = useState({
|
||||||
@@ -1384,6 +1387,26 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
|
|||||||
setDeviceStatistics(res.data || {});
|
setDeviceStatistics(res.data || {});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const id = selectedMachineSn;
|
||||||
|
if (!id || !stationId) {
|
||||||
|
setCameraNum(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let cancelled = false;
|
||||||
|
deviceRunParamSelectByDeviceId({ deviceId: id }).then((res) => {
|
||||||
|
if (cancelled) return;
|
||||||
|
if (res?.code === 200) {
|
||||||
|
const n = Number(res.data?.cameraNum);
|
||||||
|
setCameraNum(Number.isFinite(n) && n >= 1 && n <= 4 ? n : 1);
|
||||||
|
console.log('[DSP] deviceRunParam res.data=', res.data);
|
||||||
|
} else {
|
||||||
|
setCameraNum(1);
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
if (!cancelled) setCameraNum(1);
|
||||||
|
});
|
||||||
|
return () => { cancelled = true; };
|
||||||
}, [selectedMachineSn]);
|
}, [selectedMachineSn]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -3105,22 +3128,18 @@ export function TaskPlanningView({ selectedMachineSn, embedded = false, onStatsC
|
|||||||
</Row>*/}
|
</Row>*/}
|
||||||
|
|
||||||
|
|
||||||
{/*{showVideo && executingRobot && execute && taskPoolList.length > 0 && (
|
{showVideo && (
|
||||||
<DraggableBox
|
<DraggableBox
|
||||||
defaultPosition={{ x: 50, y: 50 }}
|
defaultPosition={{ x: 50, y: 50 }}
|
||||||
title={t('devices.robotPanoramaVideo', { robot: executingRobot.deviceAlias || executingRobot.serialNumber })}
|
title={t('devices.robotPanoramaVideo', { robot: targetRobot.deviceAlias || targetRobot.serialNumber })}
|
||||||
onClose={() => setShowVideo(false)}
|
onClose={() => setShowVideo(false)}
|
||||||
>
|
>
|
||||||
<div style={{ height: '100%', width: '100%' }}>
|
<div style={{ height: '100%', width: '100%' }}>
|
||||||
<MowerAllView
|
<AgrtcRoomRobot channel={targetRobot?.serialNumber || targetRobot?.device_sn || ""} cameraCount={cameraNum} />
|
||||||
serialNumber={executingRobot.serialNumber}
|
|
||||||
robotVideo={robotVideo}
|
|
||||||
ready={ready}
|
|
||||||
error={error}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</DraggableBox>
|
</DraggableBox>
|
||||||
)}*/}
|
)}
|
||||||
</div >
|
</div >
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,4 +198,8 @@ h4, .ant-typography h4 { font-size: clamp(1rem, 1.5vw, 1.25rem) !important; }
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.badge-rtc-connected .ant-badge-status-text{
|
||||||
|
color:#fff !important
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -492,6 +492,7 @@
|
|||||||
autoFetch: 'Auto Fetch',
|
autoFetch: 'Auto Fetch',
|
||||||
autoResumeFromBreakpoint: 'Auto Resume From Breakpoint',
|
autoResumeFromBreakpoint: 'Auto Resume From Breakpoint',
|
||||||
backView: 'Back View',
|
backView: 'Back View',
|
||||||
|
showGuideLine: "Show Guide Line",
|
||||||
batteryCapacity: 'Battery Capacity',
|
batteryCapacity: 'Battery Capacity',
|
||||||
batteryWithPercent: 'Battery with Percent',
|
batteryWithPercent: 'Battery with Percent',
|
||||||
batteryWithValue: 'Battery with Value',
|
batteryWithValue: 'Battery with Value',
|
||||||
|
|||||||
@@ -513,6 +513,7 @@ const zh = {
|
|||||||
autoFetch: '自动获取',
|
autoFetch: '自动获取',
|
||||||
autoResumeFromBreakpoint: '自动恢复从断点',
|
autoResumeFromBreakpoint: '自动恢复从断点',
|
||||||
backView: '后视角',
|
backView: '后视角',
|
||||||
|
showGuideLine: "显示辅助线",
|
||||||
batteryCapacity: '电量容量',
|
batteryCapacity: '电量容量',
|
||||||
batteryWithPercent: '电量带百分比',
|
batteryWithPercent: '电量带百分比',
|
||||||
batteryWithValue: '电量带值',
|
batteryWithValue: '电量带值',
|
||||||
|
|||||||
Reference in New Issue
Block a user