|
@@ -244,6 +244,15 @@ Page({
|
|
|
},
|
|
|
startBleTimer(isFirst) {
|
|
|
let that = this;
|
|
|
+
|
|
|
+
|
|
|
+ let deviceList = that.getDeviceList()
|
|
|
+ let findWifi = deviceList.find(item => {
|
|
|
+ return item.connectType != 1
|
|
|
+ })
|
|
|
+ if (findWifi) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
///再秒再对比一次
|
|
|
that.stopIntervalId1();
|
|
|
let count = 0;
|
|
@@ -254,7 +263,8 @@ Page({
|
|
|
// if (count > 4) {
|
|
|
if (isFirst) {
|
|
|
that.stopIntervalId1();
|
|
|
- that.startBleTimer(false);
|
|
|
+ var newIsFirst = false
|
|
|
+ that.startBleTimer(newIsFirst);
|
|
|
}
|
|
|
// } else {
|
|
|
// count++;
|
|
@@ -291,15 +301,16 @@ Page({
|
|
|
if (v) {
|
|
|
var device = that.data._willConnectBle;
|
|
|
console.log("开始连接设备0", device);
|
|
|
- if (device.state === 'online' || device.connectType != 1) {
|
|
|
- return;
|
|
|
- }
|
|
|
- // });
|
|
|
+ // if (device.state === 'online' || device.connectType != 1) {
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
BtHelper.getInstance().connect(device, function (isConnected, d) {
|
|
|
+ console.log("自动连接成功", isConnected)
|
|
|
if (isConnected) {
|
|
|
device.state = 'online';
|
|
|
that.addBlueDevice(device);
|
|
|
- // that.stopIntervalId1();
|
|
|
+ that.stopIntervalId1();
|
|
|
} else {
|
|
|
device.state = 'offline';
|
|
|
}
|
|
@@ -583,6 +594,8 @@ Page({
|
|
|
if (index === deviceListSelect) {
|
|
|
that.goWake();
|
|
|
} else {
|
|
|
+ // 现断线第一个
|
|
|
+ // that.disconnectFirst()
|
|
|
that.addWifiDevice(device);
|
|
|
}
|
|
|
return;
|
|
@@ -602,9 +615,11 @@ Page({
|
|
|
deviceListSelect: null,
|
|
|
});
|
|
|
var currentDevice = deviceList[deviceListSelect];
|
|
|
- await BtHelper.getInstance().disconnect(currentDevice);
|
|
|
- // await time_util.delayMills(500);
|
|
|
+ console.log("断开连接0", currentDevice)
|
|
|
+ // 现断线第一个
|
|
|
+ // that.disconnectFirst()
|
|
|
}
|
|
|
+ console.log("断开连接2", device)
|
|
|
|
|
|
device.name = device.devName;
|
|
|
BtHelper.getInstance().connect(device, function (isConnected, d) {
|
|
@@ -621,7 +636,11 @@ Page({
|
|
|
deviceListSelect: null,
|
|
|
});
|
|
|
var currentDevice = deviceList[deviceListSelect];
|
|
|
- await BtHelper.getInstance().disconnect(currentDevice);
|
|
|
+ if (currentDevice.connectType === 1) {
|
|
|
+ console.log("断开连接1", currentDevice)
|
|
|
+ await BtHelper.getInstance().disconnect(currentDevice);
|
|
|
+
|
|
|
+ }
|
|
|
// await time_util.delayMills(500);
|
|
|
}
|
|
|
|
|
@@ -635,6 +654,22 @@ Page({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ disconnectFirst() {
|
|
|
+ let that = this;
|
|
|
+ let deviceList = that.getDeviceList()
|
|
|
+ let first = deviceList[0] ?? {}
|
|
|
+ if (first.state == "online") {
|
|
|
+ if (first.connectType === 1) {
|
|
|
+ BtHelper.getInstance().disconnect(first)
|
|
|
+ first.state == "offline"
|
|
|
+ } else {
|
|
|
+ // 取消订阅
|
|
|
+ // var pubResponse = lexin_util.getResponseByDeviceId(first.deviceId);
|
|
|
+ // app.unsubscribe(pubResponse);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
// 去唤醒界面
|
|
|
goWake() {
|
|
|
var that = this;
|
|
@@ -661,7 +696,7 @@ Page({
|
|
|
if (deviceList[index].connectType == 3) {
|
|
|
that.cancelWifi(index, false);
|
|
|
} else {
|
|
|
- console.log("确定删除", index)
|
|
|
+ console.log("确定删除0", index, deviceList[index].deviceId)
|
|
|
that.cancelBlue(index, false);
|
|
|
}
|
|
|
}
|
|
@@ -712,18 +747,18 @@ Page({
|
|
|
|
|
|
///是否删除的当前播放这个
|
|
|
var isCurrentIndex = false;
|
|
|
- deviceListSelect = deviceListSelect ?? 0;
|
|
|
if (deviceListSelect != null && deviceList.length > deviceListSelect) {
|
|
|
isCurrentIndex = (deviceListSelect == index);
|
|
|
};
|
|
|
|
|
|
+ let device = deviceList[index];
|
|
|
///删除当前设备
|
|
|
- var deviceId = deviceList[index].deviceId;
|
|
|
+ var deviceId = device.deviceId;
|
|
|
deviceList = deviceList.filter((item, i) => {
|
|
|
return deviceId !== item.deviceId;
|
|
|
});
|
|
|
store.setStore("deviceList", deviceList);
|
|
|
-
|
|
|
+ console.log("确定删除1", isCurrentIndex, deviceListSelect)
|
|
|
var indexPage = that.data.indexPage;
|
|
|
that.setData({
|
|
|
deviceList: deviceList,
|
|
@@ -732,10 +767,12 @@ Page({
|
|
|
});
|
|
|
|
|
|
console.log("最终确定删除", deviceId, JSON.stringify(deviceList), deviceList.length)
|
|
|
+ if (device.state === "online") {
|
|
|
+ BtHelper.getInstance().disconnect({
|
|
|
+ "deviceId": deviceId
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- BtHelper.getInstance().disconnect({
|
|
|
- "deviceId": deviceId
|
|
|
- });
|
|
|
},
|
|
|
|
|
|
/// 断开连接wifi
|
|
@@ -782,11 +819,21 @@ Page({
|
|
|
addBlueDevice(device) {
|
|
|
var that = this;
|
|
|
var addDeviceList = lexin_add.addBlueDevice(device);
|
|
|
+ let hasOnline = 0
|
|
|
+ addDeviceList.forEach(item => {
|
|
|
+ // 蓝牙设备下线。wifi不动
|
|
|
+ if (item.deviceId != device.deviceId && item.connectType === 1) {
|
|
|
+ item.state = "offline"
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ console.log("新添加蓝牙设备", addDeviceList)
|
|
|
that.updateDeviceList(addDeviceList, false, false);
|
|
|
that.setData({
|
|
|
deviceListSelect: 0,
|
|
|
autoConnected: true,
|
|
|
});
|
|
|
+
|
|
|
that.addNotification()
|
|
|
},
|
|
|
|
|
@@ -794,8 +841,9 @@ Page({
|
|
|
let that = this;
|
|
|
event_bus.removeNotification(CmdEvent.eventName, that);
|
|
|
event_bus.addNotification(CmdEvent.eventName, function (event) {
|
|
|
+ let deviceList = that.getDeviceList()
|
|
|
+
|
|
|
if (event.cmdEvent == EnumCmdEvent.btMac) {
|
|
|
- let deviceList = that.getDeviceList()
|
|
|
let disDevice = deviceList.find(item => {
|
|
|
return item.state == "online" && item.connectType === 1
|
|
|
})
|
|
@@ -807,31 +855,43 @@ Page({
|
|
|
let isFirst = false;
|
|
|
// 有下线就开启监听扫描
|
|
|
if (event.commonValue == "online") {
|
|
|
+ console.log("有蓝牙设备上线")
|
|
|
that.stopIntervalId1();
|
|
|
} else {
|
|
|
- that.startBleTimer(isFirst);
|
|
|
+ let disDevice = deviceList.find(item => {
|
|
|
+ return item.state == "online" && item.connectType === 3
|
|
|
+ })
|
|
|
+ if (!disDevice) {
|
|
|
+ that.startBleTimer(isFirst);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- console.log("首页ble通知:", event.deviceId)
|
|
|
- let disDevice = that.data.deviceList.find(item => {
|
|
|
- return item.deviceId == event.deviceId
|
|
|
+ console.log("首页ble通知:", event.deviceId, event.commonValue)
|
|
|
+ let disDevice = deviceList.find(item => {
|
|
|
+ return item.deviceId == event.deviceId && item.connectType == 1
|
|
|
})
|
|
|
// that.data.deviceList.forEach(element => {
|
|
|
// if (item.deviceId == tmp.deviceId) {
|
|
|
// }
|
|
|
// });
|
|
|
if (!disDevice) {
|
|
|
+ console.log("没有在线的")
|
|
|
return;
|
|
|
}
|
|
|
- console.log("首页设备状态变化", disDevice)
|
|
|
disDevice.state = event.commonValue;
|
|
|
+ console.log("首页设备状态变化", disDevice.state, disDevice.deviceId)
|
|
|
+
|
|
|
+ let hasOnline = deviceList.find(item => {
|
|
|
+ return item.state == "online" && item.connectType == 1
|
|
|
+ })
|
|
|
+ console.log("发现有在线的", hasOnline)
|
|
|
|
|
|
if (event.commonValue == "online") {
|
|
|
// BtHelper.getInstance().connect()
|
|
|
console.log("首页上线连接", disDevice)
|
|
|
} else {
|
|
|
console.log("首页断开连接", disDevice)
|
|
|
- that.updateDeviceList(that.data.deviceList, false, false);
|
|
|
+ that.updateDeviceList(deviceList, false, false);
|
|
|
}
|
|
|
}
|
|
|
}, that);
|
|
@@ -848,9 +908,11 @@ Page({
|
|
|
}, 500);
|
|
|
return;
|
|
|
};
|
|
|
+ console.log("有新的wifi设备0", device)
|
|
|
|
|
|
var deviceId = device.deviceId;
|
|
|
var addDeviceList = lexin_add.addWifiDevice(device);
|
|
|
+ console.log("有新的wifi设备", addDeviceList)
|
|
|
that.updateDeviceList(addDeviceList, false, false);
|
|
|
|
|
|
var indexPage = that.data.indexPage;
|
|
@@ -864,7 +926,9 @@ Page({
|
|
|
|
|
|
refreshCurrentDevice(device) {
|
|
|
var that = this;
|
|
|
+ console.log("刷新列表0:", device)
|
|
|
var addDeviceList = lexin_add.addWifiDevice(device);
|
|
|
+ console.log("刷新列表1:", addDeviceList)
|
|
|
that.updateDeviceList(addDeviceList, false, false);
|
|
|
that.setData({
|
|
|
autoConnected: true,
|