@ray-js/lock-sdk 1.2.1-beta.8 → 1.2.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.
- package/lib/entries/main/exports/misc.d.ts +4 -0
- package/lib/entries/main/exports/misc.js +4 -1
- package/lib/feature/misc/connect-device.d.ts +3 -0
- package/lib/feature/misc/connect-device.js +99 -67
- package/lib/platform/device.d.ts +1 -0
- package/lib/platform/device.js +11 -2
- package/lib/platform/ipc.d.ts +1 -0
- package/lib/platform/ipc.js +6 -0
- package/package.json +1 -1
|
@@ -20,3 +20,7 @@ export interface AwakeDeviceOptions {
|
|
|
20
20
|
timeout?: number;
|
|
21
21
|
}
|
|
22
22
|
export declare function awakeDevice(options?: AwakeDeviceOptions): Promise<true>;
|
|
23
|
+
interface DisconnectDeviceOptions {
|
|
24
|
+
disconnetBle?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare function disconnectDevice(options?: DisconnectDeviceOptions): Promise<void>;
|
|
@@ -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 { awakeDeviceForRuntime, connectDeviceForRuntime, } from "../../../feature/misc/connect-device";
|
|
5
|
+
import { awakeDeviceForRuntime, connectDeviceForRuntime, disconnectDeviceForRuntime, } 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";
|
|
@@ -31,3 +31,6 @@ export async function validatePwdComplexity(password) {
|
|
|
31
31
|
export async function awakeDevice(options) {
|
|
32
32
|
return awakeDeviceForRuntime(resolveRuntimeFromExportThis(this), options);
|
|
33
33
|
}
|
|
34
|
+
export async function disconnectDevice(options) {
|
|
35
|
+
return disconnectDeviceForRuntime(resolveRuntimeFromExportThis(this), options);
|
|
36
|
+
}
|
|
@@ -3,3 +3,6 @@ export declare function connectDeviceForRuntime(rt: LockDeviceRuntime, timeout?:
|
|
|
3
3
|
export declare const awakeDeviceForRuntime: (runtime: LockDeviceRuntime, options?: {
|
|
4
4
|
timeout?: number;
|
|
5
5
|
}) => Promise<true>;
|
|
6
|
+
export declare const disconnectDeviceForRuntime: (rt: LockDeviceRuntime, options?: {
|
|
7
|
+
disconnetBle?: boolean;
|
|
8
|
+
}) => Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import dpCodes from "../../config/dp-code";
|
|
2
|
-
import { connectBLEDevice, getBLEOnlineState, onBleChange, onOnlineChange, offBleChange, offOnlineChange, yuChannelSyncSingleSync, } from "../../platform/device";
|
|
2
|
+
import { connectBLEDevice, getBLEOnlineState, onBleChange, onOnlineChange, offBleChange, offOnlineChange, yuChannelSyncSingleSync, disconnectBLEDevice, } from "../../platform/device";
|
|
3
3
|
import { DPCHANGE } from "../../utils/constant";
|
|
4
4
|
import emitter from "../../utils/event";
|
|
5
5
|
import { getError } from "../../utils/errors";
|
|
@@ -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 });
|
|
@@ -147,7 +85,7 @@ export async function connectDeviceForRuntime(rt, timeout) {
|
|
|
147
85
|
const cfg = rt.config;
|
|
148
86
|
const devId = cfg.devInfo.devId;
|
|
149
87
|
const deviceStatus = getDeviceStatusForRuntime(rt);
|
|
150
|
-
const hasWirelessAwakeDp =
|
|
88
|
+
const hasWirelessAwakeDp = hasDpForRuntime(rt, wirelessAwake) && !cfg.notSupportWake;
|
|
151
89
|
const startedAt = Date.now();
|
|
152
90
|
sdkLog("info", "connectDevice", "start", {
|
|
153
91
|
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,
|
|
@@ -208,5 +146,99 @@ export async function connectDeviceForRuntime(rt, timeout) {
|
|
|
208
146
|
export const awakeDeviceForRuntime = (runtime, options) => {
|
|
209
147
|
const cfg = runtime.config;
|
|
210
148
|
const devId = cfg.devInfo.devId;
|
|
211
|
-
|
|
149
|
+
const timeout = options?.timeout || 15000;
|
|
150
|
+
const startedAt = Date.now();
|
|
151
|
+
const hasWirelessAwake = hasDpForRuntime(runtime, wirelessAwake) && !cfg.notSupportWake;
|
|
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
|
+
clearTimeout(timer);
|
|
191
|
+
return resolve(true);
|
|
192
|
+
}
|
|
193
|
+
const connecting = await ipc.isConnecting(devId);
|
|
194
|
+
if (!connecting.isConnecting) {
|
|
195
|
+
sdkLog("info", "connectDevice", "awakeIpcConnectStart", { devId });
|
|
196
|
+
await ipc.connect(devId);
|
|
197
|
+
if (!hasWirelessAwake) {
|
|
198
|
+
clearTimeout(timer);
|
|
199
|
+
return resolve(true);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
sdkLog("debug", "connectDevice", "awakeIpcConnecting", { devId });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
sdkLog("error", "connectDevice", "awakeFail", {
|
|
208
|
+
devId,
|
|
209
|
+
duration: Date.now() - startedAt,
|
|
210
|
+
error,
|
|
211
|
+
});
|
|
212
|
+
reject(error);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
run();
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
export const disconnectDeviceForRuntime = async (rt, options) => {
|
|
219
|
+
const cfg = rt.config;
|
|
220
|
+
const devId = cfg.devInfo.devId;
|
|
221
|
+
const startedAt = Date.now();
|
|
222
|
+
sdkLog("info", "disconnectDevice", "start", {
|
|
223
|
+
devId,
|
|
224
|
+
});
|
|
225
|
+
try {
|
|
226
|
+
const deviceStatus = getDeviceStatusForRuntime(rt);
|
|
227
|
+
await ipc.disConnect(devId);
|
|
228
|
+
if (deviceStatus.onlineTypes.includes("ble") && !!options?.disconnetBle) {
|
|
229
|
+
await disconnectBLEDevice(devId);
|
|
230
|
+
}
|
|
231
|
+
sdkLog("info", "disconnectDevice", "success", {
|
|
232
|
+
devId,
|
|
233
|
+
duration: Date.now() - startedAt,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
catch (e) {
|
|
237
|
+
sdkLog("error", "disconnectDevice", "Fail", {
|
|
238
|
+
devId,
|
|
239
|
+
duration: Date.now() - startedAt,
|
|
240
|
+
error: e,
|
|
241
|
+
});
|
|
242
|
+
throw e;
|
|
243
|
+
}
|
|
212
244
|
};
|
package/lib/platform/device.d.ts
CHANGED
|
@@ -173,6 +173,7 @@ export declare const navigateTo: (params: ParamType<typeof ty.navigateTo>) => vo
|
|
|
173
173
|
export declare const checkShowMatterMutilpleShare: (deviceId: string) => Promise<unknown>;
|
|
174
174
|
export declare const getBLEOnlineState: (deviceId: string) => Promise<boolean>;
|
|
175
175
|
export declare const connectBLEDevice: (deviceId: string) => Promise<void>;
|
|
176
|
+
export declare const disconnectBLEDevice: (deviceId: string) => Promise<void>;
|
|
176
177
|
export interface BLEFileTransferParams {
|
|
177
178
|
deviceId: string;
|
|
178
179
|
fileId: number;
|
package/lib/platform/device.js
CHANGED
|
@@ -365,6 +365,15 @@ export const connectBLEDevice = (deviceId) => {
|
|
|
365
365
|
});
|
|
366
366
|
});
|
|
367
367
|
};
|
|
368
|
+
export const disconnectBLEDevice = (deviceId) => {
|
|
369
|
+
return new Promise((resolve, reject) => {
|
|
370
|
+
ty.device.disconnectBLEDevice({
|
|
371
|
+
deviceId,
|
|
372
|
+
success: () => resolve(),
|
|
373
|
+
fail: reject,
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
};
|
|
368
377
|
export const postBLEFileTransfer = (params) => {
|
|
369
378
|
return new Promise((resolve, reject) => {
|
|
370
379
|
const device = ty.device;
|
|
@@ -450,10 +459,10 @@ export const offAppShow = (cb) => {
|
|
|
450
459
|
ty.offAppShow(cb);
|
|
451
460
|
};
|
|
452
461
|
export const onAppHide = (cb) => {
|
|
453
|
-
ty.
|
|
462
|
+
ty.onAppHide(cb);
|
|
454
463
|
};
|
|
455
464
|
export const offAppHide = (cb) => {
|
|
456
|
-
ty.
|
|
465
|
+
ty.offAppHide(cb);
|
|
457
466
|
};
|
|
458
467
|
export const trackEvent = (event, data) => {
|
|
459
468
|
ty.event({
|
package/lib/platform/ipc.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ declare const _default: {
|
|
|
6
6
|
isConnecting: (deviceId: string) => Promise<{
|
|
7
7
|
isConnecting: boolean;
|
|
8
8
|
}>;
|
|
9
|
+
disConnect: (deviceId: string) => Promise<unknown>;
|
|
9
10
|
connect: (deviceId: string) => Promise<unknown>;
|
|
10
11
|
getCurrentSupportedTalkMode: (deviceId: string) => Promise<{
|
|
11
12
|
talkbackMode: number;
|
package/lib/platform/ipc.js
CHANGED
|
@@ -18,6 +18,11 @@ const connect = (deviceId) => {
|
|
|
18
18
|
ty.ipc.connect({ deviceId, success: resolve, fail: reject });
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
|
+
const disConnect = (deviceId) => {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
ty.ipc.disConnect({ deviceId, success: resolve, fail: reject });
|
|
24
|
+
});
|
|
25
|
+
};
|
|
21
26
|
const getCurrentSupportedTalkMode = (deviceId) => {
|
|
22
27
|
if (ty.ipc.getCurrentSupportedTalkMode) {
|
|
23
28
|
return new Promise((resolve, reject) => {
|
|
@@ -47,6 +52,7 @@ export default {
|
|
|
47
52
|
wakeUpDoorBell,
|
|
48
53
|
isConnected,
|
|
49
54
|
isConnecting,
|
|
55
|
+
disConnect,
|
|
50
56
|
connect,
|
|
51
57
|
getCurrentSupportedTalkMode,
|
|
52
58
|
getTTTAbilityKeyList,
|