@ray-js/lock-sdk 1.0.1 → 1.0.3-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.
Files changed (86) hide show
  1. package/lib/api/index.js +13 -15
  2. package/lib/api/linkage.d.ts +0 -18
  3. package/lib/api/linkage.js +61 -81
  4. package/lib/api/lock.d.ts +0 -69
  5. package/lib/api/lock.js +91 -113
  6. package/lib/api/log.d.ts +0 -33
  7. package/lib/api/log.js +33 -38
  8. package/lib/api/setting.d.ts +0 -11
  9. package/lib/api/setting.js +17 -30
  10. package/lib/api/temp.d.ts +0 -48
  11. package/lib/api/temp.js +85 -115
  12. package/lib/api/user.d.ts +5 -54
  13. package/lib/api/user.js +40 -52
  14. package/lib/api/video.d.ts +0 -5
  15. package/lib/api/video.js +9 -15
  16. package/lib/config/dp-code/index.d.ts +0 -117
  17. package/lib/config/dp-code/index.js +79 -221
  18. package/lib/config/dp-map/common.d.ts +0 -3
  19. package/lib/config/dp-map/common.js +101 -116
  20. package/lib/config/dp-map/normal.js +29 -50
  21. package/lib/config/dp-map/open.d.ts +0 -16
  22. package/lib/config/dp-map/open.js +62 -63
  23. package/lib/config/dp-map/unlock-method-big.d.ts +0 -60
  24. package/lib/config/dp-map/unlock-method-big.js +196 -233
  25. package/lib/config/dp-map/unlock-method.d.ts +0 -63
  26. package/lib/config/dp-map/unlock-method.js +189 -227
  27. package/lib/config/index.d.ts +0 -25
  28. package/lib/config/index.js +21 -54
  29. package/lib/constant.d.ts +12 -40
  30. package/lib/constant.js +83 -136
  31. package/lib/event.d.ts +0 -6
  32. package/lib/event.js +1 -8
  33. package/lib/index.d.ts +0 -7
  34. package/lib/index.js +45 -71
  35. package/lib/interface.d.ts +0 -523
  36. package/lib/interface.js +1 -1
  37. package/lib/linkage.d.ts +0 -18
  38. package/lib/linkage.js +125 -162
  39. package/lib/log.d.ts +0 -50
  40. package/lib/log.js +255 -290
  41. package/lib/media.d.ts +0 -34
  42. package/lib/media.js +6 -77
  43. package/lib/open.d.ts +0 -35
  44. package/lib/open.js +129 -224
  45. package/lib/other.d.ts +8 -26
  46. package/lib/other.js +107 -159
  47. package/lib/parse/index.d.ts +0 -4
  48. package/lib/parse/index.js +13 -19
  49. package/lib/signal.d.ts +0 -13
  50. package/lib/signal.js +17 -31
  51. package/lib/sleep.d.ts +0 -42
  52. package/lib/sleep.js +41 -98
  53. package/lib/state.d.ts +0 -38
  54. package/lib/state.js +223 -369
  55. package/lib/sync/remote-serect-key.d.ts +0 -4
  56. package/lib/sync/remote-serect-key.js +33 -49
  57. package/lib/sync/t0.d.ts +0 -3
  58. package/lib/sync/t0.js +14 -21
  59. package/lib/sync/temp.d.ts +0 -5
  60. package/lib/sync/temp.js +68 -77
  61. package/lib/sync/unlock-mothod.d.ts +0 -3
  62. package/lib/sync/unlock-mothod.js +28 -40
  63. package/lib/temporary.d.ts +0 -149
  64. package/lib/temporary.js +469 -593
  65. package/lib/unlock-method.d.ts +0 -185
  66. package/lib/unlock-method.js +479 -650
  67. package/lib/user.d.ts +2 -81
  68. package/lib/user.js +202 -336
  69. package/lib/utils/base64-to-hex.js +10 -10
  70. package/lib/utils/byte.d.ts +0 -16
  71. package/lib/utils/byte.js +57 -68
  72. package/lib/utils/constant.js +7 -11
  73. package/lib/utils/device.d.ts +46 -83
  74. package/lib/utils/device.js +294 -322
  75. package/lib/utils/errors.js +75 -122
  76. package/lib/utils/event.js +79 -135
  77. package/lib/utils/hex-to-base64.js +5 -5
  78. package/lib/utils/hex-to-bytes.d.ts +0 -5
  79. package/lib/utils/hex-to-bytes.js +10 -15
  80. package/lib/utils/index.d.ts +0 -42
  81. package/lib/utils/index.js +247 -377
  82. package/lib/utils/log.d.ts +1 -4
  83. package/lib/utils/log.js +71 -74
  84. package/lib/utils/publishDps.d.ts +0 -5
  85. package/lib/utils/publishDps.js +58 -80
  86. package/package.json +3 -4
