测试优化实时监控中心,接收全部的机器信息 ,优化显示图标的问题,优化且任务的时候显示 规划路径

This commit is contained in:
mmc
2026-09-21 13:24:06 +08:00
parent 1fd99e62d6
commit 0e95bb0c96
7 changed files with 222 additions and 125 deletions

View File

@@ -5,7 +5,7 @@ import { Badge, message } from "antd";
AgoraRTC.setLogLevel(2); // 2=只输出warning/error,屏蔽debug日志
const APP_ID = "7887b4db6033410d9ac3264b40ca9c1a";
const TOKEN = "007eJxTYDhxaLPL8617mtfHFi2tfJhQNSXh5vNJnqvu8b/3PenKKdumwGBuYWGeZJKSZGZgbGxiaJBimZhsbGRmkmRikJxomWyYuHHFiqyGQEaGB6+fMDEyQCCIz81gYqhbklGUmphrYMTAAAAyfSTX";
const TOKEN = "007eJxTYPh6QSj59sUzD3mPNm64dK9n/n1PP64UzrhzdwUeqMUKv1BVYDC3sDBPMklJMjMwNjYxNEixTEw2NjIzSTIxSE60TDZMlOdYldUQyMiQXKbEwAiFID43g4mhbklGUWpiroExAwMAjGAhHQ==";
export default function AgrtcRoomRobot({ CHANNEL }: { CHANNEL: string }) {
const [uid] = useState(() => Number(Math.floor(Math.random() * 100000)));
@@ -22,7 +22,7 @@ export default function AgrtcRoomRobot({ CHANNEL }: { CHANNEL: string }) {
useEffect(() => {
const client = AgoraRTC.createClient({
mode: "rtc",
mode: "live",
codec: "h264",
});
clientRef.current = client;
@@ -145,7 +145,7 @@ export default function AgrtcRoomRobot({ CHANNEL }: { CHANNEL: string }) {
const onUserUnpublished = (user: any, mediaType: "video" | "audio") => {
if (isUnmounted) return;
console.log("user-unpublished", user.uid, mediaType);
console.log("user-unpublished", user.uid, mediaType, subscribedUidRef.current);
if (mediaType === "video" && subscribedUidRef.current === user.uid) {
if (unpublishTimer) clearTimeout(unpublishTimer);
// 延迟2s清空,短闪断自动恢复不黑屏

View File

@@ -795,7 +795,6 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
};
function showCoordinateTooltip(tooltip, position, t, lon, lat, robot) {
console.log('showCoordinateTooltip', position, lon, lat, robot);
tooltip.style.display = "block";
tooltip.style.left = position.x + 12 + "px";
tooltip.style.top = position.y + 12 + "px";
@@ -1309,7 +1308,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
if (focusLocation.type === "plane" || focusLocation.type === "drone") {
image = planeImg;
} else if (focusLocation.type === "robot") {
image = droneInspectImg;
image = carImg;
} else if (focusLocation.type === "mower") {
image = carImg;
}
@@ -1739,7 +1738,6 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
// ==============================
// 光圈颜色:工作中蓝 / 空闲绿 / 离线红
const haloColor = getDeviceHaloColor(device);
let entity = entityMapRef.current.get(id);
@@ -1781,6 +1779,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine,
// 设备底部状态光晕:比机器稍大一点
// ==============================
const haloId = `${id}_halo`;
const haloColor = getDeviceHaloColor(device);
// 尺寸可根据设备类型微调:车辆类稍大,IOT/相机类稍小

View File

@@ -1236,7 +1236,7 @@ export default function DeviceStatusPage() {
) : mowerView === 'front' ? (
<div style={{ position: 'relative', width: '100%', height: '100%' }}>
{/*<AgrtcRoomRobot CHANNEL={device?.serialNumber || ''} />*/}
<AgrtcRoomRobot CHANNEL={"41-thream02"} />
<AgrtcRoomRobot CHANNEL={"41-thream03"} />
</div>
) : (

View File

@@ -241,6 +241,7 @@ export default function RobotTaskPage() {
const handlePoolTaskClick = (record) => {
setRunningPoolTask(record);
loadTaskPath(record.id);
fetchRouteDetail(record.id);
// 查找对应的设备
const targetDevice = devices?.find(d => d.serialNumber === record.deviceId);

View File

@@ -1,4 +1,5 @@
import throttle from 'lodash/throttle';
import dayjs from 'dayjs';
import { wsManager } from '../WebSocketManager.ts';
import {
getJurisdiction,
@@ -9,9 +10,10 @@ import envConfig from '../../../env';
import i18n from '../../i18n';
export default class DeviceController {
constructor(userInfo, messageApi) {
constructor(userInfo, messageApi, siteId) {
this.userInfo = userInfo;
this.messageApi = messageApi;
this.siteId = siteId;
this.wsUrl =
envConfig.WS_URL || 'wss://ri.satabot.com/ws/';
@@ -44,6 +46,12 @@ export default class DeviceController {
this.onIsFinished = null;
this.handleArrivedPoint = null;
// 全量设备实时状态(mapPush)连接
this.mapPushWs = null;
this.mapPushManualClose = false;
this.mapPushReconnectTimer = null;
this.onMapPush = null;
this.handleWsMessage = this.handleWsMessage.bind(this);
this.handleWsStatus = this.handleWsStatus.bind(this);
this.handleVisibilityChange = this.handleVisibilityChange.bind(this);
@@ -78,6 +86,98 @@ export default class DeviceController {
this.onControlStatusChange?.(false);
}
// ============ 全量设备实时状态(mapPush)连接 ============
// 进入实时监控页时连接一次,接收后端广播的所有设备状态;退出页面时调用 closeMapPush 断开。
initMapPush(onMapPush) {
console.log('DeviceController initMapPush: 连接全量设备 WebSocket');
this.onMapPush = onMapPush || null;
this.mapPushManualClose = false;
this.connectMapPush();
}
connectMapPush() {
if (this.mapPushWs && this.mapPushWs.readyState === WebSocket.OPEN) return;
try {
this.mapPushManualClose = false;
const ws = new WebSocket(this.wsUrl);
this.mapPushWs = ws;
ws.onopen = () => {
ws.send(JSON.stringify({
type: 'mapPush',
token: this.userInfo?.token,
siteId: this.siteId,
userName: this.userInfo?.username,
deviceId: '',
}));
};
ws.onmessage = (event) => {
let msg = null;
try { msg = JSON.parse(event.data); } catch (e) { return; }
console.log('[DeviceController] 收到全量设备状态 初始状态', msg);
if (msg?.type !== 'mapPush') return;
const list = Array.isArray(msg?.data) && msg.data.length
? msg.data
: [];
if (!list.length) return;
const next = {};
list.forEach((it) => {
const key = String(it?.id ?? '');
if (!key) return;
next[key] = {
id: key,
lng: String(it?.lng ?? it?.lon ?? it?.longitude),
lat: String(it?.lat ?? it?.latitude),
yaw: it?.y,
fix: it?.f !== undefined ? String(it.f) : undefined,
fixStatus: it?.f !== undefined ? String(it.f) : undefined,
altitude: it?.a !== undefined ? String(it.a) : undefined,
status: it?.s ?? it?.status,
taskId: it?.t ?? it?.taskId ?? null,
battery: it?.b !== undefined ? Number(it.b) : (it?.batteryLevel !== undefined ? Number(it.batteryLevel) : undefined),
hasAlarm: !!it?.ha || !!it?.hasAlarm,
updateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
};
});
console.log('[DeviceController] 收到全量设备状态', next);
this.onMapPush?.(next);
};
ws.onerror = () => {
console.error('[DeviceController] mapPush WebSocket 错误');
};
ws.onclose = () => {
if (this.mapPushWs === ws) this.mapPushWs = null;
if (!this.mapPushManualClose) {
this.mapPushReconnectTimer = setTimeout(() => this.connectMapPush(), 5000);
}
};
} catch (err) {
console.error('[DeviceController] 连接全量设备 WebSocket 失败', err);
this.mapPushReconnectTimer = setTimeout(() => this.connectMapPush(), 5000);
}
}
closeMapPush() {
this.mapPushManualClose = true;
if (this.mapPushReconnectTimer) {
clearTimeout(this.mapPushReconnectTimer);
this.mapPushReconnectTimer = null;
}
if (this.mapPushWs) {
this.mapPushWs.onopen = null;
this.mapPushWs.onmessage = null;
this.mapPushWs.onerror = null;
this.mapPushWs.onclose = null;
try { this.mapPushWs.close(); } catch (e) { /* ignore */ }
this.mapPushWs = null;
}
}
handleVisibilityChange() {
if (document.visibilityState === 'hidden') {
console.log('Page hidden, release control');