高清地图+无人机实时信息显示异常问题修复

This commit is contained in:
2026-08-19 14:57:24 +08:00
parent ab75e8c5b0
commit 83220869da
7 changed files with 397 additions and 146 deletions

View File

@@ -46,19 +46,19 @@ class DroneOsdDataSourceImpl implements DroneOsdDataSource {
}) async {
if (_isDisposed) return;
// 同一设备(SN 相同):只增加引用计数,共享订阅
// 🔥 同一设备(SN 相同):只增加引用计数,不重新订阅
if (_listenerCount > 0 &&
_deviceSn == deviceSn &&
_gatewaySn == gatewaySn &&
_subscription != null) {
_gatewaySn == gatewaySn) {
_listenerCount++;
debugPrint('[DroneOsdDataSource] 引用计数+1: $_listenerCount');
debugPrint('[DroneOsdDataSource] 引用计数+1: $_listenerCount (设备相同,不重新订阅)');
return;
}
// 切换到不同设备:强制清理旧订阅
// 不管引用计数多少,SN 变了就必须先取消旧订阅再订阅新的
if (_deviceSn != null || _gatewaySn != null) {
// 🔥 切换到不同设备或首次订阅时才清理旧订阅
// 重要:只有在设备不同的情况下才调用 stopListening,避免误取消当前订阅
final needCleanup = _deviceSn != null || _gatewaySn != null;
if (needCleanup) {
// 重置引用计数为 1,让 stopListening 能真正取消 MQTT 订阅
_listenerCount = 1;
await stopListening();