Browse Source

fix:修改黑胶音箱的重连问题

zeng.chen 2 months ago
parent
commit
8a1b683cb2
3 changed files with 30 additions and 11 deletions
  1. 16 8
      pages/pageA/index/index.js
  2. 13 2
      utils/lexin/scan.js
  3. 1 1
      utils/routeRoot.js

+ 16 - 8
pages/pageA/index/index.js

@@ -160,18 +160,22 @@ Page({
       BtHelper.getInstance().startScan(null, null, function (res) {});
       var isFirst = true;
       console.log("开始监听蓝牙设备");
-      that.startBleTimer(isFirst);
+      that.startBleTimer(isFirst, true);
       that.addNotification()
     }
   },
 
-  startBleTimer(isFirst) {
+  startBleTimer(isFirst, openTimer) {
     let that = this;
     let deviceList = that.getDeviceList()
+    let findBle = deviceList.find(item => {
+      return (item.connectType === 1 && item.state === "online")
+    })
     let findWifi = deviceList.find(item => {
-      return item.connectType != 1
+      return (item.connectType === 3 && item.state === "online")
     })
-    if (findWifi) {
+    if (!openTimer && (findBle || findWifi)) {
+      // 强制开启监听 && (有蓝牙在线 || 有wifi在线)就return
       return;
     }
     ///再秒再对比一次
@@ -185,7 +189,7 @@ Page({
       if (isFirst) {
         that.stopIntervalId1();
         var newIsFirst = false
-        that.startBleTimer(newIsFirst);
+        that.startBleTimer(newIsFirst, true);
       }
       // } else {
       //   count++;
@@ -199,6 +203,7 @@ Page({
     let that = this;
     constant.lexinScan.compareList2(that.data.deviceList, function (device) {
       if (device) {
+        console.log("找到蓝牙了");
         that.data._willConnectBle = device;
         getApp().getBluetoothStatus();
       }
@@ -788,7 +793,7 @@ Page({
     constant.eventBus.removeNotification(CmdEvent.eventName, that);
     constant.eventBus.addNotification(CmdEvent.eventName, function (event) {
       let deviceList = that.getDeviceList()
-
+      // console.log("收到监听:", JSON.stringify(event))
       if (event.cmdEvent == EnumCmdEvent.btMac) {
         let disDevice = deviceList.find(item => {
           return item.state == "online" && item.connectType === 1
@@ -809,7 +814,8 @@ Page({
             return item.state == "online" && item.connectType === 3
           })
           if (!wifiDevice) {
-            that.startBleTimer(isFirst);
+            console.log("开启蓝牙监听:", event.deviceId, event.commonValue)
+            that.startBleTimer(isFirst, true);
           }
         }
 
@@ -827,7 +833,8 @@ Page({
         //   }
         // });
         if (!disDevice) {
-          console.log("没有找到在线的对应的蓝牙设备")
+          // console.log("")
+          console.log("没有找到在线的对应的蓝牙设备", JSON.stringify(deviceList))
           return;
         }
 
@@ -918,6 +925,7 @@ Page({
         var param = "?param=" + item.forwardUrl;
         console.log("gadfeqreqrqr==111==" + param);
         constant.routeUtil.jumpParam(constant.routePath.webview, param);
+        //
       }
       // 外链
       else if (item.forwardType == 1) {

+ 13 - 2
utils/lexin/scan.js

@@ -10,10 +10,11 @@ module.exports = {
 var deviceListIndex = 0
 async function compareList2(deviceList, callback) {
   let isHasWifi = deviceList.find(item => {
-    return item.connectType == 3;
+    return item.connectType == 3 && item.state === "online";
   });
   if (isHasWifi) {
     //有wifi
+    console.log("有wifi在线")
     callback()
     return;
   }
@@ -22,10 +23,14 @@ async function compareList2(deviceList, callback) {
     // 只有一个直接连接
     let device = deviceList[0];
     if (device.state === 'online') {
+      console.log("有在线的2", JSON.stringify(device))
+
       return;
     }
-    getApp().getBluetoothStatus();
+    // getApp().getBluetoothStatus();
     callback(deviceList[0])
+    console.log("有在线的3", JSON.stringify(deviceList[0]))
+
     return;
   }
 
@@ -35,12 +40,18 @@ async function compareList2(deviceList, callback) {
 
   if (hasOnline) {
     //有在线的
+    console.log("有蓝牙在线", JSON.stringify(hasOnline))
     callback(hasOnline)
     return;
   }
 
+  console.log("有在线的3", JSON.stringify(deviceList[deviceListIndex]), deviceListIndex)
+
   callback(deviceList[deviceListIndex])
   deviceListIndex++
+  if (deviceListIndex >= deviceList.length) {
+    deviceListIndex = 0;
+  }
 
   // _startScan(deviceListIndex, deviceList, callback);
 }

+ 1 - 1
utils/routeRoot.js

@@ -1,7 +1,7 @@
 ///路由
 
 /// A
-const index = "pages/index/index";
+const index = "pages/pageA/index/index";
 const login = "pages/pageA/login/login";
 
 /// B