@tuya-miniapp/ark-extension-virtual-device 1.8.7 → 1.8.8-beta-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/worker/index.js +62 -49
- package/package.json +1 -1
package/dist/worker/index.js
CHANGED
|
@@ -220752,7 +220752,7 @@ var require_package2 = __commonJS({
|
|
|
220752
220752
|
"package.json"(exports, module2) {
|
|
220753
220753
|
module2.exports = {
|
|
220754
220754
|
name: "@tuya-miniapp/ark-extension-virtual-device",
|
|
220755
|
-
version: "1.8.7
|
|
220755
|
+
version: "1.8.7",
|
|
220756
220756
|
license: "MIT",
|
|
220757
220757
|
files: [
|
|
220758
220758
|
"manifest.json",
|
|
@@ -279951,6 +279951,7 @@ async function getDeviceInfo2(params) {
|
|
|
279951
279951
|
errorMsg: import_TYUniCode3.TYUniPluginError.SUCCESS.des
|
|
279952
279952
|
};
|
|
279953
279953
|
} catch (error) {
|
|
279954
|
+
console.log("----------error", error);
|
|
279954
279955
|
return {
|
|
279955
279956
|
data: null,
|
|
279956
279957
|
errorCode: import_TYUniCode3.TYUniPluginError.INTERNAL_ERROR.code,
|
|
@@ -280687,17 +280688,18 @@ async function removeDevice(params) {
|
|
|
280687
280688
|
}
|
|
280688
280689
|
}
|
|
280689
280690
|
async function registerMQTTDeviceListener(params) {
|
|
280690
|
-
const { deviceId } = params;
|
|
280691
|
-
await getDeviceInfo2({ deviceId });
|
|
280692
|
-
const deviceInfo2 = cachedDevices2[deviceId];
|
|
280693
|
-
initMqttClient_default.addDeviceListener(deviceInfo2);
|
|
280694
280691
|
try {
|
|
280692
|
+
const { deviceId } = params;
|
|
280693
|
+
await getDeviceInfo2({ deviceId });
|
|
280694
|
+
const deviceInfo2 = cachedDevices2[deviceId];
|
|
280695
|
+
initMqttClient_default.addDeviceListener(deviceInfo2);
|
|
280695
280696
|
return {
|
|
280696
280697
|
data: {},
|
|
280697
280698
|
errorCode: 0,
|
|
280698
280699
|
errorMsg: import_TYUniCode3.TYUniPluginError.SUCCESS.des
|
|
280699
280700
|
};
|
|
280700
280701
|
} catch (error) {
|
|
280702
|
+
console.error("registerMQTTDeviceListener error:", error);
|
|
280701
280703
|
return {
|
|
280702
280704
|
data: false,
|
|
280703
280705
|
errorCode: import_TYUniCode3.TYUniPluginError.DEVICEKIT_GW_ID_INVALID.code,
|
|
@@ -280772,58 +280774,69 @@ async function unSubscribeDeviceRemoved(params) {
|
|
|
280772
280774
|
}
|
|
280773
280775
|
}
|
|
280774
280776
|
async function sendMqttMessage(params) {
|
|
280775
|
-
|
|
280776
|
-
|
|
280777
|
-
|
|
280778
|
-
|
|
280779
|
-
|
|
280780
|
-
|
|
280781
|
-
|
|
280782
|
-
|
|
280783
|
-
const topic = `smart/mb/out/${dev.devId}`;
|
|
280784
|
-
const { pv = "2.2", localKey } = dev;
|
|
280785
|
-
if (localKey) {
|
|
280786
|
-
let data2 = null;
|
|
280787
|
-
switch (pv) {
|
|
280788
|
-
case "2.0":
|
|
280789
|
-
data2 = crypto_default.Encrypt20(message, dev.localKey, dev.gwId || dev.devId);
|
|
280790
|
-
break;
|
|
280791
|
-
case "2.2":
|
|
280792
|
-
if (dev.localKey) {
|
|
280793
|
-
data2 = crypto_default.Encrypt22(message, dev.localKey);
|
|
280794
|
-
}
|
|
280795
|
-
break;
|
|
280796
|
-
case "2.3":
|
|
280797
|
-
data2 = crypto_default.Encrypt23(message, dev.localKey);
|
|
280798
|
-
break;
|
|
280799
|
-
default:
|
|
280800
|
-
break;
|
|
280777
|
+
try {
|
|
280778
|
+
const { protocol, message: data, deviceId } = params;
|
|
280779
|
+
if (!deviceId) {
|
|
280780
|
+
return {
|
|
280781
|
+
data: null,
|
|
280782
|
+
errorCode: import_TYUniCode3.TYUniPluginError.INCORRECT_PARAM.code,
|
|
280783
|
+
errorMsg: import_TYUniCode3.TYUniPluginError.INCORRECT_PARAM.des
|
|
280784
|
+
};
|
|
280801
280785
|
}
|
|
280802
|
-
|
|
280803
|
-
|
|
280804
|
-
|
|
280805
|
-
|
|
280806
|
-
{
|
|
280807
|
-
qos: 1,
|
|
280808
|
-
retain: true
|
|
280809
|
-
},
|
|
280810
|
-
(error, pocket) => {
|
|
280811
|
-
}
|
|
280812
|
-
);
|
|
280786
|
+
let dev = cachedDevices2[deviceId];
|
|
280787
|
+
if (!dev) {
|
|
280788
|
+
await getDeviceInfo2({ deviceId });
|
|
280789
|
+
dev = cachedDevices2[deviceId];
|
|
280813
280790
|
}
|
|
280814
|
-
|
|
280791
|
+
const message = {
|
|
280792
|
+
t: `${(/* @__PURE__ */ new Date()).getTime()}`.substring(0, 10),
|
|
280793
|
+
protocol,
|
|
280794
|
+
data
|
|
280795
|
+
};
|
|
280796
|
+
const topic = `smart/mb/out/${dev.devId}`;
|
|
280797
|
+
const { pv = "2.2", localKey } = dev;
|
|
280798
|
+
if (localKey) {
|
|
280799
|
+
let data2 = null;
|
|
280800
|
+
switch (pv) {
|
|
280801
|
+
case "2.0":
|
|
280802
|
+
data2 = crypto_default.Encrypt20(message, dev.localKey, dev.gwId || dev.devId);
|
|
280803
|
+
break;
|
|
280804
|
+
case "2.2":
|
|
280805
|
+
if (dev.localKey) {
|
|
280806
|
+
data2 = crypto_default.Encrypt22(message, dev.localKey);
|
|
280807
|
+
}
|
|
280808
|
+
break;
|
|
280809
|
+
case "2.3":
|
|
280810
|
+
data2 = crypto_default.Encrypt23(message, dev.localKey);
|
|
280811
|
+
break;
|
|
280812
|
+
default:
|
|
280813
|
+
break;
|
|
280814
|
+
}
|
|
280815
|
+
if (data2) {
|
|
280816
|
+
initMqttClient_default._client.publish(
|
|
280817
|
+
topic,
|
|
280818
|
+
data2,
|
|
280819
|
+
{
|
|
280820
|
+
qos: 1,
|
|
280821
|
+
retain: true
|
|
280822
|
+
},
|
|
280823
|
+
(error, pocket) => {
|
|
280824
|
+
}
|
|
280825
|
+
);
|
|
280826
|
+
}
|
|
280815
280827
|
return {
|
|
280816
280828
|
data: null,
|
|
280817
280829
|
errorCode: 0,
|
|
280818
280830
|
errorMsg: import_TYUniCode3.TYUniPluginError.SUCCESS.des
|
|
280819
280831
|
};
|
|
280820
|
-
} catch (error) {
|
|
280821
|
-
return {
|
|
280822
|
-
data: false,
|
|
280823
|
-
errorCode: import_TYUniCode3.TYUniPluginError.DEVICEKIT_GW_ID_INVALID.code,
|
|
280824
|
-
errorMsg: import_TYUniCode3.TYUniPluginError.DEVICEKIT_GW_ID_INVALID.des
|
|
280825
|
-
};
|
|
280826
280832
|
}
|
|
280833
|
+
} catch (error) {
|
|
280834
|
+
console.log("sendMqttMessage error:", error);
|
|
280835
|
+
return {
|
|
280836
|
+
data: false,
|
|
280837
|
+
errorCode: import_TYUniCode3.TYUniPluginError.DEVICEKIT_GW_ID_INVALID.code,
|
|
280838
|
+
errorMsg: import_TYUniCode3.TYUniPluginError.DEVICEKIT_GW_ID_INVALID.des
|
|
280839
|
+
};
|
|
280827
280840
|
}
|
|
280828
280841
|
}
|
|
280829
280842
|
async function syncDeviceInfo(params) {
|