根据hashost字段 显示 视频

This commit is contained in:
mmc
2026-09-08 15:59:41 +08:00
parent 6e4083c88c
commit 39e5e80926
3 changed files with 59 additions and 37 deletions

View File

@@ -1,6 +1,6 @@
import React, { useEffect, useRef, useState } from "react";
import AgoraRTC, { IAgoraRTCClient, IRemoteVideoTrack } from "agora-rtc-sdk-ng";
import { Card, Badge, message, Space } from "antd";
import { Badge, message } from "antd";
const APP_ID = "875f6494d87548e783fefbf33f598c97";
const TOKEN = "007eJxTYIjPuZr09PC0znd6+z0MMyL6ZHb68OetXW+kO1vHU2ZNtYECg4W5aZqZiaVJCpBhYpFqbmGclpqWlGZsnGZqaZFsaT6pZH5WQyAjA7e+LysjAwSC+JwMxmYlqcUlugZGDAwAbuYeJg==";
@@ -195,23 +195,25 @@ export default function AgrtcRoomRobot({ CHANNEL }) {
c.leave();
clientRef.current = null;
};
}, [uid]);
}, [uid, CHANNEL]);
return (
<Card title="Agora RTC 上位机视频观看" style={{ width: 1000, margin: "20px auto" }}>
<Space direction="vertical" style={{ width: "100%" }}>
<div>当前 UID:{uid}</div>
<Badge color={connected ? "green" : "red"} text={connected ? "RTC 已连接" : "RTC 未连接"} />
<Badge color={joined ? "green" : "orange"} text={joined ? "已加入频道" : "未加入频道"} />
<div style={{ width: "100%", height: "100%", 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' } }}
/>
<div style={{ marginTop: 20 }}>
<h3>远端视频(上位机画面)</h3>
<div
ref={remoteVideoRef}
style={{ width: 800, height: 600, background: "#000", borderRadius: 8, overflow: "hidden" }}
/>
</div>
</Space>
</Card>
<span style={{ fontSize: 11, color: "#888" }}>频道:{CHANNEL}</span>
</div>
<div ref={remoteVideoRef} style={{ flex: 1, width: "100%", minHeight: 0 }} />
</div >
);
}

View File

@@ -17,15 +17,13 @@ import {
} from '@ant-design/icons';
import { useNavigate } from 'react-router-dom';
// 组件内
import DroneLivePlayer from '../VolcRtcPlayer.jsx';
import DroneVideoPlayer from './DroneVideoPlayer';
import AgoraTextTest from '../AgoraRtc.tsx';
import { useWebRTCPlayer } from '../useWebRTCStream.tsx';
import VideoPlayer from '../VideoPlayer.tsx';
import AgrtcRoomRobot from '../AgrtcRoomRobot';
import CesiumMap from '../Map.jsx';
import DeviceParamModal from './DeviceParamModal';
import { getUAVState, getSiteDevice, getSiteUAVList, getsinglePlan, getRobotTaskList, getDeviceTotalData, updateDeviceAliasApi, hasPermission } from '@/api/device.ts';
@@ -423,7 +421,7 @@ export default function DeviceOverviewPage() {
// 机器人视频
// 机器人视频:只有 robotPlayActive = true 才真正拉流
const { video: robotVideo, error, ready } = useWebRTCPlayer(
(!isUAV && robotPlayActive) ? (selectedDevice?.serialNumber || '') : '',
(!isUAV && robotPlayActive && !selectedDevice?.hasHost) ? (selectedDevice?.serialNumber || '') : '',
(!isUAV && robotPlayActive)
? `webrtc://1.95.137.212/live/livestream/${selectedDevice?.serialNumber}`
: ''
@@ -878,7 +876,11 @@ export default function DeviceOverviewPage() {
/>
) : (
robotPlayActive ? (
robotVideo ? (
selectedDevice?.hasHost ? (
<div style={{ width: '100%', height: '100%', position: 'relative', overflow: 'hidden', background: '#000', borderRadius: 8 }}>
<AgrtcRoomRobot CHANNEL={selectedDevice?.serialNumber || ''} />
</div>
) : robotVideo ? (
<VideoPlayer
deviceId={selectedDevice?.device_sn || selectedDevice?.serialNumber}
idx={mowerView === 'front' ? 1 : mowerView === 'back' ? 2 : mowerView === 'left' ? 3 : 4}

View File

@@ -53,6 +53,7 @@ import { useSelector } from 'react-redux';
import { RootState } from '@/src/store/index.ts';
import { useWebRTCPlayer } from '../useWebRTCStream.tsx';
import VideoPlayer from '../VideoPlayer.tsx';
import AgrtcRoomRobot from '../AgrtcRoomRobot';
import DeviceController from './DeviceController';
import { DatePicker } from 'antd';
import dayjs from 'dayjs';
@@ -66,6 +67,7 @@ const { RangePicker } = DatePicker;
const { Text } = Typography;
export default function DeviceStatusPage() {
const { t } = useTranslation();
const { userInfo } = useSelector((state: RootState) => state.user);
@@ -406,13 +408,14 @@ export default function DeviceStatusPage() {
? base
: {
...base,
...device?.locationMessage,
...wsDeviceInfo,
...locationInfo
};
}, [device, wsDeviceInfo, isUAV, locationInfo]);
const { video: robotVideo, error, ready } = useWebRTCPlayer(
(!isUAV && isVideoPlaying) ? (device?.serialNumber || '') : '',
(!isUAV && isVideoPlaying && !device?.hasHost) ? (device?.serialNumber || '') : '',
(!isUAV && isVideoPlaying)
? `webrtc://1.95.137.212/live/livestream/${device?.serialNumber}`
: ''
@@ -1219,25 +1222,41 @@ export default function DeviceStatusPage() {
{/* 视频层:停止时不渲染 / 未播放时为空,不影响状态面板 */}
{robotVideo && isVideoPlaying && (
{isVideoPlaying && (
mowerView === 'all' ? (
<div style={{ width: '100%', height: '100%' }}>
<MowerAllView
serialNumber={device?.serialNumber}
robotVideo={robotVideo}
error={error}
ready={ready}
/>
robotVideo ? (
<div style={{ width: '100%', height: '100%' }}>
<MowerAllView
serialNumber={device?.serialNumber}
robotVideo={robotVideo}
error={error}
ready={ready}
/>
</div>
) : null
) : mowerView === 'front' ? (
<div style={{ position: 'relative', width: '100%', height: '100%' }}>
{device?.hasHost ? (
<AgrtcRoomRobot CHANNEL={device?.serialNumber || ''} />
) : robotVideo ? (
<VideoPlayer
deviceId={device?.serialNumber}
idx={1}
className="w-full h-full object-contain"
video={robotVideo}
error={error}
ready={ready}
/>
) : null}
</div>
) : (
<div style={{ position: 'relative', width: '100%', height: '100%' }}>
<VideoPlayer
deviceId={device?.serialNumber}
idx={
mowerView === 'front' ? 1
: mowerView === 'back' ? 2
: mowerView === 'left' ? 3
: 4
mowerView === 'back' ? 2
: mowerView === 'left' ? 3
: 4
}
className="w-full h-full object-contain"
video={robotVideo}
@@ -1249,7 +1268,7 @@ export default function DeviceStatusPage() {
)}
{/* 视频未加载 / 停止播放的占位 */}
{(!robotVideo || !isVideoPlaying) && (
{(!robotVideo && !isVideoPlaying) && (
<div style={{
width: '100%', height: '100%',
display: 'flex', alignItems: 'center', justifyContent: 'center',
@@ -1265,7 +1284,6 @@ export default function DeviceStatusPage() {
</div>
</div>
)}
{/* 单视频(非全景)模式状态叠加层:始终渲染,和视频层解耦 */}
{mowerView !== 'all' && (
<div style={{