package/lib/constant.js CHANGED
@@ -1,136 +1,83 @@
1
- /**
2
- * 用户类型
3
- * 10 - 管理员
4
- * 20 - 普通成员
5
- * 30 - 匿名用户
6
- * 40 - 分享成员
7
- * 50 - 家庭拥有者
8
- */
9
- export let UserType = /*#__PURE__*/function (UserType) {
10
- UserType[UserType["ADMIN"] = 10] = "ADMIN";
11
- // 管理员
12
- UserType[UserType["MEMBER"] = 20] = "MEMBER";
13
- // 普通成员
14
- UserType[UserType["UNKNOW"] = 30] = "UNKNOW";
15
- // 匿名用户
16
- UserType[UserType["SHARE"] = 40] = "SHARE";
17
- // 分享成员
18
- UserType[UserType["OWNER"] = 50] = "OWNER"; // 家庭拥有者
19
- return UserType;
20
- }({});
21
-
22
- // 模组类型
23
- export let ModuleType = /*#__PURE__*/function (ModuleType) {
24
- ModuleType[ModuleType["T31"] = 0] = "T31";
25
- ModuleType[ModuleType["WBRL"] = 1] = "WBRL";
26
- ModuleType[ModuleType["M9116"] = 2] = "M9116";
27
- ModuleType[ModuleType["M7258"] = 3] = "M7258";
28
- ModuleType[ModuleType["T3"] = 4] = "T3";
29
- return ModuleType;
30
- }({});
31
-
32
- // 支持视频类型
33
- export let VedioType = /*#__PURE__*/function (VedioType) {
34
- VedioType[VedioType["NONE"] = 0] = "NONE";
35
- // 不支持视频相关能力
36
- VedioType[VedioType["VEDIO_OR_SNAPSHOT"] = 1] = "VEDIO_OR_SNAPSHOT"; // 支持视频或者抓拍
37
- return VedioType;
38
- }({});
39
-
40
- // 语音类型
41
- export let VoiceType = /*#__PURE__*/function (VoiceType) {
42
- VoiceType[VoiceType["ONE_WAY"] = 0] = "ONE_WAY";
43
- // 单向
44
- VoiceType[VoiceType["TWO_WAY"] = 1] = "TWO_WAY"; // 双向
45
- return VoiceType;
46
- }({});
47
-
48
- // 视频流方案
49
- export let VedioStreamType = /*#__PURE__*/function (VedioStreamType) {
50
- VedioStreamType[VedioStreamType["STREAMER"] = 0] = "STREAMER";
51
- // 推流方式
52
- VedioStreamType[VedioStreamType["P2P"] = 1] = "P2P"; // P2P 方式
53
- return VedioStreamType;
54
- }({});
55
-
56
- // 通讯能力
57
- export let CommunicationType = /*#__PURE__*/function (CommunicationType) {
58
- CommunicationType[CommunicationType["WIFI"] = 0] = "WIFI";
59
- // WIFI
60
- CommunicationType[CommunicationType["WIFI_BLE"] = 1] = "WIFI_BLE";
61
- // 蓝牙 + wifi
62
- CommunicationType[CommunicationType["THREAD"] = 2] = "THREAD";
63
- // 蓝牙 + Thread
64
- CommunicationType[CommunicationType["THREAD_BLE"] = 3] = "THREAD_BLE";
65
- // 蓝牙 + thread
66
- CommunicationType[CommunicationType["NONE"] = 255] = "NONE"; // 未知
67
- return CommunicationType;
68
- }({});
69
- export let RotateType = /*#__PURE__*/function (RotateType) {
70
- RotateType[RotateType["PID"] = 0] = "PID";
71
- // pid旋转
72
- RotateType[RotateType["SEI"] = 1] = "SEI"; // sei旋转
73
- return RotateType;
74
- }({});
75
-
76
- /**
77
- * 涂鸦支持的通讯能力
78
- */
79
- export let ProductCommunicationType = /*#__PURE__*/function (ProductCommunicationType) {
80
- ProductCommunicationType[ProductCommunicationType["WIFI"] = 0] = "WIFI";
81
- ProductCommunicationType[ProductCommunicationType["CABLE"] = 1] = "CABLE";
82
- ProductCommunicationType[ProductCommunicationType["GPRS"] = 2] = "GPRS";
83
- ProductCommunicationType[ProductCommunicationType["NB_IOT"] = 3] = "NB_IOT";
84
- ProductCommunicationType[ProductCommunicationType["BLUETOOTH"] = 10] = "BLUETOOTH";
85
- ProductCommunicationType[ProductCommunicationType["BLE_MESH"] = 11] = "BLE_MESH";
86
- ProductCommunicationType[ProductCommunicationType["ZIGBEE"] = 12] = "ZIGBEE";
87
- ProductCommunicationType[ProductCommunicationType["INFRARED"] = 13] = "INFRARED";
88
- ProductCommunicationType[ProductCommunicationType["SUBPIECES"] = 14] = "SUBPIECES";
89
- ProductCommunicationType[ProductCommunicationType["SIGMESH"] = 15] = "SIGMESH";
90
- ProductCommunicationType[ProductCommunicationType["MCU"] = 16] = "MCU";
91
- ProductCommunicationType[ProductCommunicationType["TY_SMESH"] = 17] = "TY_SMESH";
92
- ProductCommunicationType[ProductCommunicationType["ZWAVE"] = 18] = "ZWAVE";
93
- ProductCommunicationType[ProductCommunicationType["PL_MESH"] = 19] = "PL_MESH";
94
- ProductCommunicationType[ProductCommunicationType["CAT1"] = 20] = "CAT1";
95
- ProductCommunicationType[ProductCommunicationType["BEACON"] = 21] = "BEACON";
96
- ProductCommunicationType[ProductCommunicationType["CAT4"] = 22] = "CAT4";
97
- ProductCommunicationType[ProductCommunicationType["CAT10"] = 23] = "CAT10";
98
- ProductCommunicationType[ProductCommunicationType["LTE_CATM"] = 24] = "LTE_CATM";
99
- ProductCommunicationType[ProductCommunicationType["THREAD"] = 25] = "THREAD";
100
- return ProductCommunicationType;
101
- }({});
102
-
103
- /**
104
- * 本地管理用户类型
105
- */
106
- export let LocalOperateUserType = /*#__PURE__*/function (LocalOperateUserType) {
107
- LocalOperateUserType[LocalOperateUserType["SUPER_ADMIN"] = 0] = "SUPER_ADMIN";
108
- LocalOperateUserType[LocalOperateUserType["ADMIN"] = 1] = "ADMIN";
109
- LocalOperateUserType[LocalOperateUserType["SPECIAL_USER"] = 2] = "SPECIAL_USER";
110
- LocalOperateUserType[LocalOperateUserType["NORMAL_USER"] = 3] = "NORMAL_USER";
111
- return LocalOperateUserType;
112
- }({});
113
-
114
- /**
115
- * 本地管理操作类型
116
- * 开锁方式类:
117
- * 0 表示 添加开锁方式
118
- * 1 表示删除开锁方式
119
- * 2 表示修改开锁方式
120
- *
121
- * 操作用户类:
122
- * 16:添加用户
123
- * 17:删除用户
124
- *
125
- * 本地设置类:
126
- * 32 表示本地设备设置
127
- */
128
- export let LocalOperateCategory = /*#__PURE__*/function (LocalOperateCategory) {
129
- LocalOperateCategory[LocalOperateCategory["ADD_UNLOCK_METHOD"] = 0] = "ADD_UNLOCK_METHOD";
130
- LocalOperateCategory[LocalOperateCategory["DELETE_UNLOCK_METHOD"] = 1] = "DELETE_UNLOCK_METHOD";
131
- LocalOperateCategory[LocalOperateCategory["MODIFY_UNLOCK_METHOD"] = 2] = "MODIFY_UNLOCK_METHOD";
132
- LocalOperateCategory[LocalOperateCategory["ADD_USER"] = 16] = "ADD_USER";
133
- LocalOperateCategory[LocalOperateCategory["DELETE_USER"] = 17] = "DELETE_USER";
134
- LocalOperateCategory[LocalOperateCategory["SETTING"] = 32] = "SETTING";
135
- return LocalOperateCategory;
136
- }({});
1
+ export var UserType;
2
+ (function (UserType) {
3
+ UserType[UserType["ADMIN"] = 10] = "ADMIN";
4
+ UserType[UserType["MEMBER"] = 20] = "MEMBER";
5
+ UserType[UserType["UNKNOW"] = 30] = "UNKNOW";
6
+ UserType[UserType["SHARE"] = 40] = "SHARE";
7
+ UserType[UserType["OWNER"] = 50] = "OWNER";
8
+ })(UserType || (UserType = {}));
9
+ export var ModuleType;
10
+ (function (ModuleType) {
11
+ ModuleType[ModuleType["T31"] = 0] = "T31";
12
+ ModuleType[ModuleType["WBRL"] = 1] = "WBRL";
13
+ ModuleType[ModuleType["M9116"] = 2] = "M9116";
14
+ ModuleType[ModuleType["M7258"] = 3] = "M7258";
15
+ ModuleType[ModuleType["T3"] = 4] = "T3";
16
+ })(ModuleType || (ModuleType = {}));
17
+ export var VedioType;
18
+ (function (VedioType) {
19
+ VedioType[VedioType["NONE"] = 0] = "NONE";
20
+ VedioType[VedioType["VEDIO_OR_SNAPSHOT"] = 1] = "VEDIO_OR_SNAPSHOT";
21
+ })(VedioType || (VedioType = {}));
22
+ export var VoiceType;
23
+ (function (VoiceType) {
24
+ VoiceType[VoiceType["ONE_WAY"] = 0] = "ONE_WAY";
25
+ VoiceType[VoiceType["TWO_WAY"] = 1] = "TWO_WAY";
26
+ })(VoiceType || (VoiceType = {}));
27
+ export var VedioStreamType;
28
+ (function (VedioStreamType) {
29
+ VedioStreamType[VedioStreamType["STREAMER"] = 0] = "STREAMER";
30
+ VedioStreamType[VedioStreamType["P2P"] = 1] = "P2P";
31
+ })(VedioStreamType || (VedioStreamType = {}));
32
+ export var CommunicationType;
33
+ (function (CommunicationType) {
34
+ CommunicationType[CommunicationType["WIFI"] = 0] = "WIFI";
35
+ CommunicationType[CommunicationType["WIFI_BLE"] = 1] = "WIFI_BLE";
36
+ CommunicationType[CommunicationType["THREAD"] = 2] = "THREAD";
37
+ CommunicationType[CommunicationType["THREAD_BLE"] = 3] = "THREAD_BLE";
38
+ CommunicationType[CommunicationType["NONE"] = 255] = "NONE";
39
+ })(CommunicationType || (CommunicationType = {}));
40
+ export var RotateType;
41
+ (function (RotateType) {
42
+ RotateType[RotateType["PID"] = 0] = "PID";
43
+ RotateType[RotateType["SEI"] = 1] = "SEI";
44
+ })(RotateType || (RotateType = {}));
45
+ export var ProductCommunicationType;
46
+ (function (ProductCommunicationType) {
47
+ ProductCommunicationType[ProductCommunicationType["WIFI"] = 0] = "WIFI";
48
+ ProductCommunicationType[ProductCommunicationType["CABLE"] = 1] = "CABLE";
49
+ ProductCommunicationType[ProductCommunicationType["GPRS"] = 2] = "GPRS";
50
+ ProductCommunicationType[ProductCommunicationType["NB_IOT"] = 3] = "NB_IOT";
51
+ ProductCommunicationType[ProductCommunicationType["BLUETOOTH"] = 10] = "BLUETOOTH";
52
+ ProductCommunicationType[ProductCommunicationType["BLE_MESH"] = 11] = "BLE_MESH";
53
+ ProductCommunicationType[ProductCommunicationType["ZIGBEE"] = 12] = "ZIGBEE";
54
+ ProductCommunicationType[ProductCommunicationType["INFRARED"] = 13] = "INFRARED";
55
+ ProductCommunicationType[ProductCommunicationType["SUBPIECES"] = 14] = "SUBPIECES";
56
+ ProductCommunicationType[ProductCommunicationType["SIGMESH"] = 15] = "SIGMESH";
57
+ ProductCommunicationType[ProductCommunicationType["MCU"] = 16] = "MCU";
58
+ ProductCommunicationType[ProductCommunicationType["TY_SMESH"] = 17] = "TY_SMESH";
59
+ ProductCommunicationType[ProductCommunicationType["ZWAVE"] = 18] = "ZWAVE";
60
+ ProductCommunicationType[ProductCommunicationType["PL_MESH"] = 19] = "PL_MESH";
61
+ ProductCommunicationType[ProductCommunicationType["CAT1"] = 20] = "CAT1";
62
+ ProductCommunicationType[ProductCommunicationType["BEACON"] = 21] = "BEACON";
63
+ ProductCommunicationType[ProductCommunicationType["CAT4"] = 22] = "CAT4";
64
+ ProductCommunicationType[ProductCommunicationType["CAT10"] = 23] = "CAT10";
65
+ ProductCommunicationType[ProductCommunicationType["LTE_CATM"] = 24] = "LTE_CATM";
66
+ ProductCommunicationType[ProductCommunicationType["THREAD"] = 25] = "THREAD";
67
+ })(ProductCommunicationType || (ProductCommunicationType = {}));
68
+ export var LocalOperateUserType;
69
+ (function (LocalOperateUserType) {
70
+ LocalOperateUserType[LocalOperateUserType["SUPER_ADMIN"] = 0] = "SUPER_ADMIN";
71
+ LocalOperateUserType[LocalOperateUserType["ADMIN"] = 1] = "ADMIN";
72
+ LocalOperateUserType[LocalOperateUserType["SPECIAL_USER"] = 2] = "SPECIAL_USER";
73
+ LocalOperateUserType[LocalOperateUserType["NORMAL_USER"] = 3] = "NORMAL_USER";
74
+ })(LocalOperateUserType || (LocalOperateUserType = {}));
75
+ export var LocalOperateCategory;
76
+ (function (LocalOperateCategory) {
77
+ LocalOperateCategory[LocalOperateCategory["ADD_UNLOCK_METHOD"] = 0] = "ADD_UNLOCK_METHOD";
78
+ LocalOperateCategory[LocalOperateCategory["DELETE_UNLOCK_METHOD"] = 1] = "DELETE_UNLOCK_METHOD";
79
+ LocalOperateCategory[LocalOperateCategory["MODIFY_UNLOCK_METHOD"] = 2] = "MODIFY_UNLOCK_METHOD";
80
+ LocalOperateCategory[LocalOperateCategory["ADD_USER"] = 16] = "ADD_USER";
81
+ LocalOperateCategory[LocalOperateCategory["DELETE_USER"] = 17] = "DELETE_USER";
82
+ LocalOperateCategory[LocalOperateCategory["SETTING"] = 32] = "SETTING";
83
+ })(LocalOperateCategory || (LocalOperateCategory = {}));
package/lib/event.d.ts CHANGED
@@ -1,8 +1,2 @@
1
- /**
2
- * 休眠状态变更事件
3
- */
4
1
  export declare const SLEEP_EVENT = "sleep_event";
