@ray-js/lock-sdk 1.0.0-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 (95) hide show
  1. package/lib/api/index.d.ts +5 -0
  2. package/lib/api/index.js +18 -0
  3. package/lib/api/linkage.d.ts +161 -0
  4. package/lib/api/linkage.js +74 -0
  5. package/lib/api/lock.d.ts +195 -0
  6. package/lib/api/lock.js +129 -0
  7. package/lib/api/log.d.ts +166 -0
  8. package/lib/api/log.js +44 -0
  9. package/lib/api/setting.d.ts +14 -0
  10. package/lib/api/setting.js +36 -0
  11. package/lib/api/temp.d.ts +211 -0
  12. package/lib/api/temp.js +130 -0
  13. package/lib/api/user.d.ts +154 -0
  14. package/lib/api/user.js +59 -0
  15. package/lib/api/video.d.ts +9 -0
  16. package/lib/api/video.js +17 -0
  17. package/lib/config/dp-code/index.d.ts +175 -0
  18. package/lib/config/dp-code/index.js +224 -0
  19. package/lib/config/dp-map/common.d.ts +102 -0
  20. package/lib/config/dp-map/common.js +120 -0
  21. package/lib/config/dp-map/normal.d.ts +6 -0
  22. package/lib/config/dp-map/normal.js +51 -0
  23. package/lib/config/dp-map/open.d.ts +21 -0
  24. package/lib/config/dp-map/open.js +62 -0
  25. package/lib/config/dp-map/unlock-method-big.d.ts +559 -0
  26. package/lib/config/dp-map/unlock-method-big.js +237 -0
  27. package/lib/config/dp-map/unlock-method.d.ts +551 -0
  28. package/lib/config/dp-map/unlock-method.js +231 -0
  29. package/lib/config/index.d.ts +46 -0
  30. package/lib/config/index.js +56 -0
  31. package/lib/constant.d.ts +101 -0
  32. package/lib/constant.js +136 -0
  33. package/lib/dp-interface.d.ts +7 -0
  34. package/lib/dp-interface.js +1 -0
  35. package/lib/event.d.ts +8 -0
  36. package/lib/event.js +9 -0
  37. package/lib/index.d.ts +25 -0
  38. package/lib/index.js +92 -0
  39. package/lib/interface.d.ts +807 -0
  40. package/lib/interface.js +1 -0
  41. package/lib/linkage.d.ts +26 -0
  42. package/lib/linkage.js +175 -0
  43. package/lib/log.d.ts +91 -0
  44. package/lib/log.js +314 -0
  45. package/lib/media.d.ts +43 -0
  46. package/lib/media.js +80 -0
  47. package/lib/open.d.ts +48 -0
  48. package/lib/open.js +247 -0
  49. package/lib/other.d.ts +36 -0
  50. package/lib/other.js +178 -0
  51. package/lib/parse/index.d.ts +6 -0
  52. package/lib/parse/index.js +22 -0
  53. package/lib/signal.d.ts +26 -0
  54. package/lib/signal.js +38 -0
  55. package/lib/sleep.d.ts +61 -0
  56. package/lib/sleep.js +121 -0
  57. package/lib/state.d.ts +54 -0
  58. package/lib/state.js +429 -0
  59. package/lib/sync/remote-serect-key.d.ts +5 -0
  60. package/lib/sync/remote-serect-key.js +60 -0
  61. package/lib/sync/t0.d.ts +5 -0
  62. package/lib/sync/t0.js +33 -0
  63. package/lib/sync/temp.d.ts +7 -0
  64. package/lib/sync/temp.js +88 -0
  65. package/lib/sync/unlock-mothod.d.ts +5 -0
  66. package/lib/sync/unlock-mothod.js +54 -0
  67. package/lib/temporary.d.ts +226 -0
  68. package/lib/temporary.js +637 -0
  69. package/lib/unlock-method.d.ts +269 -0
  70. package/lib/unlock-method.js +723 -0
  71. package/lib/user.d.ts +108 -0
  72. package/lib/user.js +361 -0
  73. package/lib/utils/base64-to-hex.d.ts +1 -0
  74. package/lib/utils/base64-to-hex.js +12 -0
  75. package/lib/utils/byte.d.ts +19 -0
  76. package/lib/utils/byte.js +74 -0
  77. package/lib/utils/constant.d.ts +11 -0
  78. package/lib/utils/constant.js +17 -0
  79. package/lib/utils/device.d.ts +207 -0
  80. package/lib/utils/device.js +353 -0
  81. package/lib/utils/errors.d.ts +2 -0
  82. package/lib/utils/errors.js +125 -0
  83. package/lib/utils/event.d.ts +23 -0
  84. package/lib/utils/event.js +144 -0
  85. package/lib/utils/hex-to-base64.d.ts +1 -0
  86. package/lib/utils/hex-to-base64.js +8 -0
  87. package/lib/utils/hex-to-bytes.d.ts +6 -0
  88. package/lib/utils/hex-to-bytes.js +16 -0
  89. package/lib/utils/index.d.ts +169 -0
  90. package/lib/utils/index.js +419 -0
  91. package/lib/utils/log.d.ts +5 -0
  92. package/lib/utils/log.js +78 -0
  93. package/lib/utils/publishDps.d.ts +11 -0
  94. package/lib/utils/publishDps.js +91 -0
  95. package/package.json +37 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 获取剩余通知次数
