feat: 下任务推流地址修改
This commit is contained in:
+2
-3
@@ -141,7 +141,6 @@ public class DeviceCommandController {
|
||||
if (request.getTargetLatitude() == null || request.getTargetLongitude() == null) {
|
||||
return Result.failed("目标点经纬度不能为空");
|
||||
}
|
||||
|
||||
// 构建参数
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("target_latitude", request.getTargetLatitude());
|
||||
@@ -157,7 +156,7 @@ public class DeviceCommandController {
|
||||
params.put("flight_id", request.getFlightId() != null ? request.getFlightId() : java.util.UUID.randomUUID().toString().replace("-", "").toUpperCase());
|
||||
params.put("max_speed", request.getMaxSpeed() != null ? request.getMaxSpeed() : 5);
|
||||
params.put("flight_safety_advance_check", request.getFlightSafetyAdvanceCheck() != null ? request.getFlightSafetyAdvanceCheck() : 0);
|
||||
|
||||
params.put("stream_urls", getStreamUrls(request.getDeviceSn()));
|
||||
String commandId = commandManager.sendCommand(
|
||||
request.getDeviceSn(),
|
||||
"takeoff_to_point",
|
||||
@@ -550,7 +549,7 @@ public class DeviceCommandController {
|
||||
JSONObject result = new JSONObject();
|
||||
AgeDevice device = iAgeDeviceService.getByDeviceSn(deviceId);
|
||||
if(Objects.nonNull(device)){
|
||||
result.put("pushUrl", device.getVideoStreamUrl());
|
||||
result.put("pushUrl", device.getPushStreamUrl());
|
||||
}
|
||||
result.put("playRtmpUrl", "");
|
||||
result.put("playFlvUrl", "");
|
||||
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package com.central.device.controller;
|
||||
|
||||
import com.central.device.sse.manager.SseEmitterManager;
|
||||
import com.central.device.websocket.manager.SubscriptionPoolService;
|
||||
import com.central.common.model.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* SSE 连接管理控制器
|
||||
* 提供管理员手动管理 SSE 连接和 WebSocket 订阅的接口
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-01-20
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/admin/sse")
|
||||
@Tag(name = "SSE管理接口", description = "管理员手动管理SSE连接和订阅")
|
||||
public class SseAdminController {
|
||||
|
||||
@Autowired
|
||||
private SseEmitterManager sseEmitterManager;
|
||||
|
||||
@Autowired
|
||||
private SubscriptionPoolService subscriptionPoolService;
|
||||
|
||||
/**
|
||||
* 查看当前连接状态
|
||||
*/
|
||||
@GetMapping("/status")
|
||||
@Operation(summary = "查看SSE连接状态", description = "获取当前所有SSE连接和WebSocket订阅状态")
|
||||
public Result<Map<String, Object>> getStatus() {
|
||||
Map<String, Object> status = sseEmitterManager.getConnectionStatus();
|
||||
|
||||
// 打印 Redis 订阅状态
|
||||
subscriptionPoolService.printSubscriptionStatus();
|
||||
|
||||
return Result.succeed(status, "查询成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制断开所有连接
|
||||
*/
|
||||
@PostMapping("/disconnect-all")
|
||||
@Operation(summary = "断开所有SSE连接", description = "强制断开所有SSE连接,清理Redis订阅,关闭WebSocket")
|
||||
public Result<String> disconnectAll() {
|
||||
log.warn("【管理员操作】收到断开所有连接请求");
|
||||
|
||||
int disconnected = sseEmitterManager.disconnectAll();
|
||||
|
||||
String msg = String.format("已断开 %d 个SSE连接,已清理Redis订阅,已关闭WebSocket", disconnected);
|
||||
log.info(msg);
|
||||
|
||||
return Result.succeed(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅清理 Redis 订阅(不断开 SSE)
|
||||
*/
|
||||
@PostMapping("/clear-redis")
|
||||
@Operation(summary = "清理Redis订阅", description = "仅清理Redis中的订阅记录,不断开SSE连接")
|
||||
public Result<String> clearRedis() {
|
||||
log.warn("【管理员操作】收到清理Redis订阅请求");
|
||||
|
||||
int cleared = subscriptionPoolService.clearAllSubscriptions();
|
||||
|
||||
String msg = String.format("已清理 %d 个Redis订阅记录", cleared);
|
||||
log.info(msg);
|
||||
|
||||
return Result.succeed(msg);
|
||||
}
|
||||
}
|
||||
@@ -50,4 +50,9 @@ public class AgeDevice extends SuperEntity {
|
||||
* 视频流地址(完整WHEP URL,如:http://220.205.16.27:8024/rtc/v1/whep/?app=live&stream=49214ac552fa)
|
||||
*/
|
||||
private String videoStreamUrl;
|
||||
|
||||
/**
|
||||
* 设备推送视频流地址(完整whip URL,如:http://220.205.16.27:8024/rtc/v1/whip/?app=live&stream=48622d43e975&secret=1F8F64FE2A7447A7)
|
||||
*/
|
||||
private String pushStreamUrl;
|
||||
}
|
||||
|
||||
+71
@@ -529,6 +529,77 @@ public class SseEmitterManager {
|
||||
return deviceRefCount.getOrDefault(deviceSn, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 【管理功能】强制断开所有 SSE 连接并清理所有订阅
|
||||
* 用于管理员手动清理资源
|
||||
*
|
||||
* @return 断开的连接数
|
||||
*/
|
||||
public int disconnectAll() {
|
||||
int count = emitters.size();
|
||||
log.warn("【管理操作】强制断开所有 SSE 连接,当前连接数: {}", count);
|
||||
|
||||
// 复制一份 key 列表,避免并发修改
|
||||
java.util.List<String> sessionIds = new java.util.ArrayList<>(emitters.keySet());
|
||||
|
||||
for (String sessionId : sessionIds) {
|
||||
EmitterWrapper wrapper = emitters.get(sessionId);
|
||||
if (wrapper != null) {
|
||||
try {
|
||||
// 完成 SSE 连接(会触发 onCompletion 回调进行清理)
|
||||
wrapper.getEmitter().complete();
|
||||
} catch (Exception e) {
|
||||
log.debug("完成 SSE 连接失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 清理 Redis 订阅池
|
||||
int redisCleared = subscriptionPoolService.clearAllSubscriptions();
|
||||
log.info("Redis 订阅池已清理: {} 个 key", redisCleared);
|
||||
|
||||
// 清理本地引用计数
|
||||
deviceRefCount.clear();
|
||||
|
||||
// 断开 WebSocket 连接
|
||||
jetLinksWebSocketClient.closeManually();
|
||||
log.info("WebSocket 连接已关闭");
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 【管理功能】获取当前所有 SSE 连接状态
|
||||
*
|
||||
* @return 连接状态信息
|
||||
*/
|
||||
public java.util.Map<String, Object> getConnectionStatus() {
|
||||
java.util.Map<String, Object> status = new java.util.HashMap<>();
|
||||
status.put("totalConnections", emitters.size());
|
||||
status.put("deviceRefCounts", new java.util.HashMap<>(deviceRefCount));
|
||||
|
||||
// 按设备分组统计
|
||||
java.util.Map<String, Integer> deviceConnections = new java.util.HashMap<>();
|
||||
java.util.Map<String, Integer> droneConnections = new java.util.HashMap<>();
|
||||
|
||||
emitters.forEach((sessionId, wrapper) -> {
|
||||
String deviceSn = wrapper.getDeviceSn();
|
||||
boolean isDrone = wrapper.getIsDroneTelemetry() != null && wrapper.getIsDroneTelemetry();
|
||||
|
||||
if (isDrone) {
|
||||
droneConnections.merge(deviceSn, 1, Integer::sum);
|
||||
} else {
|
||||
deviceConnections.merge(deviceSn, 1, Integer::sum);
|
||||
}
|
||||
});
|
||||
|
||||
status.put("deviceConnections", deviceConnections);
|
||||
status.put("droneConnections", droneConnections);
|
||||
status.put("websocketConnected", jetLinksWebSocketClient.isConnected());
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅无人机遥测数据(msg_alarm)
|
||||
* 进入操控台时调用,开始接收无人机实时遥测数据
|
||||
|
||||
+4
@@ -208,6 +208,10 @@ public class DeviceCommandManager {
|
||||
data.put("flight_id", params.getString("flight_id"));
|
||||
data.put("max_speed", params.getIntValue("max_speed"));
|
||||
data.put("flight_safety_advance_check", params.getIntValue("flight_safety_advance_check"));
|
||||
// 推流地址
|
||||
if (params.containsKey("stream_urls")) {
|
||||
data.put("stream_urls", params.get("stream_urls"));
|
||||
}
|
||||
break;
|
||||
|
||||
case "return_home":
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE `manage_device` ADD COLUMN `push_stream_url` varchar(500) NULL COMMENT '设备推流地址' AFTER `video_stream_url`;
|
||||
Binary file not shown.
@@ -61,6 +61,13 @@ const DeviceForm: React.FC<DeviceFormProps> = ({ title, visible, onVisibleChange
|
||||
placeholder="如:http://220.205.16.27:8024/rtc/v1/whep/?app=live&stream=xxx"
|
||||
tooltip="WHEP视频流完整地址,用于无人机图传播放"
|
||||
/>
|
||||
<ProFormText
|
||||
name="pushStreamUrl"
|
||||
label="视频推流地址"
|
||||
width="lg"
|
||||
placeholder="如:http://220.205.16.27:8024/rtc/v1/whip/?app=live&stream=xxx"
|
||||
tooltip="用于无人机推流的地址"
|
||||
/>
|
||||
<ProFormTextArea name="deviceDesc" label="备注" width="lg" />
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
|
||||
+15
-6
@@ -1,7 +1,7 @@
|
||||
import { useState, useRef, useEffect, useCallback } from 'react';
|
||||
import { message } from 'antd';
|
||||
import { notification } from 'antd';
|
||||
|
||||
// 空闲超时时间:30分钟(毫秒)
|
||||
// 空闲超时时间:1分钟(测试用,正式环境改为30分钟)
|
||||
const IDLE_TIMEOUT_MS = 30 * 60 * 1000;
|
||||
|
||||
// GPS信息
|
||||
@@ -182,12 +182,21 @@ export function useDeviceSSE(): UseDeviceSSEResult {
|
||||
console.log('[DeviceSSE] 连接已断开');
|
||||
}, []);
|
||||
|
||||
// 因空闲断开连接
|
||||
// 因空闲断开连接并显示提醒
|
||||
const disconnectDueToIdle = useCallback(() => {
|
||||
console.log('[DeviceSSE] 页面空闲超过30分钟,断开SSE连接以节省资源');
|
||||
console.log('[DeviceSSE] 页面空闲超过1分钟,断开SSE连接');
|
||||
setIsIdleDisconnected(true);
|
||||
// 禁止自动重连
|
||||
shouldReconnectRef.current = false;
|
||||
// 断开连接
|
||||
disconnectSSE();
|
||||
message.warning('页面空闲超过30分钟,已断开实时数据连接,请刷新页面重新连接');
|
||||
// 显示提醒,使用统一的 key 避免重复
|
||||
notification.warning({
|
||||
message: '页面长时间未操作',
|
||||
description: '已断开实时数据连接,请刷新页面重新连接',
|
||||
duration: 0,
|
||||
key: 'page-idle-warning',
|
||||
});
|
||||
}, [disconnectSSE]);
|
||||
|
||||
// 重置空闲定时器
|
||||
@@ -454,4 +463,4 @@ export function useDeviceSSE(): UseDeviceSSEResult {
|
||||
};
|
||||
}
|
||||
|
||||
export default useDeviceSSE;
|
||||
export default useDeviceSSE;
|
||||
|
||||
+15
-6
@@ -1,7 +1,7 @@
|
||||
import { useState, useRef, useEffect, useCallback } from 'react';
|
||||
import { message } from 'antd';
|
||||
import { notification } from 'antd';
|
||||
|
||||
// 空闲超时时间:30分钟(毫秒)
|
||||
// 空闲超时时间:1分钟(测试用,正式环境改为30分钟)
|
||||
const IDLE_TIMEOUT_MS = 30 * 60 * 1000;
|
||||
|
||||
// 无人机遥测数据接口定义(从useDeviceSSE.ts复制)
|
||||
@@ -185,12 +185,21 @@ export const useDroneSSE = (): UseDroneSSEReturn => {
|
||||
reconnectAttemptsRef.current = 0;
|
||||
}, []);
|
||||
|
||||
// 因空闲断开连接
|
||||
// 因空闲断开连接并显示提醒
|
||||
const disconnectDueToIdle = useCallback(() => {
|
||||
console.log('[DroneSSE] 页面空闲超过30分钟,断开SSE连接以节省资源');
|
||||
console.log('[DroneSSE] 页面空闲超过1分钟,断开SSE连接');
|
||||
setIsIdleDisconnected(true);
|
||||
// 禁止自动重连
|
||||
shouldReconnectRef.current = false;
|
||||
// 断开连接
|
||||
disconnectDroneSSE();
|
||||
message.warning('页面空闲超过30分钟,已断开无人机数据连接,请刷新页面重新连接');
|
||||
// 显示提醒,使用统一的 key 避免重复
|
||||
notification.warning({
|
||||
message: '页面长时间未操作',
|
||||
description: '已断开实时数据连接,请刷新页面重新连接',
|
||||
duration: 0,
|
||||
key: 'page-idle-warning',
|
||||
});
|
||||
}, [disconnectDroneSSE]);
|
||||
|
||||
// 重置空闲定时器
|
||||
@@ -488,4 +497,4 @@ export const useDroneSSE = (): UseDroneSSEReturn => {
|
||||
disconnectDroneSSE,
|
||||
resetDroneData,
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user