@ray-js/lock-sdk 1.2.0-beta.1 → 1.2.0-beta.10

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 (74) hide show
  1. package/lib/api/index.d.ts +3 -1
  2. package/lib/api/index.js +16 -0
  3. package/lib/api/notify.d.ts +28 -0
  4. package/lib/api/notify.js +17 -0
  5. package/lib/api/screen.d.ts +1 -0
  6. package/lib/api/service.d.ts +26 -0
  7. package/lib/api/service.js +25 -0
  8. package/lib/api/video.d.ts +9 -0
  9. package/lib/api/video.js +30 -0
  10. package/lib/api/voip.d.ts +10 -0
  11. package/lib/api/voip.js +17 -0
  12. package/lib/config/dp-code/index.d.ts +1 -0
  13. package/lib/config/dp-code/index.js +1 -0
  14. package/lib/config/dp-map/media.d.ts +13 -0
  15. package/lib/config/dp-map/media.js +19 -0
  16. package/lib/entries/main/exports/ai.d.ts +4 -0
  17. package/lib/entries/main/exports/ai.js +11 -0
  18. package/lib/entries/main/exports/index.d.ts +4 -0
  19. package/lib/entries/main/exports/index.js +4 -0
  20. package/lib/entries/main/exports/media.d.ts +10 -1
  21. package/lib/entries/main/exports/media.js +29 -1
  22. package/lib/entries/main/exports/notify.d.ts +7 -0
  23. package/lib/entries/main/exports/notify.js +8 -0
  24. package/lib/entries/main/exports/screen/bind.d.ts +6 -3
  25. package/lib/entries/main/exports/screen/bind.js +7 -0
  26. package/lib/entries/main/exports/service.d.ts +4 -0
  27. package/lib/entries/main/exports/service.js +11 -0
  28. package/lib/entries/main/exports/voip.d.ts +3 -0
  29. package/lib/entries/main/exports/voip.js +8 -0
  30. package/lib/entries/screen/exports/bind-events.d.ts +4 -0
  31. package/lib/entries/screen/exports/bind-events.js +8 -0
  32. package/lib/entries/screen/exports/index.d.ts +1 -0
  33. package/lib/entries/screen/exports/index.js +1 -0
  34. package/lib/feature/ai/report.d.ts +5 -0
  35. package/lib/feature/ai/report.js +37 -0
  36. package/lib/feature/media/camera.d.ts +18 -0
  37. package/lib/feature/media/camera.js +36 -0
  38. package/lib/feature/media/media.d.ts +10 -0
  39. package/lib/feature/media/media.js +31 -0
  40. package/lib/feature/misc/capability.js +77 -6
  41. package/lib/feature/notify/notify.d.ts +4 -0
  42. package/lib/feature/notify/notify.js +3 -0
  43. package/lib/feature/password/temporary/custom-dp.js +59 -54
  44. package/lib/feature/screen/bind-watch.d.ts +18 -0
  45. package/lib/feature/screen/bind-watch.js +92 -0
  46. package/lib/feature/screen/bind.d.ts +2 -2
  47. package/lib/feature/screen/bind.js +8 -38
  48. package/lib/feature/screen/list.js +13 -0
  49. package/lib/feature/service/goto-service.d.ts +2 -1
  50. package/lib/feature/service/goto-service.js +7 -1
  51. package/lib/feature/service/value-added.d.ts +4 -0
  52. package/lib/feature/service/value-added.js +4 -0
  53. package/lib/feature/state/init-state.js +26 -18
  54. package/lib/feature/state/remote-permissions.js +16 -0
  55. package/lib/feature/storage/index.d.ts +5 -0
  56. package/lib/feature/storage/index.js +32 -0
  57. package/lib/feature/unlock/sync/unlock-method.js +3 -0
  58. package/lib/feature/voip/voip.d.ts +3 -0
  59. package/lib/feature/voip/voip.js +3 -0
  60. package/lib/interface.d.ts +24 -1
  61. package/lib/platform/device.d.ts +1 -1
  62. package/lib/platform/device.js +1 -1
  63. package/lib/platform/index.d.ts +1 -0
  64. package/lib/platform/index.js +1 -0
  65. package/lib/platform/ipc.js +10 -7
  66. package/lib/platform/storage.d.ts +3 -0
  67. package/lib/platform/storage.js +9 -0
  68. package/lib/runtime/lock-config.d.ts +2 -1
  69. package/lib/runtime/lock-config.js +1 -0
  70. package/lib/utils/errors.js +3 -1
  71. package/lib/utils/index.d.ts +35 -0
  72. package/lib/utils/index.js +11 -1
  73. package/lib/utils/parse.js +1 -1
  74. package/package.json +1 -1
