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

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 +191 -196
  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-1",
220716
220716
  license: "MIT",
220717
220717
  files: [
220718
220718
  "manifest.json",
@@ -279661,15 +279661,6 @@ async function publishDps2(params) {
279661
279661
  let data = null;
279662
279662
  console.log("--------pv", pv);
279663
279663
  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
279664
  case "2.3":
279674
279665
  data = crypto_default.Encrypt23(message, dev.localKey);
279675
279666
  break;
@@ -282136,180 +282127,43 @@ function saveDebugExtension({ service, params: { path: path5 }, eventId }) {
282136
282127
 
282137
282128
  // worker/index.ts
282138
282129
  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();
282130
+ try {
282131
+ initPlugin();
282132
+ ark.runtime.onMessage(async (event) => {
282284
282133
  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;
282134
+ const message = event.message;
282135
+ console.log("\u540E\u7AEF\u6536\u5230\u6D88\u606F", message);
282136
+ if (isJSON(message)) {
282137
+ const data = JSON.parse(message);
282138
+ if (data["__bridge__"]) {
282139
+ const { event: event2, payload } = data["__bridge__"];
282140
+ bridgeWall.send(event2, payload);
282141
+ console.log("[bridgeWall.send]", data["__bridge__"]);
282142
+ }
282143
+ const service = data.service;
282144
+ const params = data.params;
282145
+ console.log(`\u540E\u7AEF\u65B9\u6CD5[${service}]\u662F\u5426\u5B9E\u73B0:`, service in services_default);
282146
+ if (service in services_default) {
282147
+ try {
282148
+ const res = await services_default[service](params);
282149
+ ark.runtime.sendMessage(
282150
+ JSON.stringify({
282151
+ ...data,
282152
+ result: res
282153
+ })
282154
+ );
282155
+ } catch (error) {
282156
+ console.log(`\u540E\u7AEF\u65B9\u6CD5[${service}]\u6267\u884C\u5931\u8D25`, error);
282157
+ ark.runtime.sendMessage(
282158
+ JSON.stringify({
282159
+ ...data,
282160
+ result: null
282161
+ })
282162
+ );
282163
+ }
282164
+ } else {
282165
+ if (service === "initLaunchParams") {
282166
+ const { deviceId, productId, groupId, __debugMode } = params;
282313
282167
  if (!!productId) {
282314
282168
  await setProductId(productId);
282315
282169
  } else {
@@ -282320,25 +282174,166 @@ var initUpdateMessage = () => {
282320
282174
  } else {
282321
282175
  await setDeviceId("");
282322
282176
  }
282323
- await setDebugMode({
282324
- mode: deviceId.startsWith("vdev") ? "virtual" : "real"
282325
- });
282326
- await initLaunchParams();
282177
+ if (!!groupId) {
282178
+ await setGroupId(groupId);
282179
+ } else {
282180
+ await setGroupId("");
282181
+ }
282182
+ initMqttClient_default.removeAllSubscribe();
282183
+ await setDebugMode({ mode: __debugMode });
282184
+ initLaunchParams();
282185
+ ark.runtime.sendMessage(JSON.stringify({ ...data }));
282186
+ } else if (service === "startMQTT") {
282187
+ initMqttClient_default.reconnectAll();
282188
+ } else if (service === "set_debug_extension_path") {
282189
+ saveDebugExtension(data);
282327
282190
  }
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
282191
  }
282335
282192
  }
282336
282193
  } catch (error) {
282337
- console.log(error);
282194
+ console.log("---------------error", error);
282338
282195
  }
282339
282196
  });
282340
- };
282341
- initMqttClient();
282197
+ async function initLaunchParams() {
282198
+ try {
282199
+ onUpdateListener && onUpdateListener();
282200
+ const status = await ark.auth.checkStatus();
282201
+ console.log("authorized:", status);
282202
+ if (status !== "authorized")
282203
+ return;
282204
+ console.log("to get device or group id");
282205
+ let deviceId = await services_default.getDeviceId();
282206
+ console.log(" got device id", deviceId);
282207
+ const groupId = await services_default.getGroupId();
282208
+ console.log(" got group id", groupId);
282209
+ const mode = await services_default.getDebugMode();
282210
+ console.log(" got dev mode", mode);
282211
+ let deviceInfo2 = null, groupInfo2 = null;
282212
+ if (groupId && mode === "group") {
282213
+ const gd = await getGroupInfo({ groupId });
282214
+ groupInfo2 = gd?.data;
282215
+ deviceId = groupId;
282216
+ }
282217
+ if (deviceId && deviceId !== groupId) {
282218
+ await getLangContent({});
282219
+ await getDeviceInfo2({ deviceId });
282220
+ deviceInfo2 = getCachedDevice()[deviceId];
282221
+ }
282222
+ console.log("to startMQTT", deviceId, groupId);
282223
+ if (mode === "group") {
282224
+ initMqttClient_default.addGroupListener(groupInfo2);
282225
+ } else {
282226
+ console.log("------------------- \u53BB\u76D1\u542C");
282227
+ initMqttClient_default.addDeviceListener(deviceInfo2);
282228
+ }
282229
+ ark.utils.reload();
282230
+ initUpdateMessage();
282231
+ } catch (error) {
282232
+ console.log("---------update", error);
282233
+ }
282234
+ }
282235
+ isInstanceMode7 && ark.project.setCompilationParams({ params: `deviceId=123` });
282236
+ ark.auth.onAuthed(async (env) => {
282237
+ try {
282238
+ await setProductId("");
282239
+ await setDeviceId("");
282240
+ await setGroupId("");
282241
+ await setHomeId("");
282242
+ const info = await services_default.getTuyaProjectInfo();
282243
+ const { productId: pid } = info || {};
282244
+ const productId = await services_default.getProductId();
282245
+ if (pid !== productId) {
282246
+ await services_default.setCompilationParams({ deviceId: "" });
282247
+ }
282248
+ initMqttClient_default._client && initMqttClient_default._client.end();
282249
+ initMqttClient_default._client = null;
282250
+ await initMqttClient();
282251
+ await initLaunchParams();
282252
+ ark.utils.reload();
282253
+ } catch (error) {
282254
+ console.error("---error", error);
282255
+ }
282256
+ });
282257
+ ark.miniapp.onUploadedPackage(async () => {
282258
+ const res = await services_default.getI18nNoUseStrings();
282259
+ console.log("[onUploadedPackage]", "getI18nNoUseStrings:", res);
282260
+ if (res.count > 0) {
282261
+ const keys = getArray(res.result).reduce(
282262
+ (acc, cur) => acc.concat(cur.noUseKeys),
282263
+ []
282264
+ );
282265
+ ark.utils.message({
282266
+ content: `\u68C0\u6D4B\u5230\u5197\u4F59\u591A\u8BED\u8A00\u5B57\u6BB5\uFF1A${keys.join(",")}`,
282267
+ type: "error"
282268
+ });
282269
+ }
282270
+ });
282271
+ let onUpdateListener = null;
282272
+ const initUpdateMessage = () => {
282273
+ onUpdateListener = ark.project.onUpdate(async () => {
282274
+ const { page, params } = await ark.project.getCompilationParams() || {};
282275
+ await getHomeDeviceList();
282276
+ try {
282277
+ let debugParams = parseSearchParams(params);
282278
+ const allDeviceIds2 = getAllDeviceIds();
282279
+ const allGroupIds2 = getAllGroupIds();
282280
+ console.log(typeof allDeviceIds2, typeof allGroupIds2);
282281
+ const { deviceId, groupId } = debugParams;
282282
+ if (allDeviceIds2.length || allGroupIds2.length) {
282283
+ console.log("-----deviceId", deviceId, groupId, typeof deviceId);
282284
+ if (!!deviceId && allDeviceIds2.indexOf(deviceId) > -1 || !!groupId && allGroupIds2.indexOf(groupId) > -1) {
282285
+ if (groupId) {
282286
+ const groupInfo2 = await getGroupInfo({ groupId });
282287
+ const { productId } = groupInfo2.data;
282288
+ if (!!groupId) {
282289
+ await setGroupId(groupId);
282290
+ } else {
282291
+ await setGroupId("");
282292
+ }
282293
+ if (!!productId) {
282294
+ await setProductId(productId);
282295
+ } else {
282296
+ await setProductId("");
282297
+ }
282298
+ await setDebugMode({
282299
+ mode: "group"
282300
+ });
282301
+ await initLaunchParams();
282302
+ } else {
282303
+ const device = await getDeviceInfo2({ deviceId });
282304
+ const { productId } = device.data;
282305
+ if (!!productId) {
282306
+ await setProductId(productId);
282307
+ } else {
282308
+ await setProductId("");
282309
+ }
282310
+ if (!!deviceId) {
282311
+ await setDeviceId(deviceId);
282312
+ } else {
282313
+ await setDeviceId("");
282314
+ }
282315
+ await setDebugMode({
282316
+ mode: deviceId.startsWith("vdev") ? "virtual" : "real"
282317
+ });
282318
+ await initLaunchParams();
282319
+ }
282320
+ } else {
282321
+ console.log("\u4E0D\u884C\u554A\uFF0C \u8FD9ID\u627E\u4E0D\u5230");
282322
+ ark.utils.message({
282323
+ type: "error",
282324
+ content: "\u8BF7\u5728\u9996\u9875\u9009\u62E9\u6216\u626B\u7801\u6DFB\u52A0\u8BBE\u5907"
282325
+ });
282326
+ }
282327
+ }
282328
+ } catch (error) {
282329
+ console.log(error);
282330
+ }
282331
+ });
282332
+ };
282333
+ initMqttClient();
282334
+ } catch (error) {
282335
+ console.log("-------------------worker \u6302\u4E86", error);
282336
+ }
282342
282337
  /*! Bundled license information:
282343
282338
 
282344
282339
  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-2",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "manifest.json",