3
+ * @returns {Promise<{message: number, phone: number}>}
4
+ */
5
+ export declare const getRemainingInfo: () => Promise<{
6
+ message: number;
7
+ phone: number;
8
+ }>;
9
+ /**
10
+ * 获取门铃通知服务信息
11
+ * @returns {Promise<boolean>}
12
+ */
13
+ export declare const getDoorbellService: () => Promise<import("./api/linkage").LinkageRule | undefined>;
14
+ /**
15
+ * 启用门铃通知服务
16
+ * 注意: 首次开通时,会先进入创建动作的页面,创建完成后,会自动启用门铃通知服务
17
+ */
18
+ export declare const enableDoorbellService: () => Promise<void>;
19
+ /**
20
+ * 禁用门铃通知服务
21
+ */
22
+ export declare const disableDoorbellService: () => Promise<never>;
23
+ /**
24
+ * 去配置门铃通知服务
25
+ */
26
+ export declare const toSetDoorbellService: () => Promise<void>;
package/lib/linkage.js ADDED
@@ -0,0 +1,175 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.find.js";
3
+ import "core-js/modules/esnext.iterator.map.js";
4
+ import { disableLinkage, enableLinkage, getLinkageList, getRemainingMessage, getRemainingPhone, saveLinkage } from "./api/linkage";
5
+ import config from "./config";
6
+ import { getHomeInfo } from "./utils";
7
+ import { createAction, editAction } from "./utils/device";
8
+ import { getError } from "./utils/errors";
9
+ const DOORBELL_RING_TYPE = "doorbell_ring";
10
+ const TARGET_KEY = "appPushTrigger"; // 用于从筛选出的配置对象中 筛选出需要的规则
11
+ const ACTION_TYPE = "kafkaSend"; // 新增的action类型
12
+ const MOBILE_TYPE = "mobileVoiceSend"; // actions对象的actionExecutor属性的类型
13
+ const MESSAGE_TYPE = "smsSend"; // actions对象的actionExecutor属性的类型
14
+
15
+ /**
16
+ * 获取剩余通知次数
17
+ * @returns {Promise<{message: number, phone: number}>}
18
+ */
19
+ export const getRemainingInfo = async () => {
20
+ const [message, phone] = await Promise.all([getRemainingMessage(), getRemainingPhone()]);
21
+ return {
22
+ message,
23
+ phone
24
+ };
25
+ };
26
+
27
+ /**
28
+ * 获取门铃通知服务信息
29
+ * @returns {Promise<boolean>}
30
+ */
31
+ export const getDoorbellService = async () => {
32
+ const list = await getLinkageList(config.devInfo.devId);
33
+ return list.find(item => item.code === DOORBELL_RING_TYPE && item.ruleId);
34
+ };
35
+ const createDoorbellService = async () => {
36
+ const actions = await createAction({
37
+ createType: "auto",
38
+ smartType: "remind"
39
+ });
40
+ console.log("actions", actions);
41
+ await saveDoorbellService(actions);
42
+ };
43
+ const saveDoorbellService = async actions => {
44
+ const homeInfo = await getHomeInfo();
45
+ // 保存配置
46
+ saveLinkage({
47
+ devId: config.devInfo.devId,
48
+ ownerId: homeInfo.homeId,
49
+ name: "",
50
+ enabled: true,
51
+ extraInfo: {},
52
+ bizType: DOORBELL_RING_TYPE,
53
+ logicRuleList: [{
54
+ name: "",
55
+ // 规则名称
56
+ matchType: 2,
57
+ // MatchType枚举,1:任意条件触发,2:全部条件满足触发,3:通过expr来判断整个条件的匹配情况
58
+ enabled: true,
59
+ // 规则启用/禁用
60
+ scenarioRule: false,
61
+ // 是否在场景列表中展示
62
+ preConditions: [],
63
+ coverIcon: "",
64
+ displayColor: "",
65
+ background: "",
66
+ conditions: [{
67
+ entityType: 23,
68
+ // entityType=23,表示kafka 消息触发类型
69
+ entityId: config.devInfo.devId,
70
+ // 可以是设备ID,或者产品id等,根据实际的业务需求来
71
+ entitySubIds: "",
72
+ // 无 根据实际的需求来 可以是dpIds
73
+ iconUrl: "",
74
+ // 图片
75
+ expr: [],
76
+ // 为空 传递JSONArray
77
+ extraInfo: {
78
+ businessType: DOORBELL_RING_TYPE // 门铃呼叫的43协议
79
+ }
80
+ }],
81
+ actions: actions.map(item => {
82
+ // 电话提醒处理
83
+ if ((item === null || item === void 0 ? void 0 : item.actionExecutor) === MOBILE_TYPE) {
84
+ const executorProperty = {
85
+ topic: 1,
86
+ customParameters: {
87
+ type: 1
88
+ }
89
+ };
90
+ return {
91
+ actionExecutor: ACTION_TYPE,
92
+ entityName: "notify_phone",
93
+ // 根据实际的业务来,作为面板展示使用
94
+ extraProperty: executorProperty,
95
+ executorProperty
96
+ };
97
+ }
98
+ // 短信提醒处理
99
+ if ((item === null || item === void 0 ? void 0 : item.actionExecutor) === MESSAGE_TYPE) {
100
+ const executorProperty = {
101
+ topic: 2,
102
+ customParameters: {
103
+ type: 2
104
+ }
105
+ };
106
+ return {
107
+ actionExecutor: ACTION_TYPE,
108
+ entityName: "notify_message",
109
+ // 根据实际的业务来,作为面板展示使用
110
+ extraProperty: executorProperty,
111
+ executorProperty
112
+ };
113
+ }
114
+ return item;
115
+ })
116
+ }]
117
+ });
118
+ };
119
+
120
+ /**
121
+ * 启用门铃通知服务
122
+ * 注意: 首次开通时,会先进入创建动作的页面,创建完成后,会自动启用门铃通知服务
123
+ */
124
+ export const enableDoorbellService = async () => {
125
+ const service = await getDoorbellService();
126
+ if (service && service.ruleId) {
127
+ await enableLinkage(service.ruleId);
128
+ } else {
129
+ await createDoorbellService();
130
+ }
131
+ };
132
+
133
+ /**
134
+ * 禁用门铃通知服务
135
+ */
136
+ export const disableDoorbellService = async () => {
137
+ const service = await getDoorbellService();
138
+ if (service && service.ruleId) {
139
+ await disableLinkage(service.ruleId);
140
+ }
141
+ throw getError(1059);
142
+ };
143
+
144
+ /**
145
+ * 去配置门铃通知服务
146
+ */
147
+ export const toSetDoorbellService = async () => {
148
+ const service = await getDoorbellService();
149
+ if (service && service.ruleId && service.ruleVO) {
150
+ const findIndex = service.ruleVO.actions.findIndex(item => item.actionExecutor === TARGET_KEY || item.actionExecutor === ACTION_TYPE);
151
+ // 去编辑
152
+ const actions = await editAction({
153
+ editIndex: findIndex > -1 ? findIndex : 0,
154
+ smartType: "auto",
155
+ actionArray: service.ruleVO.actions.map(item => {
156
+ if (item.actionExecutor === ACTION_TYPE) {
157
+ const {
158
+ customParameters: {
159
+ type
160
+ }
161
+ } = item.executorProperty;
162
+ const actionType = type === 1 ? MOBILE_TYPE : MESSAGE_TYPE;
163
+ // eslint-disable-next-line no-param-reassign
164
+ item.actionExecutor = actionType;
165
+ }
166
+ return item;
167
+ })
168
+ });
169
+ console.log("actions", actions);
170
+ await saveDoorbellService(actions);
171
+ } else {
172
+ // 去创建
173
+ await createDoorbellService();
174
+ }
175
+ };
package/lib/log.d.ts ADDED
@@ -0,0 +1,91 @@
1
+ import { AlbumMessage, LogData, UnlockMethodType } from "./interface";
2
+ /**
3
+ * 开锁 DP 映射开锁类型
4
+ */
5
+ export declare const unlockDp2Type: Record<string, UnlockMethodType>;
6
+ /**
7
+ * 获取最近2条记录
8
+ */
9
+ export declare const getLatestLogs: () => Promise<{
10
+ data: LogData[];
11
+ unreadCount: number;
12
+ }>;
13
+ /**
14
+ * 注册通知可刷新日志事件
15
+ * @param cb
16
+ */
17
+ export declare const onLogsRefresh: (cb: () => void) => void;
18
+ /**
19
+ * 注销通知可刷新日志事件
20
+ * @param cb
21
+ */
22
+ export declare const offLogsRefresh: (cb: () => void) => void;
23
+ interface GetLogsParams {
24
+ /**
25
+ * 页码,默认 1
26
+ */
27
+ page?: number;
28
+ /**
29
+ * 每页数量,默认为 50
30
+ */
31
+ pageSize?: number;
32
+ }
33
+ export declare const openDps: string[];
34
+ /**
35
+ * 获取日志记录列表
36
+ * @param {GetLogsParams} params
37
+ */
38
+ export declare const getLogs: (params?: GetLogsParams) => Promise<{
39
+ list: LogData[];
40
+ hasMore: boolean;
41
+ total: number;
42
+ }>;
43
+ interface GetAlarmsParams {
44
+ /**
45
+ * 页码,默认 1
46
+ */
47
+ page?: number;
48
+ /**
49
+ * 页码,默认 50
50
+ */
51
+ pageSize?: number;
52
+ }
53
+ /**
54
+ * 获取告警列表
55
+ * @param {GetAlarmsParams} params
56
+ */
57
+ export declare const getAlarms: (params?: GetAlarmsParams) => Promise<{
58
+ list: LogData[];
59
+ hasMore: boolean;
60
+ total: number;
61
+ }>;
62
+ interface GetAlbumsParams {
63
+ /**
64
+ * 页码,默认 1
65
+ */
66
+ page?: number;
67
+ /**
68
+ * 每页数量,默认为 20
69
+ */
70
+ pageSize?: number;
71
+ /**
72
+ * 开始时间,单位为毫秒
73
+ */
74
+ startTime?: number;
75
+ /**
76
+ * 结束时间,单位为毫秒
77
+ */
78
+ endTime?: number;
79
+ }
80
+ /**
81
+ * 获取相册日志
82
+ * 仅支持视对讲设备
83
+ */
84
+ export declare const getAlbums: (params?: GetAlbumsParams) => Promise<{
85
+ hasMore: boolean;
86
+ list: AlbumMessage[];
87
+ allAitypes: number[];
88
+ types: number[];
89
+ langMap: string[];
90
+ }>;
91
+ export {};
package/lib/log.js ADDED
@@ -0,0 +1,314 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.map.js";
3
+ import "core-js/modules/esnext.iterator.some.js";
4
+ import { getAlarmList, getAlbumMessages, getLatest2Log, getRecordList } from "./api/log";
5
+ import config from "./config";
6
+ import dpCodes from "./config/dp-code";
7
+ import { getCurrentUser } from "./state";
8
+ import base64ToHex from "./utils/base64-to-hex";
9
+ import { LOGCHANGE } from "./utils/constant";
10
+ import emitter from "./utils/event";
11
+ import { handleLocalOperation } from "./utils/log";
12
+
13
+ /**
14
+ * 开锁 DP 映射开锁类型
15
+ */
16
+ export const unlockDp2Type = {
17
+ [dpCodes.unlockFingerprint]: "finger",
18
+ [dpCodes.unlockPassword]: "password",
19
+ [dpCodes.unlockCard]: "card",
20
+ [dpCodes.unlockFace]: "face",
21
+ [dpCodes.unlockFingerVein]: "fingerVein",
22
+ [dpCodes.unlockHand]: "hand",
23
+ [dpCodes.unlockEye]: "eye"
24
+ };
25
+
26
+ /**
27
+ * 获取最近2条记录
28
+ */
29
+ export const getLatestLogs = async () => {
30
+ const data = await getLatest2Log(config.devInfo.devId);
31
+ // TODO 处理统一日志格式
32
+ if (data.operateRecordVOList && data.operateRecordVOList.length) {
33
+ const list = data.operateRecordVOList.map(item => {
34
+ var _item$unionUnlockInfo, _item$unlockNameRoset;
35
+ let type = item.logCategory;
36
+ if (type === "operation" && item.logType === "dev_bind") {
37
+ type = "dev_bind";
38
+ }
39
+ const dpCode = config.codesById[item.dpId];
40
+ const dpSchema = config.dpSchema[dpCode];
41
+ let itemData = item.data || "";
42
+ if ((dpSchema === null || dpSchema === void 0 ? void 0 : dpSchema.type) === "raw") {
43
+ itemData = base64ToHex(item.data);
44
+ }
45
+ if (typeof itemData === "string" && itemData.includes("[")) {
46
+ try {
47
+ itemData = JSON.parse(itemData)[0];
48
+ } catch {
49
+ //
50
+ }
51
+ }
52
+ return {
53
+ type,
54
+ logId: item.logId,
55
+ dpId: item.dpId,
56
+ dpCode,
57
+ data: itemData,
58
+ userId: item.userId,
59
+ userName: item.userName,
60
+ unlockName: item.unlockName,
61
+ mediaInfo: item.mediaInfoList,
62
+ unionUnlockInfo: (_item$unionUnlockInfo = item.unionUnlockInfo) === null || _item$unionUnlockInfo === void 0 ? void 0 : _item$unionUnlockInfo.map(item1 => {
63
+ return {
64
+ userId: item1.userId,
65
+ userName: item1.userName,
66
+ unlockName: item.unlockName,
67
+ sn: item1.sn,
68
+ type: unlockDp2Type[item1.opMode]
69
+ };
70
+ }),
71
+ closeValue: (_item$unlockNameRoset = item.unlockNameRosettaKey) === null || _item$unlockNameRoset === void 0 ? void 0 : _item$unlockNameRoset.replace("HISTORY_LOCK_", ""),
72
+ time: item.time,
73
+ currentUser: !!item.currentUser,
74
+ bindable: item.memberBindableFlag
75
+ };
76
+ });
77
+ return {
78
+ data: list,
79
+ unreadCount: data.unReadCount
80
+ };
81
+ }
82
+ return {
83
+ data: [],
84
+ unreadCount: 0
85
+ };
86
+ };
87
+
88
+ /**
89
+ * 注册通知可刷新日志事件
90
+ * @param cb
91
+ */
92
+ export const onLogsRefresh = cb => {
93
+ emitter.on(LOGCHANGE, cb);
94
+ };
95
+
96
+ /**
97
+ * 注销通知可刷新日志事件
98
+ * @param cb
99
+ */
100
+ export const offLogsRefresh = cb => {
101
+ emitter.off(LOGCHANGE, cb);
102
+ };
103
+ // 开门记录dpID合集
104
+ export const openDps = [dpCodes.openInside, dpCodes.lockLocalRecord, dpCodes.unlockPassword, dpCodes.lockRecord, dpCodes.unlockFingerprint, dpCodes.unlockCard, dpCodes.unlockFace, dpCodes.unlockHand, dpCodes.unlockFingerVein, dpCodes.unlockEye, dpCodes.unlockTemporary, dpCodes.unlockDoubleKit, dpCodes.unlockKey, dpCodes.unlockPhoneRemote, dpCodes.unlockVoiceRemote, dpCodes.unlockDoubleKitW, dpCodes.unlockBle, dpCodes.unlockOfflinePd, dpCodes.unlockDynamic
105
+ // dpCodes.unlockOfflineClear,
106
+ // dpCodes.unlockOfflineClearSingle,
107
+ ];
108
+
109
+ /**
110
+ * 0-未定义xx关锁
111
+ * 1-手机远程关锁
112
+ * 2-语音远程关锁
113
+ * 3-地理围栏关锁
114
+ * 4-app长按关锁
115
+ * 5-配件关锁
116
+ * 6-自动落锁
117
+ * 7-本地手动落锁
118
+ */
119
+ const closeTypes = ["UNDEFINED", "APP_REMOTE", "VOICE_REMOTE", "GEO_FENCE", "APP", "FITTINGS", "AUTO", "LOCAL_MANUAL"];
120
+
121
+ /**
122
+ * 获取日志记录列表
123
+ * @param {GetLogsParams} params
124
+ */
125
+ export const getLogs = async params => {
126
+ const {
127
+ page = 1,
128
+ pageSize = 50
129
+ } = params || {};
130
+ const currentUser = await getCurrentUser();
131
+ const data = await getRecordList({
132
+ devId: config.devInfo.devId,
133
+ dpIds: openDps.reduce((res, item) => {
134
+ if (config.idsByCode[item]) {
135
+ res.push(config.idsByCode[item]);
136
+ }
137
+ return res;
138
+ }, []),
139
+ offset: (page - 1) * pageSize,
140
+ limit: pageSize
141
+ });
142
+
143
+ // 封装数据
144
+ if (data.datas.length) {
145
+ const result = data.datas.map(record => {
146
+ var _record$unionUnlockIn;
147
+ let closeValue = undefined;
148
+ let dpValue = record.dpValue;
149
+ const dpCode = config.codesById[record.dpId];
150
+ let type = dpCode === dpCodes.lockRecord ? "close_record" : "unlock_record";
151
+ const dpSchema = config.dpSchema[dpCode];
152
+ if (dpSchema.type === "raw") {
153
+ dpValue = base64ToHex(dpValue);
154
+ }
155
+ if (type === "close_record") {
156
+ const closeType = parseInt(dpValue.slice(0, 2), 16);
157
+ closeValue = closeTypes[closeType] || closeTypes[0];
158
+ }
159
+
160
+ // 设备本地操作记录处理
161
+ if (dpCode === dpCodes.lockLocalRecord) {
162
+ type = "local_operation";
163
+ }
164
+ return {
165
+ type,
166
+ logId: record.historyId.toString(),
167
+ userId: record.userId,
168
+ dpId: record.dpId,
169
+ data: dpValue,
170
+ dpCode,
171
+ userName: record.userName,
172
+ unlockName: record.unlockName,
173
+ mediaInfo: record.mediaInfoList,
174
+ unionUnlockInfo: (_record$unionUnlockIn = record.unionUnlockInfo) === null || _record$unionUnlockIn === void 0 ? void 0 : _record$unionUnlockIn.map(item => ({
175
+ userId: item.userId,
176
+ userName: item.userName,
177
+ unlockName: item.unlockName,
178
+ sn: item.sn,
179
+ type: unlockDp2Type[item.opMode]
180
+ })),
181
+ closeValue,
182
+ time: record.gmtCreate,
183
+ currentUser: +record.userId === +currentUser.userId,
184
+ bindable: record.memberBindableFlag === 1,
185
+ unlockMethod: type === "unlock_record" ? unlockDp2Type[dpCode] : undefined,
186
+ localRecord: handleLocalOperation(record.localOperateRecordInfo)
187
+ };
188
+ });
189
+ return {
190
+ list: result,
191
+ hasMore: data.hasNext,
192
+ total: data.totalCount
193
+ };
194
+ }
195
+ return {
196
+ list: [],
197
+ hasMore: false,
198
+ total: 0
199
+ };
200
+ };
201
+ const alarmDps = [dpCodes.doorbell, dpCodes.familyCall, dpCodes.alarmReminder, dpCodes.alarmLock, dpCodes.unlockOfflineClear, dpCodes.unlockOfflineClearSingle, dpCodes.hijack];
202
+ /**
203
+ * 获取告警列表
204
+ * @param {GetAlarmsParams} params
205
+ */
206
+ export const getAlarms = async params => {
207
+ const {
208
+ page = 1,
209
+ pageSize = 50
210
+ } = params || {};
211
+ const currentUser = await getCurrentUser();
212
+ const data = await getAlarmList({
213
+ devId: config.devInfo.devId,
214
+ dpIds: alarmDps.reduce((res, item) => {
215
+ if (config.idsByCode[item]) {
216
+ res.push(config.idsByCode[item]);
217
+ }
218
+ return res;
219
+ }, []),
220
+ offset: (page - 1) * pageSize,
221
+ limit: pageSize
222
+ });
223
+ // 封装数据
224
+ if (data.datas.length) {
225
+ const result = data.datas.map(record => {
226
+ var _record$dps;
227
+ let dpId = record.dpId;
228
+ let dpValue = record.dpValue;
229
+ let dpCode = config.codesById[dpId];
230
+ const dpSchema = config.dpSchema[dpCode];
231
+ if (dpSchema.type === "raw") {
232
+ dpValue = base64ToHex(dpValue);
233
+ }
234
+ // 处理劫持告警情况
235
+ const isHijack = (_record$dps = record.dps) === null || _record$dps === void 0 ? void 0 : _record$dps.some(item => Object.keys(item)[0] === "98");
236
+ return {
237
+ type: "alarm_record",
238
+ logId: record.historyId.toString(),
239
+ userId: record.userId,
240
+ dpId: record.dpId,
241
+ data: dpValue,
242
+ dpCode,
243
+ userName: record.userName,
244
+ unlockName: record.unlockName,
245
+ mediaInfo: record.mediaInfoList,
246
+ time: record.gmtCreate,
247
+ currentUser: +record.userId === +currentUser.userId,
248
+ bindable: false,
249
+ isHijack
250
+ };
251
+ });
252
+ return {
253
+ list: result,
254
+ hasMore: data.hasNext,
255
+ total: data.totalCount
256
+ };
257
+ }
258
+ return {
259
+ list: [],
260
+ hasMore: false,
261
+ total: 0
262
+ };
263
+ };
264
+ /**
265
+ * 获取相册日志
266
+ * 仅支持视对讲设备
267
+ */
268
+ export const getAlbums = async params => {
269
+ const now = Date.now();
270
+ // 一年前
271
+
272
+ const {
273
+ page = 1,
274
+ pageSize = 20,
275
+ startTime = now - 365 * 24 * 60 * 60 * 1000,
276
+ endTime = now
277
+ } = params || {};
278
+ const data = await getAlbumMessages({
279
+ devId: config.devInfo.devId,
280
+ limit: pageSize,
281
+ offset: (page - 1) * pageSize,
282
+ safeMode: false,
283
+ picInclude: true,
284
+ startTime,
285
+ endTime
286
+ });
287
+ // 格式化数据
288
+ return {
289
+ hasMore: data.hasNext,
290
+ list: data.albumList.map(item => ({
291
+ id: item.fileId,
292
+ mediaPath: item.mediaPath,
293
+ fileKey: item.fileKey,
294
+ fileUrl: item.fileUrl,
295
+ mediaBucket: item.mediaBucket,
296
+ mediaKey: item.mediaKey,
297
+ aiTypes: item.aiTypes,
298
+ describe: item.describe,
299
+ aiInfos: item.aiDetectResults.map(x => ({
300
+ id: x.bizId,
301
+ type: x.aiType,
302
+ name: x.eventTypeDesc,
303
+ desc: x.desc,
304
+ happenTime: x.happenTime,
305
+ isCorrected: x.missStep
306
+ })),
307
+ type: item.eventType,
308
+ createTime: item.uploadMilTime
309
+ })),
310
+ allAitypes: data.allAitypes,
311
+ types: data.eventTypes,
312
+ langMap: data.eventLangMap
313
+ };
314
+ };
package/lib/media.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * 多媒体相关接口
3
+ */
4
+ /**
5
+ * 获取视频的实际播放地址参数
6
+ */
7
+ interface GetMediaUrlParams {
8
+ /**
9
+ * 媒体路径
10
+ */
11
+ mediaPath: string;
12
+ /**
13
+ * 媒体桶
14
+ */
15
+ mediaBucket: string;
16
+ }
17
+ interface MediaUrlResult {
18
+ mediaUrl: string;
19
+ }
20
+ /**
21
+ * 获取视频的实际播放地址
22
+ * @param params
23
+ * @returns
24
+ */
25
+ export declare const getMediaUrl: (params: GetMediaUrlParams) => Promise<MediaUrlResult>;
26
+ /**
27
+ * 跳转到本地相册页面
28
+ */
29
+ export declare const goToLocalAlbum: (params?: {
30
+ theme?: "dark" | "light";
31
+ }) => Promise<unknown>;
32
+ /**
33
+ * 跳转到回放页面
34
+ * @param params { theme?: "dark" | "light" }
35
+ * @returns Promise<boolean>
36
+ */
37
+ export declare const goToPlayback: (params?: {
38
+ theme?: "dark" | "light";
39
+ }) => Promise<unknown>;
40
+ export declare const openCameraSettings: (params?: {
41
+ theme?: "dark" | "light";
42
+ }) => Promise<unknown>;
43
+ export {};