소스 검색

feature: 解决解决连接之后会有一段时间显示离线,先添加进去就不会了的问题

Damon 7 달 전
부모
커밋
e599c912c2
1개의 변경된 파일19개의 추가작업 그리고 3개의 파일을 삭제
  1. 19 3
      utils/blue_ble/util.js

+ 19 - 3
utils/blue_ble/util.js

@@ -73,7 +73,7 @@ class BleUtil {
     const strings = require('./../../utils/strings');
     var services = await that.manager.getNotifyServices(device);
     if (strings.isEmpty(services)) {
-      onChanged(false, device);
+      onChanged(false);
       return;
     }
 
@@ -81,9 +81,25 @@ class BleUtil {
       async function (notifyServiceId, notifyCharaterId) {
           var isTrue = that.manager.monitorCharacteristicValueChange(device, notifyServiceId, notifyCharaterId);
           if (!isTrue) {
-            onChanged(false, device);
+            onChanged(false);
             return;
           }
+
+          ///解决连接之后会有一段时间显示离线,先添加进去就不会了
+          var has = false;
+          var compareList = that.bleManager.getCompareList();
+          for (var j = 0; j < compareList.length; j++) {
+            if (compareList[j].deviceId == device.deviceId) {
+              has = true;
+              break;
+            }
+          }
+          if (!has) {
+            compareList.unshift(device);
+            that.bleManager.setCompareList(compareList);
+          }
+          onChanged(true);
+
           const hex_util = require('./../../utils/hex_util');
           const bt_parse = require('./../../devices/bluetooth/bt_parse');
           that.manager.onBLECharacteristicValueChange(function (value) {
@@ -99,7 +115,7 @@ class BleUtil {
           });
         },
         function () {
-          onChanged(false, device);
+          onChanged(false);
           return;
         });
   }