增加推拉流播放和停止
This commit is contained in:
@@ -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' }}>
|
||||
|
||||
@@ -60,6 +60,7 @@ import { MowerAllView } from './MowerAllView';
|
||||
import { useMqtt } from '@/hooks/useMqtt';
|
||||
import envConfig from '../../../env';
|
||||
import { dataUrlToFile } from '@/lib/utils.ts';
|
||||
import { PauseOutlined, PlayCircleOutlined } from '@ant-design/icons';
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
const { Text } = Typography;
|
||||
@@ -78,6 +79,15 @@ export default function DeviceStatusPage() {
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
|
||||
|
||||
// 视频播放开关
|
||||
const [isVideoPlaying, setIsVideoPlaying] = useState(false);
|
||||
|
||||
const toggleVideoPlay = useCallback(() => {
|
||||
setIsVideoPlaying(prev => !prev);
|
||||
}, []);
|
||||
|
||||
|
||||
|
||||
const [isControlled, setIsControlled] = useState(false);
|
||||
const [hasControlRight, setHasControlRight] = useState(false);
|
||||
const [connecting, setConnecting] = useState(false);
|
||||
@@ -192,12 +202,16 @@ export default function DeviceStatusPage() {
|
||||
);
|
||||
if (target) {
|
||||
setSelectedSn(urlSn);
|
||||
setIsVideoPlaying(false);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
// url无sn / 没匹配到对应设备:默认选中第一个
|
||||
const firstDevice = devicesAll[0];
|
||||
setSelectedSn(firstDevice.device_sn || firstDevice.serialNumber);
|
||||
setIsVideoPlaying(false);
|
||||
|
||||
}
|
||||
}, [devicesAll, urlSn]);
|
||||
|
||||
@@ -391,9 +405,16 @@ export default function DeviceStatusPage() {
|
||||
}, [device, wsDeviceInfo, isUAV]);
|
||||
|
||||
const { video: robotVideo, error, ready } = useWebRTCPlayer(
|
||||
!isUAV ? device?.serialNumber : '',
|
||||
`webrtc://1.95.137.212/live/livestream/${device?.serialNumber}`,
|
||||
(!isUAV && isVideoPlaying) ? (device?.serialNumber || '') : '',
|
||||
(!isUAV && isVideoPlaying)
|
||||
? `webrtc://1.95.137.212/live/livestream/${device?.serialNumber}`
|
||||
: ''
|
||||
);
|
||||
|
||||
//const { video: robotVideo, error, ready } = useWebRTCPlayer(
|
||||
// !isUAV ? device?.serialNumber : '',
|
||||
// `webrtc://1.95.137.212/live/livestream/${device?.serialNumber}`,
|
||||
//);
|
||||
const getVal = (val) => val === "no_rain" ? "无" : (val || '-');
|
||||
|
||||
const realtimePosition = React.useMemo(() => {
|
||||
@@ -1051,6 +1072,16 @@ export default function DeviceStatusPage() {
|
||||
bordered={false}
|
||||
style={{ borderRadius: 12, marginBottom: 8 }}
|
||||
bodyStyle={{ padding: 12, height: 'calc(100vh - 220px)', minHeight: 500 }}
|
||||
|
||||
extra={
|
||||
<Button
|
||||
size="small"
|
||||
icon={isVideoPlaying ? <PauseOutlined /> : <PlayCircleOutlined />}
|
||||
onClick={toggleVideoPlay}
|
||||
>
|
||||
{isVideoPlaying ? '停止' : '播放'}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Space style={{ marginBottom: 8, }} align="start" >
|
||||
<Button type={mowerView === 'front' ? 'primary' : 'default'} onClick={() => setMowerView('front')}>前视</Button>
|
||||
@@ -1208,7 +1239,7 @@ export default function DeviceStatusPage() {
|
||||
</div>
|
||||
)
|
||||
) : (
|
||||
<div style={{ color: '#ccc', margin: 'auto' }}>视频加载中...</div>
|
||||
<div style={{ color: '#ccc', margin: 'auto', fontSize: 40 }}>视频加载中...</div>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user