@ray-js/lock-sdk 1.2.1-beta.7 → 1.2.1-beta.9
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/lib/api/video.d.ts +5 -0
- package/lib/api/video.js +10 -0
- package/lib/entries/main/exports/misc.d.ts +4 -0
- package/lib/entries/main/exports/misc.js +4 -1
- package/lib/feature/misc/capability.js +15 -13
- package/lib/feature/misc/connect-device.d.ts +3 -0
- package/lib/feature/misc/connect-device.js +73 -64
- package/lib/feature/state/init-state.js +4 -2
- package/package.json +1 -1
package/lib/api/video.d.ts
CHANGED
|
@@ -48,4 +48,9 @@ interface GetDeviceCurrentMeidaConfigResult {
|
|
|
48
48
|
vedioClaritys: number[];
|
|
49
49
|
}
|
|
50
50
|
export declare const getDeviceCurrentMeidaConfig: (devId: string) => Promise<GetDeviceCurrentMeidaConfigResult>;
|
|
51
|
+
interface GetVideoResolutionMarkResult {
|
|
52
|
+
capability: number[];
|
|
53
|
+
cloudCapability: string[];
|
|
54
|
+
}
|
|
55
|
+
export declare const getVideoResolutionMark: (devId: string) => Promise<GetVideoResolutionMarkResult>;
|
|
51
56
|
export {};
|
package/lib/api/video.js
CHANGED
|
@@ -70,3 +70,13 @@ export const getDeviceCurrentMeidaConfig = (devId) => {
|
|
|
70
70
|
},
|
|
71
71
|
});
|
|
72
72
|
};
|
|
73
|
+
export const getVideoResolutionMark = (devId) => {
|
|
74
|
+
return requestApi({
|
|
75
|
+
logName: "getVideoResolutionMark",
|
|
76
|
+
api: `${THING}.m.device.lock.capability.cloud.get`,
|
|
77
|
+
version: "1.0",
|
|
78
|
+
data: {
|
|
79
|
+
devId,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
};
|
|
@@ -16,3 +16,7 @@ export declare function updateDpPeriodTime(dpCode: string, data: UpdateDpPeriodT
|
|
|
16
16
|
export declare function connectDevice(options?: ConnectDeviceOptions): Promise<true>;
|
|
17
17
|
export declare function gotoService(params?: GotoServiceParams): Promise<void>;
|
|
18
18
|
export declare function validatePwdComplexity(password: string): Promise<boolean>;
|
|
19
|
+
export interface AwakeDeviceOptions {
|
|
20
|
+
timeout?: number;
|
|
21
|
+
}
|
|
22
|
+
export declare function awakeDevice(options?: AwakeDeviceOptions): Promise<true>;
|
|
@@ -2,7 +2,7 @@ import { resolveRuntimeFromExportThis } from "../bootstrap/resolve-runtime-from-
|
|
|
2
2
|
import { openSceneForRuntime } from "../../../feature/misc/open-scene";
|
|
3
3
|
import { isSupportBleControlForRuntime } from "../../../feature/misc/ble-control";
|
|
4
4
|
import { getDpPeriodTimeForRuntime, updateDpPeriodTimeForRuntime, } from "../../../feature/misc/dp-period";
|
|
5
|
-
import { connectDeviceForRuntime } from "../../../feature/misc/connect-device";
|
|
5
|
+
import { awakeDeviceForRuntime, connectDeviceForRuntime, } from "../../../feature/misc/connect-device";
|
|
6
6
|
import { validatePwdComplexityForRuntime } from "../../../feature/misc/validate-pwd";
|
|
7
7
|
import { gotoServiceForRuntime, } from "../../../feature/service/goto-service";
|
|
8
8
|
export { parseDpPeriodTime } from "../../../feature/misc/dp-period";
|
|
@@ -28,3 +28,6 @@ export async function gotoService(params) {
|
|
|
28
28
|
export async function validatePwdComplexity(password) {
|
|
29
29
|
return validatePwdComplexityForRuntime(resolveRuntimeFromExportThis(this), password);
|
|
30
30
|
}
|
|
31
|
+
export async function awakeDevice(options) {
|
|
32
|
+
return awakeDeviceForRuntime(resolveRuntimeFromExportThis(this), options);
|
|
33
|
+
}
|
|
@@ -3,6 +3,9 @@ import { CommunicationType, ProductCommunicationType } from "../../constant";
|
|
|
3
3
|
import { checkShowMatterMutilpleShare } from "../../platform/device";
|
|
4
4
|
import { ipc } from "../../platform";
|
|
5
5
|
import { getWithLocalCache } from "../storage/swr-cache";
|
|
6
|
+
import { getVideoResolutionMark } from "../../api/video";
|
|
7
|
+
import dpCodes from "../../config/dp-code";
|
|
8
|
+
import { hasDpForRuntime } from "../dp/has-dp";
|
|
6
9
|
export const hasCapabilityForRuntime = (runtime, capability) => runtime.config.communication.includes(capability);
|
|
7
10
|
export const isBlePureDeviceForRuntime = (rt) => hasCapabilityForRuntime(rt, ProductCommunicationType.BLUETOOTH) &&
|
|
8
11
|
rt.config.communication.length === 1;
|
|
@@ -68,7 +71,7 @@ export const getDeviceAdvancedAbilitiesForRuntime = async (rt) => {
|
|
|
68
71
|
return rt.cache.deviceAdvanceAbilityCache;
|
|
69
72
|
}
|
|
70
73
|
const devId = rt.config.devInfo.devId;
|
|
71
|
-
const [productAbilitiesRes, deviceAdvancedAbilityRes, tttList] = await Promise.allSettled([
|
|
74
|
+
const [productAbilitiesRes, deviceAdvancedAbilityRes, tttList, videoMarkRes] = await Promise.allSettled([
|
|
72
75
|
getWithLocalCache(rt, "productAbilities", () => getProductAbilities(devId, [
|
|
73
76
|
"tyabi4ucx5",
|
|
74
77
|
"tyabis9tpe",
|
|
@@ -76,18 +79,25 @@ export const getDeviceAdvancedAbilitiesForRuntime = async (rt) => {
|
|
|
76
79
|
"tyabipd4hh",
|
|
77
80
|
"tyabin4u5v",
|
|
78
81
|
"visual_door_lock_cloud_store",
|
|
79
|
-
"tyabixkep7",
|
|
80
|
-
"tyabig3wt9",
|
|
81
82
|
])),
|
|
82
83
|
getWithLocalCache(rt, "deviceAdvancedAbility", () => getDeviceAdvancedAbility(devId)),
|
|
83
84
|
ipc.getTTTAbilityKeyList("isSupportedVRMode"),
|
|
85
|
+
hasDpForRuntime(rt, dpCodes.initiativeMessage)
|
|
86
|
+
? getWithLocalCache(rt, "videoResolutionMark", () => getVideoResolutionMark(devId))
|
|
87
|
+
: Promise.resolve({
|
|
88
|
+
capability: [],
|
|
89
|
+
cloudCapability: [],
|
|
90
|
+
}),
|
|
84
91
|
]);
|
|
85
92
|
const productAbilities = productAbilitiesRes.status === "fulfilled" ? productAbilitiesRes.value : [];
|
|
86
93
|
const tttAbList = tttList.status === "fulfilled" ? tttList.value.abilityList : [];
|
|
94
|
+
const videoMark = videoMarkRes.status === "fulfilled"
|
|
95
|
+
? videoMarkRes.value
|
|
96
|
+
: { capability: [], cloudCapability: [] };
|
|
87
97
|
const deviceAdvanceAbilityCache = {
|
|
88
98
|
videoConfig: {
|
|
89
|
-
isLowResolution:
|
|
90
|
-
isHighResolution:
|
|
99
|
+
isLowResolution: videoMark?.cloudCapability?.includes("tyabig3wt9"),
|
|
100
|
+
isHighResolution: videoMark?.cloudCapability?.includes("tyabixkep7"),
|
|
91
101
|
},
|
|
92
102
|
cloudStorage: {
|
|
93
103
|
support: false,
|
|
@@ -129,14 +139,6 @@ export const getDeviceAdvancedAbilitiesForRuntime = async (rt) => {
|
|
|
129
139
|
if (item.isOpen) {
|
|
130
140
|
const data = item.extConfig ? JSON.parse(item.extConfig) : {};
|
|
131
141
|
switch (item.abilityCode) {
|
|
132
|
-
case "tyabixkep7": {
|
|
133
|
-
deviceAdvanceAbilityCache.videoConfig.isHighResolution = true;
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
case "tyabig3wt9": {
|
|
137
|
-
deviceAdvanceAbilityCache.videoConfig.isLowResolution = true;
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
142
|
case "visual_door_lock_cloud_store":
|
|
141
143
|
deviceAdvanceAbilityCache.cloudStorage.support = true;
|
|
142
144
|
break;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
|
|
2
2
|
export declare function connectDeviceForRuntime(rt: LockDeviceRuntime, timeout?: number): Promise<true>;
|
|
3
|
+
export declare const awakeDeviceForRuntime: (runtime: LockDeviceRuntime, options?: {
|
|
4
|
+
timeout?: number;
|
|
5
|
+
}) => Promise<true>;
|
|
@@ -8,70 +8,8 @@ import { getDpValueForRuntime } from "../dp/get-dp-value";
|
|
|
8
8
|
import { getDeviceStatusForRuntime } from "../state/device-status";
|
|
9
9
|
import { isSupportBleControlForRuntime } from "./ble-control";
|
|
10
10
|
import { sdkLog } from "../../utils/sdk-log";
|
|
11
|
+
import { hasDpForRuntime } from "../dp/has-dp";
|
|
11
12
|
const { wirelessAwake } = dpCodes;
|
|
12
|
-
const awakeDevice = async (devId, timeout) => {
|
|
13
|
-
const startedAt = Date.now();
|
|
14
|
-
sdkLog("info", "connectDevice", "awakeStart", {
|
|
15
|
-
devId,
|
|
16
|
-
data: { timeout: timeout || 15000 },
|
|
17
|
-
});
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
const handleChangeDp = (dpCodesArg) => {
|
|
20
|
-
if (dpCodesArg[wirelessAwake] === true) {
|
|
21
|
-
sdkLog("info", "connectDevice", "awakeReportSuccess", {
|
|
22
|
-
devId,
|
|
23
|
-
duration: Date.now() - startedAt,
|
|
24
|
-
});
|
|
25
|
-
resolve(true);
|
|
26
|
-
emitter.off(DPCHANGE, handleChangeDp);
|
|
27
|
-
clearTimeout(timer);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
emitter.on(DPCHANGE, handleChangeDp);
|
|
31
|
-
const timer = setTimeout(() => {
|
|
32
|
-
emitter.off(DPCHANGE, handleChangeDp);
|
|
33
|
-
const error = getError(1002);
|
|
34
|
-
sdkLog("warn", "connectDevice", "awakeTimeout", {
|
|
35
|
-
devId,
|
|
36
|
-
duration: Date.now() - startedAt,
|
|
37
|
-
error,
|
|
38
|
-
});
|
|
39
|
-
reject(error);
|
|
40
|
-
}, timeout || 15000);
|
|
41
|
-
const run = async () => {
|
|
42
|
-
try {
|
|
43
|
-
ipc.wakeUpDoorBell(devId);
|
|
44
|
-
ipc.wakeUpDoorBell(devId);
|
|
45
|
-
ipc.wakeUpDoorBell(devId);
|
|
46
|
-
const connected = await ipc.isConnected(devId);
|
|
47
|
-
if (connected.isConnected) {
|
|
48
|
-
sdkLog("info", "connectDevice", "awakeAlreadyConnected", {
|
|
49
|
-
devId,
|
|
50
|
-
duration: Date.now() - startedAt,
|
|
51
|
-
});
|
|
52
|
-
return resolve(true);
|
|
53
|
-
}
|
|
54
|
-
const connecting = await ipc.isConnecting(devId);
|
|
55
|
-
if (!connecting.isConnecting) {
|
|
56
|
-
sdkLog("info", "connectDevice", "awakeIpcConnectStart", { devId });
|
|
57
|
-
await ipc.connect(devId);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
sdkLog("debug", "connectDevice", "awakeIpcConnecting", { devId });
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
sdkLog("error", "connectDevice", "awakeFail", {
|
|
65
|
-
devId,
|
|
66
|
-
duration: Date.now() - startedAt,
|
|
67
|
-
error,
|
|
68
|
-
});
|
|
69
|
-
reject(error);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
run();
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
13
|
const connectBle = async (devId, timeout) => {
|
|
76
14
|
const startedAt = Date.now();
|
|
77
15
|
sdkLog("info", "connectDevice", "bleConnectStart", { devId });
|
|
@@ -160,7 +98,7 @@ export async function connectDeviceForRuntime(rt, timeout) {
|
|
|
160
98
|
});
|
|
161
99
|
if (deviceStatus.connectEnable && hasWirelessAwakeDp) {
|
|
162
100
|
if (cfg.devInfo.isCloudOnline && !getDpValueForRuntime(rt, wirelessAwake)) {
|
|
163
|
-
const result = await
|
|
101
|
+
const result = await awakeDeviceForRuntime(rt, { timeout });
|
|
164
102
|
sdkLog("info", "connectDevice", "success", {
|
|
165
103
|
devId,
|
|
166
104
|
duration: Date.now() - startedAt,
|
|
@@ -205,3 +143,74 @@ export async function connectDeviceForRuntime(rt, timeout) {
|
|
|
205
143
|
});
|
|
206
144
|
throw error;
|
|
207
145
|
}
|
|
146
|
+
export const awakeDeviceForRuntime = (runtime, options) => {
|
|
147
|
+
const cfg = runtime.config;
|
|
148
|
+
const devId = cfg.devInfo.devId;
|
|
149
|
+
const timeout = options?.timeout || 15000;
|
|
150
|
+
const startedAt = Date.now();
|
|
151
|
+
const hasWirelessAwake = hasDpForRuntime(runtime, wirelessAwake);
|
|
152
|
+
sdkLog("info", "connectDevice", "awakeStart", {
|
|
153
|
+
devId,
|
|
154
|
+
data: { timeout, hasWirelessAwake },
|
|
155
|
+
});
|
|
156
|
+
return new Promise((resolve, reject) => {
|
|
157
|
+
const handleChangeDp = (dpCodesArg) => {
|
|
158
|
+
if (dpCodesArg[wirelessAwake] === true) {
|
|
159
|
+
sdkLog("info", "connectDevice", "awakeReportSuccess", {
|
|
160
|
+
devId,
|
|
161
|
+
duration: Date.now() - startedAt,
|
|
162
|
+
});
|
|
163
|
+
resolve(true);
|
|
164
|
+
emitter.off(DPCHANGE, handleChangeDp);
|
|
165
|
+
clearTimeout(timer);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
hasWirelessAwake && emitter.on(DPCHANGE, handleChangeDp);
|
|
169
|
+
const timer = setTimeout(() => {
|
|
170
|
+
emitter.off(DPCHANGE, handleChangeDp);
|
|
171
|
+
const error = getError(1002);
|
|
172
|
+
sdkLog("warn", "connectDevice", "awakeTimeout", {
|
|
173
|
+
devId,
|
|
174
|
+
duration: Date.now() - startedAt,
|
|
175
|
+
error,
|
|
176
|
+
});
|
|
177
|
+
reject(error);
|
|
178
|
+
}, timeout);
|
|
179
|
+
const run = async () => {
|
|
180
|
+
try {
|
|
181
|
+
ipc.wakeUpDoorBell(devId);
|
|
182
|
+
ipc.wakeUpDoorBell(devId);
|
|
183
|
+
ipc.wakeUpDoorBell(devId);
|
|
184
|
+
const connected = await ipc.isConnected(devId);
|
|
185
|
+
if (connected.isConnected) {
|
|
186
|
+
sdkLog("info", "connectDevice", "awakeAlreadyConnected", {
|
|
187
|
+
devId,
|
|
188
|
+
duration: Date.now() - startedAt,
|
|
189
|
+
});
|
|
190
|
+
return resolve(true);
|
|
191
|
+
}
|
|
192
|
+
const connecting = await ipc.isConnecting(devId);
|
|
193
|
+
if (!connecting.isConnecting) {
|
|
194
|
+
sdkLog("info", "connectDevice", "awakeIpcConnectStart", { devId });
|
|
195
|
+
await ipc.connect(devId);
|
|
196
|
+
if (!hasWirelessAwake) {
|
|
197
|
+
clearTimeout(timer);
|
|
198
|
+
return resolve(true);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
sdkLog("debug", "connectDevice", "awakeIpcConnecting", { devId });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
sdkLog("error", "connectDevice", "awakeFail", {
|
|
207
|
+
devId,
|
|
208
|
+
duration: Date.now() - startedAt,
|
|
209
|
+
error,
|
|
210
|
+
});
|
|
211
|
+
reject(error);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
run();
|
|
215
|
+
});
|
|
216
|
+
};
|
|
@@ -172,8 +172,10 @@ export const initState = async (runtime) => {
|
|
|
172
172
|
});
|
|
173
173
|
setTimeout(() => {
|
|
174
174
|
sdkLog("debug", "initState", "scheduledSyncUnlock", { devId });
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
if (getDeviceStatusForRuntime(runtime).type === "online") {
|
|
176
|
+
syncT0(runtime);
|
|
177
|
+
autoSyncUnlockMethod(runtime);
|
|
178
|
+
}
|
|
177
179
|
}, 2000);
|
|
178
180
|
setTimeout(() => {
|
|
179
181
|
sdkLog("debug", "initState", "scheduledSyncTempAndUsers", { devId });
|