@tuya-miniapp/ark-extension-virtual-device 1.6.2-beta-1 → 1.6.2-beta-3

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.
Files changed (2) hide show
  1. package/dist/worker/index.js +226 -221
  2. package/package.json +1 -1
@@ -220712,7 +220712,7 @@ var require_package2 = __commonJS({
220712
220712
  "package.json"(exports, module2) {
220713
220713
  module2.exports = {
220714
220714
  name: "@tuya-miniapp/ark-extension-virtual-device",
220715
- version: "1.6.1",
220715
+ version: "1.6.2-beta-2",
220716
220716
  license: "MIT",
220717
220717
  files: [
220718
220718
  "manifest.json",
@@ -264074,6 +264074,7 @@ var MqttClientManager = class _MqttClientManager {
264074
264074
  async function initMqttClient() {
264075
264075
  console.log("---------------initClient");
264076
264076
  const client = await MqttClientManager.init();
264077
+ console.log("---------------initClient success");
264077
264078
  return client;
264078
264079
  }
264079
264080
  var initMqttClient_default = MqttClientManager;
@@ -279661,15 +279662,6 @@ async function publishDps2(params) {
279661
279662
  let data = null;
279662
279663
  console.log("--------pv", pv);
279663
279664
  switch (pv) {
279664
- case "2.0":
279665
- result = await publishDps({ deviceId, dps: _dps }, (err) => {
279666
- reason = err;
279667
- console.log("--------error", err);
279668
- });
279669
- break;
279670
- case "2.2":
279671
- data = crypto_default.Encrypt22(message, dev.localKey);
279672
- break;
279673
279665
  case "2.3":
279674
279666
  data = crypto_default.Encrypt23(message, dev.localKey);
279675
279667
  break;
@@ -281981,39 +281973,48 @@ var getInstalledExtList2 = () => {
281981
281973
  var getDebugExt = () => {
281982
281974
  return new Promise((resolve) => {
281983
281975
  ark.storage.get(DEBUG_EXT_STORAGE_KEY).then((value) => {
281984
- let list = null;
281985
- if (value) {
281986
- list = JSON.parse(value);
281976
+ try {
281977
+ let list = null;
281978
+ if (value) {
281979
+ list = JSON.parse(value);
281980
+ }
281981
+ resolve(list);
281982
+ } catch (error) {
281983
+ console.log("getDebugExt error", error);
281987
281984
  }
281988
- resolve(list);
281989
281985
  }).catch((err) => {
281990
281986
  resolve(null);
281991
281987
  });
281992
281988
  });
281993
281989
  };
281994
281990
  async function initPlugin() {
281995
- const installedExt = await getInstalledExtList2();
281996
- const plugins = [...installedExt];
281997
- const debugExt = await getDebugExt();
281998
- if (debugExt) {
281999
- plugins.push(debugExt);
282000
- }
282001
- return Promise.all(
282002
- plugins.map(async (item) => {
282003
- try {
282004
- const p2 = `${item.baseDir}/${item.worker.entry}`;
282005
- if (!!item.worker.initFunc) {
282006
- import(p2);
282007
- } else {
282008
- import(p2);
281991
+ try {
281992
+ const installedExt = await getInstalledExtList2();
281993
+ const plugins = [...installedExt];
281994
+ const debugExt = await getDebugExt();
281995
+ if (debugExt) {
281996
+ plugins.push(debugExt);
281997
+ }
281998
+ return Promise.all(
281999
+ plugins.map(async (item) => {
282000
+ try {
282001
+ const p2 = `${item.baseDir}/${item.worker.entry}`;
282002
+ if (!!item.worker.initFunc) {
282003
+ import(p2);
282004
+ } else {
282005
+ import(p2);
282006
+ }
282007
+ } catch (error) {
282008
+ console.log("\u63D2\u4EF6\u52A0\u8F7D\u5931\u8D25", item, error);
282009
282009
  }
282010
- } catch (error) {
282011
- console.log("\u63D2\u4EF6\u52A0\u8F7D\u5931\u8D25", item, error);
282012
- }
282013
- })
282014
- ).catch((e2) => {
282015
- console.log("------promise fail", e2);
282016
- });
282010
+ })
282011
+ ).catch((e2) => {
282012
+ console.log("------promise fail", e2);
282013
+ return Promise.reject(e2);
282014
+ });
282015
+ } catch (error) {
282016
+ return Promise.reject(error);
282017
+ }
282017
282018
  }
282018
282019
 
282019
282020
  // worker/utils/debugExtension.ts
@@ -282136,180 +282137,43 @@ function saveDebugExtension({ service, params: { path: path5 }, eventId }) {
282136
282137
 
282137
282138
  // worker/index.ts
282138
282139
  var isInstanceMode7 = process.env.PROJECT_MODE === "instant";
282139
- initPlugin();
282140
- ark.runtime.onMessage(async (event) => {
282141
- try {
282142
- const message = event.message;
282143
- console.log("\u540E\u7AEF\u6536\u5230\u6D88\u606F", message);
282144
- if (isJSON(message)) {
282145
- const data = JSON.parse(message);
282146
- if (data["__bridge__"]) {
282147
- const { event: event2, payload } = data["__bridge__"];
282148
- bridgeWall.send(event2, payload);
282149
- console.log("[bridgeWall.send]", data["__bridge__"]);
282150
- }
282151
- const service = data.service;
282152
- const params = data.params;
282153
- console.log(`\u540E\u7AEF\u65B9\u6CD5[${service}]\u662F\u5426\u5B9E\u73B0:`, service in services_default);
282154
- if (service in services_default) {
282155
- try {
282156
- const res = await services_default[service](params);
282157
- ark.runtime.sendMessage(
282158
- JSON.stringify({
282159
- ...data,
282160
- result: res
282161
- })
282162
- );
282163
- } catch (error) {
282164
- console.log(`\u540E\u7AEF\u65B9\u6CD5[${service}]\u6267\u884C\u5931\u8D25`, error);
282165
- ark.runtime.sendMessage(
282166
- JSON.stringify({
282167
- ...data,
282168
- result: null
282169
- })
282170
- );
282171
- }
282172
- } else {
282173
- if (service === "initLaunchParams") {
282174
- const { deviceId, productId, groupId, __debugMode } = params;
282175
- if (!!productId) {
282176
- await setProductId(productId);
282177
- } else {
282178
- await setProductId("");
282179
- }
282180
- if (!!deviceId) {
282181
- await setDeviceId(deviceId);
282182
- } else {
282183
- await setDeviceId("");
282184
- }
282185
- if (!!groupId) {
282186
- await setGroupId(groupId);
282187
- } else {
282188
- await setGroupId("");
282189
- }
282190
- initMqttClient_default.removeAllSubscribe();
282191
- await setDebugMode({ mode: __debugMode });
282192
- initLaunchParams();
282193
- ark.runtime.sendMessage(JSON.stringify({ ...data }));
282194
- } else if (service === "startMQTT") {
282195
- initMqttClient_default.reconnectAll();
282196
- } else if (service === "set_debug_extension_path") {
282197
- saveDebugExtension(data);
282198
- }
282199
- }
282200
- }
282201
- } catch (error) {
282202
- console.log("---------------error", error);
282203
- }
282204
- });
282205
- async function initLaunchParams() {
282206
- try {
282207
- onUpdateListener && onUpdateListener();
282208
- const status = await ark.auth.checkStatus();
282209
- console.log("authorized:", status);
282210
- if (status !== "authorized")
282211
- return;
282212
- console.log("to get device or group id");
282213
- let deviceId = await services_default.getDeviceId();
282214
- console.log(" got device id", deviceId);
282215
- const groupId = await services_default.getGroupId();
282216
- console.log(" got group id", groupId);
282217
- const mode = await services_default.getDebugMode();
282218
- console.log(" got dev mode", mode);
282219
- let deviceInfo2 = null, groupInfo2 = null;
282220
- if (groupId && mode === "group") {
282221
- const gd = await getGroupInfo({ groupId });
282222
- groupInfo2 = gd?.data;
282223
- deviceId = groupId;
282224
- }
282225
- if (deviceId && deviceId !== groupId) {
282226
- await getLangContent({});
282227
- await getDeviceInfo2({ deviceId });
282228
- deviceInfo2 = getCachedDevice()[deviceId];
282229
- }
282230
- console.log("to startMQTT", deviceId, groupId);
282231
- if (mode === "group") {
282232
- initMqttClient_default.addGroupListener(groupInfo2);
282233
- } else {
282234
- console.log("------------------- \u53BB\u76D1\u542C");
282235
- initMqttClient_default.addDeviceListener(deviceInfo2);
282236
- }
282237
- ark.utils.reload();
282238
- initUpdateMessage();
282239
- } catch (error) {
282240
- console.log("---------update", error);
282241
- }
282242
- }
282243
- isInstanceMode7 && ark.project.setCompilationParams({ params: `deviceId=123` });
282244
- ark.auth.onAuthed(async (env) => {
282245
- try {
282246
- await setProductId("");
282247
- await setDeviceId("");
282248
- await setGroupId("");
282249
- await setHomeId("");
282250
- const info = await services_default.getTuyaProjectInfo();
282251
- const { productId: pid } = info || {};
282252
- const productId = await services_default.getProductId();
282253
- if (pid !== productId) {
282254
- await services_default.setCompilationParams({ deviceId: "" });
282255
- }
282256
- initMqttClient_default._client && initMqttClient_default._client.end();
282257
- initMqttClient_default._client = null;
282258
- await initMqttClient();
282259
- await initLaunchParams();
282260
- ark.utils.reload();
282261
- } catch (error) {
282262
- console.error("---error", error);
282263
- }
282264
- });
282265
- ark.miniapp.onUploadedPackage(async () => {
282266
- const res = await services_default.getI18nNoUseStrings();
282267
- console.log("[onUploadedPackage]", "getI18nNoUseStrings:", res);
282268
- if (res.count > 0) {
282269
- const keys = getArray(res.result).reduce(
282270
- (acc, cur) => acc.concat(cur.noUseKeys),
282271
- []
282272
- );
282273
- ark.utils.message({
282274
- content: `\u68C0\u6D4B\u5230\u5197\u4F59\u591A\u8BED\u8A00\u5B57\u6BB5\uFF1A${keys.join(",")}`,
282275
- type: "error"
282276
- });
282277
- }
282278
- });
282279
- var onUpdateListener = null;
282280
- var initUpdateMessage = () => {
282281
- onUpdateListener = ark.project.onUpdate(async () => {
282282
- const { page, params } = await ark.project.getCompilationParams() || {};
282283
- await getHomeDeviceList();
282140
+ try {
282141
+ initPlugin();
282142
+ ark.runtime.onMessage(async (event) => {
282284
282143
  try {
282285
- let debugParams = parseSearchParams(params);
282286
- const allDeviceIds2 = getAllDeviceIds();
282287
- const allGroupIds2 = getAllGroupIds();
282288
- console.log(typeof allDeviceIds2, typeof allGroupIds2);
282289
- const { deviceId, groupId } = debugParams;
282290
- if (allDeviceIds2.length || allGroupIds2.length) {
282291
- console.log("-----deviceId", deviceId, groupId, typeof deviceId);
282292
- if (!!deviceId && allDeviceIds2.indexOf(deviceId) > -1 || !!groupId && allGroupIds2.indexOf(groupId) > -1) {
282293
- if (groupId) {
282294
- const groupInfo2 = await getGroupInfo({ groupId });
282295
- const { productId } = groupInfo2.data;
282296
- if (!!groupId) {
282297
- await setGroupId(groupId);
282298
- } else {
282299
- await setGroupId("");
282300
- }
282301
- if (!!productId) {
282302
- await setProductId(productId);
282303
- } else {
282304
- await setProductId("");
282305
- }
282306
- await setDebugMode({
282307
- mode: "group"
282308
- });
282309
- await initLaunchParams();
282310
- } else {
282311
- const device = await getDeviceInfo2({ deviceId });
282312
- const { productId } = device.data;
282144
+ const message = event.message;
282145
+ console.log("\u540E\u7AEF\u6536\u5230\u6D88\u606F", message);
282146
+ if (isJSON(message)) {
282147
+ const data = JSON.parse(message);
282148
+ if (data["__bridge__"]) {
282149
+ const { event: event2, payload } = data["__bridge__"];
282150
+ bridgeWall.send(event2, payload);
282151
+ console.log("[bridgeWall.send]", data["__bridge__"]);
282152
+ }
282153
+ const service = data.service;
282154
+ const params = data.params;
282155
+ console.log(`\u540E\u7AEF\u65B9\u6CD5[${service}]\u662F\u5426\u5B9E\u73B0:`, service in services_default);
282156
+ if (service in services_default) {
282157
+ try {
282158
+ const res = await services_default[service](params);
282159
+ ark.runtime.sendMessage(
282160
+ JSON.stringify({
282161
+ ...data,
282162
+ result: res
282163
+ })
282164
+ );
282165
+ } catch (error) {
282166
+ console.log(`\u540E\u7AEF\u65B9\u6CD5[${service}]\u6267\u884C\u5931\u8D25`, error);
282167
+ ark.runtime.sendMessage(
282168
+ JSON.stringify({
282169
+ ...data,
282170
+ result: null
282171
+ })
282172
+ );
282173
+ }
282174
+ } else {
282175
+ if (service === "initLaunchParams") {
282176
+ const { deviceId, productId, groupId, __debugMode } = params;
282313
282177
  if (!!productId) {
282314
282178
  await setProductId(productId);
282315
282179
  } else {
@@ -282320,25 +282184,166 @@ var initUpdateMessage = () => {
282320
282184
  } else {
282321
282185
  await setDeviceId("");
282322
282186
  }
282323
- await setDebugMode({
282324
- mode: deviceId.startsWith("vdev") ? "virtual" : "real"
282325
- });
282326
- await initLaunchParams();
282187
+ if (!!groupId) {
282188
+ await setGroupId(groupId);
282189
+ } else {
282190
+ await setGroupId("");
282191
+ }
282192
+ initMqttClient_default.removeAllSubscribe();
282193
+ await setDebugMode({ mode: __debugMode });
282194
+ initLaunchParams();
282195
+ ark.runtime.sendMessage(JSON.stringify({ ...data }));
282196
+ } else if (service === "startMQTT") {
282197
+ initMqttClient_default.reconnectAll();
282198
+ } else if (service === "set_debug_extension_path") {
282199
+ saveDebugExtension(data);
282327
282200
  }
282328
- } else {
282329
- console.log("\u4E0D\u884C\u554A\uFF0C \u8FD9ID\u627E\u4E0D\u5230");
282330
- ark.utils.message({
282331
- type: "error",
282332
- content: "\u8BF7\u5728\u9996\u9875\u9009\u62E9\u6216\u626B\u7801\u6DFB\u52A0\u8BBE\u5907"
282333
- });
282334
282201
  }
282335
282202
  }
282336
282203
  } catch (error) {
282337
- console.log(error);
282204
+ console.log("---------------error", error);
282338
282205
  }
282339
282206
  });
282340
- };
282341
- initMqttClient();
282207
+ const initLaunchParams = async () => {
282208
+ try {
282209
+ onUpdateListener && onUpdateListener();
282210
+ const status = await ark.auth.checkStatus();
282211
+ console.log("authorized:", status);
282212
+ if (status !== "authorized")
282213
+ return;
282214
+ console.log("to get device or group id");
282215
+ let deviceId = await services_default.getDeviceId();
282216
+ console.log(" got device id", deviceId);
282217
+ const groupId = await services_default.getGroupId();
282218
+ console.log(" got group id", groupId);
282219
+ const mode = await services_default.getDebugMode();
282220
+ console.log(" got dev mode", mode);
282221
+ let deviceInfo2 = null, groupInfo2 = null;
282222
+ if (groupId && mode === "group") {
282223
+ const gd = await getGroupInfo({ groupId });
282224
+ groupInfo2 = gd?.data;
282225
+ deviceId = groupId;
282226
+ }
282227
+ if (deviceId && deviceId !== groupId) {
282228
+ await getLangContent({});
282229
+ await getDeviceInfo2({ deviceId });
282230
+ deviceInfo2 = getCachedDevice()[deviceId];
282231
+ }
282232
+ console.log("to startMQTT", deviceId, groupId);
282233
+ if (mode === "group") {
282234
+ initMqttClient_default.addGroupListener(groupInfo2);
282235
+ } else {
282236
+ console.log("------------------- \u53BB\u76D1\u542C");
282237
+ initMqttClient_default.addDeviceListener(deviceInfo2);
282238
+ }
282239
+ ark.utils.reload();
282240
+ initUpdateMessage();
282241
+ } catch (error) {
282242
+ console.log("---------update", error);
282243
+ }
282244
+ };
282245
+ isInstanceMode7 && ark.project.setCompilationParams({ params: `deviceId=123` });
282246
+ ark.auth.onAuthed(async (env) => {
282247
+ try {
282248
+ await setProductId("");
282249
+ await setDeviceId("");
282250
+ await setGroupId("");
282251
+ await setHomeId("");
282252
+ const info = await services_default.getTuyaProjectInfo();
282253
+ const { productId: pid } = info || {};
282254
+ const productId = await services_default.getProductId();
282255
+ if (pid !== productId) {
282256
+ await services_default.setCompilationParams({ deviceId: "" });
282257
+ }
282258
+ initMqttClient_default._client && initMqttClient_default._client.end();
282259
+ initMqttClient_default._client = null;
282260
+ await initMqttClient();
282261
+ await initLaunchParams();
282262
+ ark.utils.reload();
282263
+ } catch (error) {
282264
+ console.error("---error", error);
282265
+ }
282266
+ });
282267
+ ark.miniapp.onUploadedPackage(async () => {
282268
+ const res = await services_default.getI18nNoUseStrings();
282269
+ console.log("[onUploadedPackage]", "getI18nNoUseStrings:", res);
282270
+ if (res.count > 0) {
282271
+ const keys = getArray(res.result).reduce(
282272
+ (acc, cur) => acc.concat(cur.noUseKeys),
282273
+ []
282274
+ );
282275
+ ark.utils.message({
282276
+ content: `\u68C0\u6D4B\u5230\u5197\u4F59\u591A\u8BED\u8A00\u5B57\u6BB5\uFF1A${keys.join(",")}`,
282277
+ type: "error"
282278
+ });
282279
+ }
282280
+ });
282281
+ let onUpdateListener = null;
282282
+ const initUpdateMessage = () => {
282283
+ onUpdateListener = ark.project.onUpdate(async () => {
282284
+ const { page, params } = await ark.project.getCompilationParams() || {};
282285
+ await getHomeDeviceList();
282286
+ try {
282287
+ let debugParams = parseSearchParams(params);
282288
+ const allDeviceIds2 = getAllDeviceIds();
282289
+ const allGroupIds2 = getAllGroupIds();
282290
+ console.log(typeof allDeviceIds2, typeof allGroupIds2);
282291
+ const { deviceId, groupId } = debugParams;
282292
+ if (allDeviceIds2.length || allGroupIds2.length) {
282293
+ console.log("-----deviceId", deviceId, groupId, typeof deviceId);
282294
+ if (!!deviceId && allDeviceIds2.indexOf(deviceId) > -1 || !!groupId && allGroupIds2.indexOf(groupId) > -1) {
282295
+ if (groupId) {
282296
+ const groupInfo2 = await getGroupInfo({ groupId });
282297
+ const { productId } = groupInfo2.data;
282298
+ if (!!groupId) {
282299
+ await setGroupId(groupId);
282300
+ } else {
282301
+ await setGroupId("");
282302
+ }
282303
+ if (!!productId) {
282304
+ await setProductId(productId);
282305
+ } else {
282306
+ await setProductId("");
282307
+ }
282308
+ await setDebugMode({
282309
+ mode: "group"
282310
+ });
282311
+ await initLaunchParams();
282312
+ } else {
282313
+ const device = await getDeviceInfo2({ deviceId });
282314
+ const { productId } = device.data;
282315
+ if (!!productId) {
282316
+ await setProductId(productId);
282317
+ } else {
282318
+ await setProductId("");
282319
+ }
282320
+ if (!!deviceId) {
282321
+ await setDeviceId(deviceId);
282322
+ } else {
282323
+ await setDeviceId("");
282324
+ }
282325
+ await setDebugMode({
282326
+ mode: deviceId.startsWith("vdev") ? "virtual" : "real"
282327
+ });
282328
+ await initLaunchParams();
282329
+ }
282330
+ } else {
282331
+ console.log("\u4E0D\u884C\u554A\uFF0C \u8FD9ID\u627E\u4E0D\u5230");
282332
+ ark.utils.message({
282333
+ type: "error",
282334
+ content: "\u8BF7\u5728\u9996\u9875\u9009\u62E9\u6216\u626B\u7801\u6DFB\u52A0\u8BBE\u5907"
282335
+ });
282336
+ }
282337
+ }
282338
+ } catch (error) {
282339
+ console.log(error);
282340
+ }
282341
+ });
282342
+ };
282343
+ initMqttClient();
282344
+ } catch (error) {
282345
+ console.log("-------------------worker \u6302\u4E86", error);
282346
+ }
282342
282347
  /*! Bundled license information:
282343
282348
 
282344
282349
  lodash/lodash.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-miniapp/ark-extension-virtual-device",
3
- "version": "1.6.2-beta-1",
3
+ "version": "1.6.2-beta-3",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "manifest.json",