5
- /**
6
- * 设备状态变更事件
7
- */
8
2
  export declare const DEVICE_STATUS_CHANGE_EVENT = "device_status_change";
package/lib/event.js CHANGED
@@ -1,9 +1,2 @@
1
- /**
2
- * 休眠状态变更事件
3
- */
4
1
  export const SLEEP_EVENT = "sleep_event";
5
-
6
- /**
7
- * 设备状态变更事件
8
- */
9
- export const DEVICE_STATUS_CHANGE_EVENT = "device_status_change";
2
+ export const DEVICE_STATUS_CHANGE_EVENT = "device_status_change";
package/lib/index.d.ts CHANGED
@@ -13,13 +13,6 @@ export * from "./constant";
13
13
  export * from "./other";
14
14
  export * from "./media";
15
15
  export * from "./linkage";
16
- /**
17
- * 初始化sdk
18
- * @param options 初始化参数
19
- */
20
16
  export declare const init: (options?: LockSDKOption) => Promise<void>;
21
- /**
22
- * 销毁 sdk
23
- */
24
17
  export declare const destroy: () => void;
25
18
  export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, };
package/lib/index.js CHANGED
@@ -1,10 +1,6 @@
1
- import "core-js/modules/esnext.iterator.constructor.js";
2
- import "core-js/modules/esnext.iterator.for-each.js";
3
- import "core-js/modules/esnext.iterator.map.js";
4
- import "core-js/modules/esnext.iterator.reduce.js";
5
1
  import config from "./config";
