|
@@ -0,0 +1,99 @@
|
|
|
|
+module.exports = {
|
|
|
|
+ searchOnlineDevice: searchOnlineDevice,
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
|
|
|
|
+///连上就调用2次 处理离线在线问题 wifi设备 BLUFI_
|
|
|
|
+/// payloads:{"uuid":"AIrSMArT_7cdfa1fcbb24","state":"online","userid":"1"}
|
|
|
|
+// [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
|
|
|
|
+
|
|
|
|
+///更新在线状态,连接第一个在线设备
|
|
|
|
+// deviceId: BLUFI_7cdfa1fd3af0
|
|
|
|
+// uuid: AIrSMArT_7cdfa1fd3af0
|
|
|
|
+function searchOnlineDevice(payloads, changeCallback, resetCallback) {
|
|
|
|
+ var isChanged = false;
|
|
|
|
+ const strings = require('../strings');
|
|
|
|
+ var deviceList = getCurrentPages()[0].getDeviceList();
|
|
|
|
+
|
|
|
|
+ /// 处理在线设备
|
|
|
|
+ if (!strings.isEmpty(deviceList)) {
|
|
|
|
+ for (var i = 0; i < deviceList.length; i++) {
|
|
|
|
+ if (payloads && payloads.uuid) {
|
|
|
|
+ var device = deviceList[i];
|
|
|
|
+ var connectType = device.connectType;
|
|
|
|
+ if (connectType == 3) {
|
|
|
|
+ var deviceId = device.deviceId;
|
|
|
|
+ var splitDeviceId = deviceId.split("BLUFI_");
|
|
|
|
+ if (splitDeviceId.length == 2) {
|
|
|
|
+ var index = payloads.uuid.indexOf(splitDeviceId[1]);
|
|
|
|
+ if (index !== -1) {
|
|
|
|
+ if (device.state != payloads.state) {
|
|
|
|
+ isChanged = true;
|
|
|
|
+ device.state = payloads.state;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ///更新数据
|
|
|
|
+ if (isChanged) {
|
|
|
|
+ changeCallback(deviceList);
|
|
|
|
+ }
|
|
|
|
+ _connectToDevice(resetCallback);
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/// 连接设备
|
|
|
|
+function _connectToDevice(resetCallback) {
|
|
|
|
+ ///是否已登录
|
|
|
|
+ var isLogin = getCurrentPages()[0].getIsLogin();
|
|
|
|
+ if (!isLogin) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ///当前没有连接设备,则去连接第一个wifi设备
|
|
|
|
+ var deviceList = getCurrentPages()[0].getDeviceList();
|
|
|
|
+ var deviceListSelect = getCurrentPages()[0].getDeviceListSelect();
|
|
|
|
+ ///去连接第一个
|
|
|
|
+ if (deviceListSelect === null) {
|
|
|
|
+ const strings = require('../strings');
|
|
|
|
+ if (!strings.isEmpty(deviceList)) {
|
|
|
|
+ var autoConnected = getCurrentPages()[0].getAutoConnected();
|
|
|
|
+ var connectDeviceIding = getCurrentPages()[0].getConnectDeviceIding();
|
|
|
|
+
|
|
|
|
+ console.log("呃呃呃呃呃呃呃==000===" + connectDeviceIding);
|
|
|
|
+ /// 还没有自动连接采用第一个
|
|
|
|
+ if (!autoConnected) {
|
|
|
|
+ for (var i = 0; i < deviceList.length; i++) {
|
|
|
|
+ var device = deviceList[i];
|
|
|
|
+ var deviceId = device.deviceId;
|
|
|
|
+ if (device.connectType == 3 && device.state === "online") {
|
|
|
|
+ connectDeviceIding = deviceId;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (var i = 0; i < deviceList.length; i++) {
|
|
|
|
+ var device = deviceList[i];
|
|
|
|
+ var deviceId = device.deviceId;
|
|
|
|
+ console.log("呃呃呃呃呃呃呃==111===" + deviceId + "===" + connectDeviceIding);
|
|
|
|
+ if (deviceId == connectDeviceIding) {
|
|
|
|
+ console.log("呃呃呃呃呃呃呃==22222===" + deviceId + "===" + connectDeviceIding);
|
|
|
|
+ if (device.connectType == 3 && device.state === "online") {
|
|
|
|
+ getCurrentPages()[0].actionDevice(device);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 当前播放设备离线
|
|
|
|
+ if (deviceList.length > deviceListSelect && deviceList[deviceListSelect].state !== "online") {
|
|
|
|
+ resetCallback();
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+}
|