@@ -4,6 +4,7 @@ import dpCodes from "../../config/dp-code";
4
4
  import { RotateType, VedioType } from "../../constant";
5
5
  import { isSupportShortLink } from "../../platform";
6
6
  import { getError } from "../../utils/errors";
7
+ import { getMediaViewTimes, setMediaViewTimes, getAlbumDateList, } from "../../api/video";
7
8
  export const getMediaUrlForRuntime = async (runtime, params) => {
8
9
  const devId = runtime.config.devInfo.devId;
9
10
  if ("mediaPath" in params && "mediaBucket" in params) {
@@ -52,6 +53,27 @@ export const openLocalAlbumForRuntime = async (runtime, params) => {
52
53
  }
53
54
  return Promise.reject(getError(1013));
54
55
  };
56
+ export const gotoPlaybackForRuntime = async (runtime, params) => {
57
+ const link = await isSupportShortLink("camera_playbacks_panel");
58
+ if (!link) {
59
+ return Promise.reject(getError(1013));
60
+ }
61
+ const tabs = params?.tabs && params.tabs.length ? params.tabs : ["local"];
62
+ let url = `tuyaSmart://${link}?extra_camera_uuid=${runtime.devId}&devId=${runtime.devId}&bizType=doorLock&defaultShowTabs=true&theme=1&tabs=${JSON.stringify(tabs)}`;
63
+ if (params?.isLowPower) {
64
+ url += `&isLowPowerDevice=true`;
65
+ }
66
+ if (params?.rotate !== undefined) {
67
+ url += `&rotate=${params.rotate}`;
68
+ }
69
+ return new Promise((resolve, reject) => {
70
+ ty.router({
71
+ url,
72
+ success: () => resolve(),
73
+ fail: (e) => reject(e),
74
+ });
75
+ });
76
+ };
55
77
  export const getMediaInfoForRuntime = (runtime) => {
56
78
  const isSEI = runtime.config.capabilities?.rotateType === RotateType.SEI;
57
79
  return {
@@ -64,3 +86,12 @@ export const getMediaInfoForRuntime = (runtime) => {
64
86
  isTwoWayTalk: runtime.config.isTwoWayTalk,
65
87
  };
66
88
  };
89
+ export const getMediaViewTimesForRuntime = (runtime) => {
90
+ return getMediaViewTimes(runtime.config.devInfo.devId);
91
+ };
92
+ export const setMediaViewTimesForRuntime = (runtime) => {
93
+ return setMediaViewTimes(runtime.config.devInfo.devId);
94
+ };
95
+ export const getAlbumDateListForRuntime = (runtime) => {
96
+ return getAlbumDateList(runtime.config.devInfo.devId);
97
+ };
@@ -34,23 +34,52 @@ export const isActiveThreadForRuntime = async (rt) => {
34
34
  }
35
35
  return false;
36
36
  };
37
+ const allModes = [
38
+ {
39
+ mode: "VR",
40
+ value: 1,
41
+ },
42
+ {
43
+ mode: "original",
44
+ value: 0,
45
+ },
46
+ {
47
+ mode: "vertical",
48
+ value: 3,
49
+ },
50
+ {
51
+ mode: "horizontal",
52
+ value: 2,
53
+ },
54
+ ];
37
55
  export const getDeviceAdvancedAbilitiesForRuntime = async (rt) => {
38
56
  if (rt.cache.deviceAdvanceAbilityCache) {
39
57
  return rt.cache.deviceAdvanceAbilityCache;
40
58
  }
41
- const [productAbilities, deviceAdvancedAbility] = await Promise.all([
59
+ const [productAbilitiesRes, deviceAdvancedAbilityRes] = await Promise.allSettled([
42
60
  getProductAbilities(rt.config.devInfo.devId, [
43
61
  "tyabi4ucx5",
44
62
  "tyabis9tpe",
45
63
  "tyabiwxrn9",
46
64
  "tyabipd4hh",
47
65
  "tyabin4u5v",
66
+ "visual_door_lock_cloud_store",
48
67
  ]),
49
68
  getDeviceAdvancedAbility(rt.config.devInfo.devId),
50
69
  ]);
70
+ const productAbilities = productAbilitiesRes.status === "fulfilled" ? productAbilitiesRes.value : [];
71
+ const deviceAdvancedAbility = deviceAdvancedAbilityRes.status === "fulfilled"
72
+ ? deviceAdvancedAbilityRes.value
73
+ : undefined;
51
74
  const deviceAdvanceAbilityCache = {
52
75
  cloudStorage: {
53
- support: deviceAdvancedAbility.types.includes(0),
76
+ support: deviceAdvancedAbility?.types?.includes(0) ?? false,
77
+ },
78
+ vr: {
79
+ support: false,
80
+ defaultMode: "VR",
81
+ modes: [],
82
+ coverMode: "VR",
54
83
  },
55
84
  ai: {
56
85
  support: false,
@@ -61,12 +90,12 @@ export const getDeviceAdvancedAbilitiesForRuntime = async (rt) => {
61
90
  config: {},
62
91
  },
63
92
  voip: {
64
- support: deviceAdvancedAbility.types.includes(1),
93
+ support: false,
65
94
  config: {},
66
95
  },
67
96
  wechatVoip: {
68
97
  support: false,
69
- config: {},
98
+ isPublice: true,
70
99
  },
71
100
  unlockGuide: {
72
101
  support: false,
@@ -80,8 +109,11 @@ export const getDeviceAdvancedAbilitiesForRuntime = async (rt) => {
80
109
  productAbilities.forEach((item) => {
81
110
  try {
82
111
  if (item.isOpen) {
83
- const data = JSON.parse(item.extConfig);
112
+ const data = item.extConfig ? JSON.parse(item.extConfig) : {};
84
113
  switch (item.abilityCode) {
114
+ case "visual_door_lock_cloud_store":
115
+ deviceAdvanceAbilityCache.cloudStorage.support = true;
116
+ break;
85
117
  case "tyabi4ucx5": {
86
118
  deviceAdvanceAbilityCache.ai.config = data;
87
119
  const dataReport = data?.ai_data_report ?? false;
@@ -95,6 +127,37 @@ export const getDeviceAdvancedAbilitiesForRuntime = async (rt) => {
95
127
  petRecognition ||
96
128
  voice ||
97
129
  message;
130
+ deviceAdvanceAbilityCache.vr.support = !!data?.lock_VR;
131
+ if (deviceAdvanceAbilityCache.vr.support) {
132
+ const modeMap = {
133
+ original: {
134
+ mode: "original",
135
+ value: 0,
136
+ },
137
+ VR: {
138
+ mode: "VR",
139
+ value: 1,
140
+ },
141
+ horizontal: {
142
+ mode: "horizontal",
143
+ value: 2,
144
+ },
145
+ vertical: {
146
+ mode: "vertical",
147
+ value: 3,
148
+ },
149
+ };
150
+ deviceAdvanceAbilityCache.vr.modes = allModes.filter((item) => {
151
+ return data?.modes?.includes(item.mode);
152
+ });
153
+ deviceAdvanceAbilityCache.vr.defaultMode = data.default_mode;
154
+ const exist = deviceAdvanceAbilityCache.vr.modes.find((x) => x.mode === deviceAdvanceAbilityCache.vr.defaultMode);
155
+ if (!exist) {
156
+ deviceAdvanceAbilityCache.vr.defaultMode =
157
+ deviceAdvanceAbilityCache.vr.modes?.[0].mode;
158
+ }
159
+ deviceAdvanceAbilityCache.vr.coverMode = data.photo_cover_format;
160
+ }
98
161
  break;
99
162
  }
100
163
  case "tyabis9tpe": {
@@ -104,8 +167,16 @@ export const getDeviceAdvancedAbilitiesForRuntime = async (rt) => {
104
167
  }
105
168
  case "tyabiwxrn9": {
106
169
  deviceAdvanceAbilityCache.wechatVoip.support =
170
+ deviceAdvancedAbility?.types?.includes(1) ?? false;
171
+ deviceAdvanceAbilityCache.wechatVoip.isPublice =
172
+ data?.WechatType === "0";
173
+ if (!deviceAdvanceAbilityCache.wechatVoip.isPublice) {
174
+ deviceAdvanceAbilityCache.wechatVoip.appId =
175
+ data["WechatMPAppid"];
176
+ deviceAdvanceAbilityCache.wechatVoip.modeId = data["WechatMPMid"];
177
+ }
178
+ deviceAdvanceAbilityCache.voip.support =
107
179
  !!data?.voipType?.includes("0");
108
- deviceAdvanceAbilityCache.wechatVoip.config = data;
109
180
  break;
110
181
  }
111
182
  case "tyabipd4hh": {
@@ -0,0 +1,4 @@
1
+ import { type UpdateVasNotifyConfigParams } from "../../api/notify";
2
+ import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
3
+ export declare const getVasNotifyConfigForRuntime: (rt: LockDeviceRuntime) => Promise<import("../../api/notify").VasNotifyConfig>;
4
+ export declare const updateVasNotifyConfigForRuntime: (rt: LockDeviceRuntime, params: UpdateVasNotifyConfigParams) => Promise<import("../../api/notify").VasNotifyConfig>;
@@ -0,0 +1,3 @@
1
+ import { getVasNotifyConfigApi, updateVasNotifyConfigApi, } from "../../api/notify";
2
+ export const getVasNotifyConfigForRuntime = (rt) => getVasNotifyConfigApi(rt.config.devInfo.devId);
3
+ export const updateVasNotifyConfigForRuntime = (rt, params) => updateVasNotifyConfigApi(rt.config.devInfo.devId, params);
@@ -52,67 +52,72 @@ export const createTempCustomForRuntime = parallelOnlyForRuntime(async function
52
52
  throw handleCloudError(error);
53
53
  }
54
54
  }
55
- await isValidPassword(baseData);
56
- const { tyNum, name: createdName } = await createTemporaryPassword({
57
- ...baseData,
58
- sn: 0,
59
- availTime: 0,
60
- symbolic: false,
61
- dpTunnel: 2,
62
- });
63
- if (!tyNum) {
64
- const error = getError(1043);
65
- sdkLog("warn", "tempPassword", "createCustomMissingCloudNo", {
55
+ try {
56
+ await isValidPassword(baseData);
57
+ const { tyNum, name: createdName } = await createTemporaryPassword({
58
+ ...baseData,
59
+ sn: 0,
60
+ availTime: 0,
61
+ symbolic: false,
62
+ dpTunnel: 2,
63
+ });
64
+ if (!tyNum) {
65
+ const error = getError(1043);
66
+ sdkLog("warn", "tempPassword", "createCustomMissingCloudNo", {
67
+ devId: rt.devId,
68
+ duration: Date.now() - startedAt,
69
+ error,
70
+ });
71
+ throw error;
72
+ }
73
+ const targetDpCode = cfg.supportBigData
74
+ ? dpCodes.tempPwdCreateW
75
+ : dpCodes.tempPwdCreate;
76
+ const dpPayload = dpUtils.format({
77
+ cloudNo: tyNum,
78
+ valid: true,
79
+ validConfig,
80
+ validNum: 0,
81
+ pwdLength: params.password.length,
82
+ pwd: params.password.split("").map(Number),
83
+ }, (cfg.supportBigData ? addTempPwdBigDpMap : addTempPwdDpMap));
84
+ const result = await publishDpsForRuntime(rt, {
85
+ [targetDpCode]: dpPayload,
86
+ }, {
87
+ checkReport: (dpsIn) => {
88
+ const dpDataRow = dpsIn;
89
+ const reportData = dpDataRow[targetDpCode];
90
+ if (reportData) {
91
+ const data = dpUtils.parse(dpDataRow[targetDpCode], (cfg.supportBigData
92
+ ? reportAddTempPwdDBigpMap
93
+ : reportAddTempPwdDpMap));
94
+ if (data.cloudNo === tyNum) {
95
+ return data;
96
+ }
97
+ }
98
+ return false;
99
+ },
100
+ });
101
+ if (result.status === 0) {
102
+ sdkLog("info", "tempPassword", "createCustomSuccess", {
103
+ devId: rt.devId,
104
+ duration: Date.now() - startedAt,
105
+ data: { route: "nearDp" },
106
+ });
107
+ return buildTempCustomCreateResult(createdName, params.password, result.unlockBindingId, effective);
108
+ }
109
+ const error = getError(result.status === 2 ? 1041 : 1042);
110
+ sdkLog("warn", "tempPassword", "createCustomDpFail", {
66
111
  devId: rt.devId,
67
112
  duration: Date.now() - startedAt,
113
+ data: { status: result.status },
68
114
  error,
69
115
  });
70
116
  throw error;
71
117
  }
72
- const targetDpCode = cfg.supportBigData
73
- ? dpCodes.tempPwdCreateW
74
- : dpCodes.tempPwdCreate;
75
- const dpPayload = dpUtils.format({
76
- cloudNo: tyNum,
77
- valid: true,
78
- validConfig,
79
- validNum: 0,
80
- pwdLength: params.password.length,
81
- pwd: params.password.split("").map(Number),
82
- }, (cfg.supportBigData ? addTempPwdBigDpMap : addTempPwdDpMap));
83
- const result = await publishDpsForRuntime(rt, {
84
- [targetDpCode]: dpPayload,
85
- }, {
86
- checkReport: (dpsIn) => {
87
- const dpDataRow = dpsIn;
88
- const reportData = dpDataRow[targetDpCode];
89
- if (reportData) {
90
- const data = dpUtils.parse(dpDataRow[targetDpCode], (cfg.supportBigData
91
- ? reportAddTempPwdDBigpMap
92
- : reportAddTempPwdDpMap));
93
- if (data.cloudNo === tyNum) {
94
- return data;
95
- }
96
- }
97
- return false;
98
- },
99
- });
100
- if (result.status === 0) {
101
- sdkLog("info", "tempPassword", "createCustomSuccess", {
102
- devId: rt.devId,
103
- duration: Date.now() - startedAt,
104
- data: { route: "nearDp" },
105
- });
106
- return buildTempCustomCreateResult(createdName, params.password, result.unlockBindingId, effective);
118
+ catch (er) {
119
+ throw handleCloudError(er);
107
120
  }
108
- const error = getError(result.status === 2 ? 1041 : 1042);
109
- sdkLog("warn", "tempPassword", "createCustomDpFail", {
110
- devId: rt.devId,
111
- duration: Date.now() - startedAt,
112
- data: { status: result.status },
113
- error,
114
- });
115
- throw error;
116
121
  });
117
122
  export async function removeTempCustomForRuntime(rt, params) {
118
123
  const cfg = rt.config;
@@ -0,0 +1,18 @@
1
+ import { type BindingResult } from "../../api/screen";
2
+ import type { ErrorData } from "../../interface";
3
+ import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
4
+ export interface BindLockToScreenEvent {
5
+ lockDevId: string;
6
+ success: boolean;
7
+ data?: BindingResult;
8
+ error?: ErrorData;
9
+ }
10
+ export type BindLockToScreenListener = (event: BindLockToScreenEvent) => void;
11
+ export declare function emitBindResult(runtime: LockDeviceRuntime, event: BindLockToScreenEvent): void;
12
+ export declare function onBindLockToScreenForRuntime(runtime: LockDeviceRuntime, listener: BindLockToScreenListener): void;
13
+ export declare function offBindLockToScreenForRuntime(runtime: LockDeviceRuntime, listener: BindLockToScreenListener): void;
14
+ export declare function watchBindResult(runtime: LockDeviceRuntime, params: {
15
+ lockDevId: string;
16
+ sessionId: string;
17
+ }): Promise<void>;
18
+ export declare function isWatchingBind(runtime: LockDeviceRuntime, sessionId: string): boolean;
@@ -0,0 +1,92 @@
1
+ import { getBindingResultApi } from "../../api/screen";
2
+ import emitter from "../../utils/event";
3
+ import { getError } from "../../utils/errors";
4
+ import { sdkLog } from "../../utils/sdk-log";
5
+ import { handleScreenCloudError } from "./error";
6
+ const POLL_INTERVAL_MS = 2_000;
7
+ const BIND_POLL_TIMEOUT_MS = 30_000;
8
+ const delay = (ms) => new Promise((resolve) => {
9
+ setTimeout(resolve, ms);
10
+ });
11
+ function bindResultEventName(runtime) {
12
+ return `screen_bind_result_${runtime.devId}`;
13
+ }
14
+ export function emitBindResult(runtime, event) {
15
+ emitter.emit(bindResultEventName(runtime), event);
16
+ }
17
+ const watchKey = (runtime, sessionId) => `${runtime.devId}:${sessionId}`;
18
+ const inflight = new Map();
19
+ export function onBindLockToScreenForRuntime(runtime, listener) {
20
+ emitter.on(bindResultEventName(runtime), listener);
21
+ }
22
+ export function offBindLockToScreenForRuntime(runtime, listener) {
23
+ emitter.off(bindResultEventName(runtime), listener);
24
+ }
25
+ async function pollBindResult(runtime, lockDevId, sessionId) {
26
+ const accessoryDevId = runtime.devId;
27
+ const startedAt = Date.now();
28
+ const deadline = startedAt + BIND_POLL_TIMEOUT_MS;
29
+ while (Date.now() < deadline) {
30
+ await delay(POLL_INTERVAL_MS);
31
+ let result;
32
+ try {
33
+ result = await getBindingResultApi({ accessoryDevId, sessionId });
34
+ }
35
+ catch (e) {
36
+ const error = handleScreenCloudError(e);
37
+ sdkLog("error", "screen", "bindResultPollError", {
38
+ devId: accessoryDevId,
39
+ duration: Date.now() - startedAt,
40
+ data: { lockDevId },
41
+ error: e,
42
+ });
43
+ emitBindResult(runtime, { lockDevId, success: false, error });
44
+ return;
45
+ }
46
+ if (result.status === "binding") {
47
+ continue;
48
+ }
49
+ if (result.status === "bound") {
50
+ sdkLog("info", "screen", "bindResultSettled", {
51
+ devId: accessoryDevId,
52
+ duration: Date.now() - startedAt,
53
+ data: { lockDevId, status: result.status, lanStatus: result.lanStatus },
54
+ });
55
+ emitBindResult(runtime, { lockDevId, success: true, data: result });
56
+ return;
57
+ }
58
+ sdkLog("info", "screen", "bindResultSettled", {
59
+ devId: accessoryDevId,
60
+ duration: Date.now() - startedAt,
61
+ data: { lockDevId, status: result.status, lanStatus: result.lanStatus },
62
+ });
63
+ emitBindResult(runtime, {
64
+ lockDevId,
65
+ success: false,
66
+ data: result,
67
+ error: getError(1103),
68
+ });
69
+ return;
70
+ }
71
+ sdkLog("warn", "screen", "bindResultTimeout", {
72
+ devId: accessoryDevId,
73
+ duration: Date.now() - startedAt,
74
+ data: { lockDevId },
75
+ });
76
+ emitBindResult(runtime, { lockDevId, success: false, error: getError(1002) });
77
+ }
78
+ export function watchBindResult(runtime, params) {
79
+ const key = watchKey(runtime, params.sessionId);
80
+ const existing = inflight.get(key);
81
+ if (existing) {
82
+ return existing;
83
+ }
84
+ const task = pollBindResult(runtime, params.lockDevId, params.sessionId).finally(() => {
85
+ inflight.delete(key);
86
+ });
87
+ inflight.set(key, task);
88
+ return task;
89
+ }
90
+ export function isWatchingBind(runtime, sessionId) {
91
+ return inflight.has(watchKey(runtime, sessionId));
92
+ }
@@ -1,4 +1,4 @@
1
- import { type BindingResult, type UnbindingResult } from "../../api/screen";
1
+ import { type AddBindingResult, type UnbindingResult } from "../../api/screen";
2
2
  import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
3
- export declare function bindLockForRuntime(runtime: LockDeviceRuntime, lockDevId: string): Promise<BindingResult>;
3
+ export declare function bindLockForRuntime(runtime: LockDeviceRuntime, lockDevId: string): Promise<AddBindingResult>;
4
4
  export declare function unbindLockForRuntime(runtime: LockDeviceRuntime, relationId: string): Promise<UnbindingResult>;
@@ -1,11 +1,11 @@
1
- import { addBindingApi, deleteBindingApi, getBindingResultApi, getUnbindingResultApi, } from "../../api/screen";
1
+ import { addBindingApi, deleteBindingApi, getUnbindingResultApi, } from "../../api/screen";
2
2
  import { getDeviceInfo } from "../../platform/device";
3
3
  import { getError } from "../../utils/errors";
4
4
  import { sdkLog } from "../../utils/sdk-log";
5
5
  import { getDeviceStatusForRuntime } from "../state/device-status";
6
6
  import { handleScreenCloudError } from "./error";
7
+ import { watchBindResult } from "./bind-watch";
7
8
  const POLL_INTERVAL_MS = 2_000;
8
- const BIND_POLL_TIMEOUT_MS = 25_000;
9
9
  const UNBIND_POLL_TIMEOUT_MS = 20_000;
10
10
  const delay = (ms) => new Promise((resolve) => {
11
11
  setTimeout(resolve, ms);
@@ -42,48 +42,18 @@ export async function bindLockForRuntime(runtime, lockDevId) {
42
42
  });
43
43
  sdkLog("info", "screen", "bindAddSuccess", {
44
44
  devId: accessoryDevId,
45
+ duration: Date.now() - startedAt,
45
46
  data: { lockDevId, relationId: sessionData.relationId },
46
47
  });
47
48
  }
48
49
  catch (e) {
49
50
  throw handleScreenCloudError(e);
50
51
  }
51
- const deadline = Date.now() + BIND_POLL_TIMEOUT_MS;
52
- let last;
53
- while (Date.now() < deadline) {
54
- await delay(POLL_INTERVAL_MS);
55
- try {
56
- last = await getBindingResultApi({
57
- accessoryDevId,
58
- sessionId: sessionData.sessionId,
59
- });
60
- }
61
- catch (e) {
62
- throw handleScreenCloudError(e);
63
- }
64
- if (last.status !== "binding") {
65
- sdkLog("info", "screen", "bindSettled", {
66
- devId: accessoryDevId,
67
- duration: Date.now() - startedAt,
68
- data: {
69
- lockDevId,
70
- relationId: sessionData.relationId,
71
- status: last.status,
72
- lanStatus: last.lanStatus,
73
- },
74
- });
75
- if (last.status === "failed") {
76
- throw getError(1103);
77
- }
78
- return last;
79
- }
80
- }
81
- sdkLog("warn", "screen", "bindTimeout", {
82
- devId: accessoryDevId,
83
- duration: Date.now() - startedAt,
84
- data: { lockDevId, relationId: sessionData.relationId },
85
- });
86
- throw getError(1002);
52
+ void watchBindResult(runtime, {
53
+ lockDevId,
54
+ sessionId: sessionData.sessionId,
55
+ }).catch(() => { });
56
+ return sessionData;
87
57
  }
88
58
  catch (error) {
89
59
  sdkLog("error", "screen", "bindFail", {
@@ -1,6 +1,7 @@
1
1
  import { getBoundLockListApi, getBindableLockListApi, } from "../../api/screen";
2
2
  import { getDeviceInfo } from "../../platform/device";
3
3
  import { sdkLog } from "../../utils/sdk-log";
4
+ import { isWatchingBind, watchBindResult } from "./bind-watch";
4
5
  async function resolveLockDeviceInfo(accessoryDevId, lockDevId) {
5
6
  try {
6
7
  const info = await getDeviceInfo(lockDevId);
@@ -52,5 +53,17 @@ export async function getBindableLockListForRuntime(runtime) {
52
53
  duration: Date.now() - startedAt,
53
54
  data: { count: items.length, canBindMore: result?.canBindMore },
54
55
  });
56
+ for (const item of items) {
57
+ if (item.bindStatus !== "binding" || !item.sessionId) {
58
+ continue;
59
+ }
60
+ if (isWatchingBind(runtime, item.sessionId)) {
61
+ continue;
62
+ }
63
+ void watchBindResult(runtime, {
64
+ lockDevId: item.lockDevId,
65
+ sessionId: item.sessionId,
66
+ }).catch(() => { });
67
+ }
55
68
  return { ...result, items };
56
69
  }
@@ -1,5 +1,6 @@
1
1
  import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
2
2
  export interface GotoServiceParams {
3
- tab?: "cloudStorage" | "AI";
3
+ tab?: "cloudStorage" | "AI" | "voip";
4
+ showGift?: boolean;
4
5
  }
5
6
  export declare function gotoServiceForRuntime(rt: LockDeviceRuntime, params?: GotoServiceParams): Promise<unknown>;
@@ -4,8 +4,14 @@ export function gotoServiceForRuntime(rt, params) {
4
4
  if (params?.tab === "AI") {
5
5
  type = 3;
6
6
  }
7
+ else if (params?.tab === "voip") {
8
+ type = 1;
9
+ }
7
10
  return new Promise((resolve, reject) => {
8
- const url = `godzilla://tyawqoyej4wi3pqebb?deviceId=${rt.config.devInfo.devId}&commodityType=${type}`;
11
+ let url = `godzilla://tyawqoyej4wi3pqebb?deviceId=${rt.config.devInfo.devId}&commodityType=${type}`;
12
+ if (params?.showGift) {
13
+ url += `&showGift=true`;
14
+ }
9
15
  navigateToMiniProgram({
10
16
  position: "bottom",
11
17
  shortLink: url,
@@ -0,0 +1,4 @@
1
+ import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
2
+ export declare const getCloudServiceStatusForRuntime: (rt: LockDeviceRuntime) => Promise<import("../../api/service").CloudServiceStatus>;
3
+ export declare const getServicePopupListForRuntime: (rt: LockDeviceRuntime) => Promise<import("../../api/service").ServiceBenefitPopupItem[]>;
4
+ export declare const claimServiceForRuntime: (rt: LockDeviceRuntime, batchId: string) => Promise<import("../../api/service").ClaimResultItem[]>;
@@ -0,0 +1,4 @@
1
+ import { getCloudServiceStatusApi, getServicePopupListApi, claimServiceApi, } from "../../api/service";
2
+ export const getCloudServiceStatusForRuntime = (rt) => getCloudServiceStatusApi(rt.config.devInfo.devId);
3
+ export const getServicePopupListForRuntime = (rt) => getServicePopupListApi(rt.config.devInfo.devId);
4
+ export const claimServiceForRuntime = (rt, batchId) => claimServiceApi(rt.config.devInfo.devId, batchId);
@@ -16,6 +16,7 @@ import { fetchDeviceProperties } from "./remote-permissions";
16
16
  import { ipc, yuChannelSyncSingleSync } from "../../platform";
17
17
  import { sdkLog } from "../../utils/sdk-log";
18
18
  import { RotateType } from "../../constant";
19
+ import { isHarmony } from "../../utils";
19
20
  export const initState = async (runtime) => {
20
21
  const { devInfo: { dps, devId, yuNetState }, dpSchema, } = runtime.config;
21
22
  const startedAt = Date.now();
@@ -38,9 +39,10 @@ export const initState = async (runtime) => {
38
39
  isSupportVideo,
39
40
  },
40
41
  });
41
- const [, , rotateInfo, deviceSkill, ipcConfig] = await Promise.allSettled([
42
+ const [, , , rotateInfo, deviceSkill, ipcConfig] = await Promise.allSettled([
42
43
  updateOnlineType(runtime),
43
44
  getCurrentUserForRuntime(runtime),
45
+ fetchDeviceProperties(runtime),
44
46
  isSupportVideo
45
47
  ? getDataWithPreFetchForRuntime(runtime, "getRotate", () => getRotateInfo(devId))
46
48
  : Promise.resolve({
@@ -76,24 +78,31 @@ export const initState = async (runtime) => {
76
78
  }
77
79
  if (ipcConfig.status === "fulfilled" &&
78
80
  ipcConfig.value?.audioAttributes?.hardwareCapability?.includes(2)) {
79
- try {
80
- const modeRes = await ipc.getCurrentSupportedTalkMode(devId);
81
+ if (isHarmony()) {
81
82
  runtime.config.supportTalk = true;
82
- runtime.config.isTwoWayTalk = modeRes.talkbackMode === 2;
83
- sdkLog("info", "initState", "supportTalk", {
84
- devId,
85
- duration: Date.now() - startedAt,
86
- data: {
87
- mode: modeRes.talkbackMode,
88
- },
89
- });
83
+ runtime.config.isTwoWayTalk =
84
+ ipcConfig.value?.audioAttributes?.callMode?.includes(2);
90
85
  }
91
- catch (e) {
92
- sdkLog("error", "initState", "supportTalk", {
93
- devId,
94
- duration: Date.now() - startedAt,
95
- data: {},
96
- });
86
+ else {
87
+ try {
88
+ runtime.config.supportTalk = true;
89
+ const modeRes = await ipc.getCurrentSupportedTalkMode(devId);
90
+ runtime.config.isTwoWayTalk = modeRes.talkbackMode === 2;
91
+ sdkLog("info", "initState", "supportTalk", {
92
+ devId,
93
+ duration: Date.now() - startedAt,
94
+ data: {
95
+ mode: modeRes.talkbackMode,
96
+ },
97
+ });
98
+ }
99
+ catch (e) {
100
+ sdkLog("error", "initState", "supportTalk", {
101
+ devId,
102
+ duration: Date.now() - startedAt,
103
+ error: e,
104
+ });
105
+ }
97
106
  }
98
107
  }
99
108
  if (!isSEI &&
@@ -103,7 +112,6 @@ export const initState = async (runtime) => {
103
112
  runtime.config.mediaHeight = temp;
104
113
  }
105
114
  }
106
- await fetchDeviceProperties(runtime);
107
115
  sdkLog("info", "initState", "ready", {
108
116
  devId,
109
117
  duration: Date.now() - startedAt,