6
2
  import dpCodes from "./config/dp-code";
7
- import { addEvents, clearState, initState, removeEvents, getCurrentUser, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, getCurrentUserSync, getMediaRotate } from "./state";
3
+ import { addEvents, clearState, initState, removeEvents, getCurrentUser, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, getCurrentUserSync, getMediaRotate, } from "./state";
8
4
  import { getCapabilities } from "./utils";
9
5
  import { getDeviceInfo, getLaunchOptionsSync } from "./utils/device";
10
6
  import { syncUnlockMethod } from "./sync/unlock-mothod";
@@ -20,73 +16,51 @@ export * from "./constant";
20
16
  export * from "./other";
21
17
  export * from "./media";
22
18
  export * from "./linkage";
23
-
24
- /**
25
- * 初始化sdk
26
- * @param options 初始化参数
27
- */
28
- export const init = async options => {
29
- var _options$strictMode, _options$passwordDigi, _options$passwordSupp;
30
- let {
31
- devInfo,
32
- deviceId
33
- } = options || {};
34
- if (!devInfo && !deviceId) {
35
- // 从启动参数中获取设备id
36
- const {
37
- query
38
- } = getLaunchOptionsSync();
39
- deviceId = query.deviceId;
40
- if (!deviceId) {
41
- throw new Error("deviceId is required in lock sdk");
19
+ export const init = async (options) => {
20
+ let { devInfo, deviceId } = options || {};
21
+ if (!devInfo && !deviceId) {
22
+ const { query } = getLaunchOptionsSync();
23
+ deviceId = query.deviceId;
24
+ if (!deviceId) {
25
+ throw new Error("deviceId is required in lock sdk");
26
+ }
42
27
  }
43
- }
44
- if (deviceId && (!devInfo || devInfo.devId !== deviceId)) {
45
- devInfo = await getDeviceInfo(deviceId);
46
- }
47
-
48
- // 处理dp
49
- let dpSchema = {};
50
- const codesById = {};
51
- const idsByCode = {};
52
- if (devInfo.schema) {
53
- dpSchema = devInfo.schema.reduce((acc, cur) => {
54
- acc[cur.code] = cur;
55
- codesById[cur.id] = cur.code;
56
- idsByCode[cur.code] = cur.id;
57
- return acc;
58
- }, {});
59
- } else if (devInfo.dpSchema) {
60
- dpSchema = devInfo.dpSchema;
61
- Object.keys(dpSchema).forEach(key => {
62
- const item = dpSchema[key];
63
- codesById[item.id] = item.code;
64
- idsByCode[item.code] = item.id;
65
- });
66
- }
67
- config.strictMode = (_options$strictMode = options === null || options === void 0 ? void 0 : options.strictMode) !== null && _options$strictMode !== void 0 ? _options$strictMode : true;
68
- config.passwordDigitalBase = (_options$passwordDigi = options === null || options === void 0 ? void 0 : options.passwordDigitalBase) !== null && _options$passwordDigi !== void 0 ? _options$passwordDigi : 10; // 默认十进制
69
- config.passwordSupportZero = (_options$passwordSupp = options === null || options === void 0 ? void 0 : options.passwordSupportZero) !== null && _options$passwordSupp !== void 0 ? _options$passwordSupp : true; // 默认支持0
70
- config.devInfo = devInfo;
71
- config.dpSchema = dpSchema;
72
- config.codesById = codesById;
73
- config.idsByCode = idsByCode;
74
- config.supportBigData = !!dpSchema[dpCodes.synchMethodW];
75
-
76
- // 产品通讯能力
77
- config.communication = getCapabilities(devInfo.capability).map(item => item.id);
78
-
79
- // 初始化数据
80
- await initState();
81
- // 加入事件
82
- addEvents();
28
+ if (deviceId && (!devInfo || devInfo.devId !== deviceId)) {
29
+ devInfo = await getDeviceInfo(deviceId);
30
+ }
31
+ let dpSchema = {};
32
+ const codesById = {};
33
+ const idsByCode = {};
34
+ if (devInfo.schema) {
35
+ dpSchema = devInfo.schema.reduce((acc, cur) => {
36
+ acc[cur.code] = cur;
37
+ codesById[cur.id] = cur.code;
38
+ idsByCode[cur.code] = cur.id;
39
+ return acc;
40
+ }, {});
41
+ }
42
+ else if (devInfo.dpSchema) {
43
+ dpSchema = devInfo.dpSchema;
44
+ Object.keys(dpSchema).forEach((key) => {
45
+ const item = dpSchema[key];
46
+ codesById[item.id] = item.code;
47
+ idsByCode[item.code] = item.id;
48
+ });
49
+ }
50
+ config.strictMode = options?.strictMode ?? true;
51
+ config.passwordDigitalBase = options?.passwordDigitalBase ?? 10;
52
+ config.passwordSupportZero = options?.passwordSupportZero ?? true;
53
+ config.devInfo = devInfo;
54
+ config.dpSchema = dpSchema;
55
+ config.codesById = codesById;
56
+ config.idsByCode = idsByCode;
57
+ config.supportBigData = !!dpSchema[dpCodes.synchMethodW];
58
+ config.communication = getCapabilities(devInfo.capability).map((item) => item.id);
59
+ await initState();
60
+ addEvents();
83
61
  };
84
-
85
- /**
86
- * 销毁 sdk
87
- */
88
62
  export const destroy = () => {
89
- clearState();
90
- removeEvents();
63
+ clearState();
64
+ removeEvents();
91
65
  };
92
- export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange };
66
+ export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, };