增加推拉流播放和停止

This commit is contained in:
mmc
2026-08-06 13:39:14 +08:00
parent 0d10593cd9
commit 60e910f12a
2 changed files with 97 additions and 17 deletions

View File

@@ -85,7 +85,7 @@ export default function DeviceOverviewPage() {
const [currentParamDevice, setCurrentParamDevice] = useState<any>(null);
const navigate = useNavigate();
console.log('stationId', stationId, currentStation);
const [robotPlayActive, setRobotPlayActive] = useState<boolean>(false);
// 获取数据
@@ -415,9 +415,12 @@ export default function DeviceOverviewPage() {
});
// 机器人视频
// 机器人视频:只有 robotPlayActive = true 才真正拉流
const { video: robotVideo, error, ready } = useWebRTCPlayer(
!isUAV ? selectedDevice?.serialNumber || '' : '',
`webrtc://1.95.137.212/live/livestream/${selectedDevice?.serialNumber}`,
(!isUAV && robotPlayActive) ? (selectedDevice?.serialNumber || '') : '',
(!isUAV && robotPlayActive)
? `webrtc://1.95.137.212/live/livestream/${selectedDevice?.serialNumber}`
: ''
);
const getDevivePermisstion = (data) => {
@@ -545,6 +548,7 @@ export default function DeviceOverviewPage() {
const handleDeviceChange = (id) => {
setCurrentSelectedRobot(id);
setRobotPlayActive(false);
};
// 获取无人机状态
@@ -867,22 +871,67 @@ export default function DeviceOverviewPage() {
onSourceChange={setVideoSource}
/>
) : (
robotVideo ? (
<VideoPlayer
deviceId={selectedDevice?.device_sn || selectedDevice?.serialNumber}
idx={mowerView === 'front' ? 1 : mowerView === 'back' ? 2 : mowerView === 'left' ? 3 : 4}
className="w-full h-full object-contain"
video={robotVideo}
error={error}
ready={ready}
/>
robotPlayActive ? (
robotVideo ? (
<VideoPlayer
deviceId={selectedDevice?.device_sn || selectedDevice?.serialNumber}
idx={mowerView === 'front' ? 1 : mowerView === 'back' ? 2 : mowerView === 'left' ? 3 : 4}
className="w-full h-full object-contain"
video={robotVideo}
error={error}
ready={ready}
/>
) : (
<div style={{ color: '#ccc', display: 'flex', height: '100%', alignItems: 'center', justifyContent: 'center' }}>
视频加载中...
</div>
)
) : (
<div style={{ color: '#ccc', display: 'flex', height: '100%', alignItems: 'center', justifyContent: 'center' }}>
视频加载中...
// ========== 未点击播放时:显示播放大按钮 ==========
<div
onClick={() => setRobotPlayActive(true)}
style={{
width: '100%',
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
cursor: 'pointer',
background: '#000',
}}
>
<div
style={{
width: 48,
height: 48,
borderRadius: '50%',
background: 'rgba(255,255,255,0.25)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: '#fff',
fontSize: 22,
}}
>
▶
</div>
</div>
)
)}
</div>
{!isUAV && robotPlayActive && (
<div style={{ marginTop: 6, textAlign: 'right' }}>
<Button
size="small"
danger
onClick={() => {
setRobotPlayActive(false);
}}
>停止视频</Button>
</div>
)}
</div>
<div style={{ display: 'flex', gap: 12, flexWrap: 'wrap' }}>