@ray-js/ray-ipc-utils 1.1.4 → 1.1.6-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.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  [English](./README.md) | 简体中文
2
2
 
3
- # @ray/ray-ipc-utils
3
+ # @ray-js/ray-ipc-utils
4
4
 
5
- [![latest](https://img.shields.io/npm/v/@ray/ray-ipc-utils/latest.svg)](https://www.npmjs.com/package/@ray/ray-ipc-utils) [![download](https://img.shields.io/npm/dt/@ray/ray-ipc-utils.svg)](https://www.npmjs.com/package/@ray/ray-ipc-utils)
5
+ [![latest](https://img.shields.io/npm/v/@ray/ray-ipc-utils/latest.svg)](https://www.npmjs.com/package/@ray-js/ray-ipc-utils) [![download](https://img.shields.io/npm/dt/@ray/ray-ipc-utils.svg)](https://www.npmjs.com/package/@ray-js/ray-ipc-utils)
6
6
 
7
7
  > IPC utility library
8
8
 
@@ -14,113 +14,17 @@ $ npm install @ray-js/ray-ipc-utils
14
14
  $ yarn add @ray-js/ray-ipc-utils
15
15
  ```
16
16
 
17
- ## Usage
18
-
19
- ### preloadPanel
20
-
21
- 预下载设置二级页
22
-
23
- 入参:
24
-
25
- | 参数名称 | 描述 |
26
- | -------- | -------- |
27
- | devInfo | 设备信息 |
28
-
29
- devInfo
30
-
31
- | 参数名称 | 描述 |
32
- | -------------- | ---------------- |
33
- | devId | 设备 id |
34
- | productId | 产品 id |
35
- | productVersion | 产品版本 |
36
- | i18nTime | 面板多语言时间戳 |
37
-
38
- 示例
39
-
40
- ```tsx
41
- import { preloadPanel } from '@ray/ray-ipc-utils';
42
-
43
- // 预下载面板小程序
44
- export const getPanelApp = () => {
45
- const { devInfo } = store.getState();
46
- preloadPanel({
47
- devId: devInfo.devId, // 设备id
48
- productId: devInfo.productId, // 产品id
49
- productVersion: devInfo.pv, // 产品版本
50
- i18nTime: devInfo.time, // 面板多语言时间戳
51
- });
52
- };
53
- ```
54
-
55
- ### openPanel
56
-
57
- 打开设置二级页
58
-
59
- 入参:
60
-
61
- | 参数名称 | 描述 |
62
- | --------- | ------------------------------------------ |
63
- | devId | 设备 id |
64
- | extraData | 额外参数(一般是主小程序与二级页通信数据) |
65
- | fn | 监听二级页传递消息事件 |
66
-
67
- 示例
68
-
69
- ```tsx
70
- import { openPanel } from '@ray/ray-ipc-utils';
71
-
72
- // 打开面板小程序
73
- export const openPanelApp = () => {
74
- const { devInfo, ipcCommon } = store.getState();
75
- const { mainDeviceCameraConfig } = ipcCommon;
76
-
77
- openPanel(devInfo.devId, { mainDeviceCameraConfig }, data => {
78
- const { type } = data;
79
- const supportedAudioMode = data?.mainDeviceCameraConfig?.supportedAudioMode;
80
- switch (type) {
81
- case 'changeTalkType':
82
- // 切换对讲方式
83
- Storage.setDevItem('talkType', supportedAudioMode).then(() => {
84
- store.dispatch(
85
- actions.common.mainDeviceCameraConfig({
86
- supportedAudioMode,
87
- })
88
- );
89
- });
90
- break;
91
- // 退出设置页
92
- case 'exitMiniProgram':
93
- setTimeout(() => {
94
- exitMiniProgram();
95
- }, 50);
96
- break;
97
- default:
98
- }
99
- });
100
- };
101
- ```
102
-
103
- ### useEmitMessage
104
-
105
- 向一级小程序传递消息,结合 openPanel 传入的第三个参数使用
106
-
107
- 示例
17
+ ## Example
108
18
 
109
19
  ```tsx
110
- import { openPanel } from '@ray/ray-ipc-utils';
20
+ import { goToIpcPageNativeRoute } from '@ray-js/ray-ipc-utils';
111
21
 
112
- const emitMessage = useEmitMessage();
22
+ const id = 'ipc_album_panel';
23
+ const deviceId = '1234567890xxxxxx';
113
24
 
114
- useEmitMessage({
115
- type: 'exitMiniProgram',
116
- });
25
+ const result = await goToIpcPageNativeRoute(id, deviceId);
117
26
  ```
118
27
 
119
- ### 其他方法
28
+ ## Documentation
120
29
 
121
- | 方法名称 | 描述 | 返回值类型 |
122
- | ------------ | ------------- | ---------- |
123
- | isIos | 是否 ios 系统 | boolean |
124
- | isIphoneX | 是否 iPhoneX | boolean |
125
- | smallScreen | 是否小屏幕 | boolean |
126
- | middleScreen | 是否中屏幕 | boolean |
30
+ See [API Reference](https://developer.tuya.com/en/miniapp/solution-panel/ability/special/ipc/toolkit/general) for more information.
@@ -11,6 +11,7 @@ export declare enum IntercomMode {
11
11
  OneWay = "OneWay",
12
12
  TwoWay = "TwoWay"
13
13
  }
14
+ export declare type TalkMode = 1 | 2;
14
15
  export declare enum ServeTpe {
15
16
  trafficService = "traffic_service",
16
17
  securityCloudService = "security_cloud_service",
@@ -62,3 +63,47 @@ export interface IpcConfigInfo {
62
63
  */
63
64
  maxZoomSettings: number;
64
65
  }
66
+ export interface IApiError {
67
+ errorMsg: string;
68
+ errorCode: string | number;
69
+ innerError: {
70
+ errorMsg: string;
71
+ errorCode: string | number;
72
+ };
73
+ }
74
+ export interface IRes<T> {
75
+ code?: number;
76
+ data?: T;
77
+ msg?: IApiError | string | boolean | Record<string, any>;
78
+ }
79
+ export interface IResData<T> {
80
+ data: T;
81
+ }
82
+ export interface IResError {
83
+ code: number;
84
+ msg: string;
85
+ }
86
+ export interface IResDataError {
87
+ data: IResError;
88
+ }
89
+ export interface IResDataList<T> {
90
+ data: T[];
91
+ }
92
+ export interface IResDataListError {
93
+ data: IResError[];
94
+ }
95
+ export interface HomeInfo {
96
+ homeId: number;
97
+ [key: string]: any;
98
+ }
99
+ export interface DevInfo {
100
+ uuid: string;
101
+ dps: Record<string, any>;
102
+ schema: Record<string, any>;
103
+ [key: string]: any;
104
+ }
105
+ export interface SystemInfo {
106
+ theme: 'light' | 'dark';
107
+ [key: string]: any;
108
+ }
109
+ export declare type NativeStorageValue = any;
package/lib/interface.js CHANGED
@@ -30,4 +30,6 @@ export let MuteMode = /*#__PURE__*/function (MuteMode) {
30
30
  MuteMode["ON"] = "ON";
31
31
  MuteMode["OFF"] = "OFF";
32
32
  return MuteMode;
33
- }({});
33
+ }({});
34
+
35
+ // 封装app-api的返回类型
@@ -1,4 +1,4 @@
1
- import { IRes } from '../interface';
1
+ import { IRes } from '../../interface';
2
2
  /**
3
3
  * 获取信号强度
4
4
  * @param deviceId
@@ -8,7 +8,7 @@ import { IRes } from '../interface';
8
8
  export declare const requestWifiSignal: <T>(deviceId: string, dps?: {}) => Promise<IRes<T>>;
9
9
  /**
10
10
  * IPC-低功耗唤醒:低功耗唤醒,唤醒门铃设备
11
- * 需引入DeviceKit,且在>=3.1.0-ipcwake.1版本才可使用
11
+ * 需引入DeviceKit
12
12
  * @param deviceId
13
13
  * @returns
14
14
  */
@@ -12,14 +12,12 @@ export const requestWifiSignal = function (deviceId) {
12
12
  deviceId,
13
13
  dps: dps,
14
14
  success: res => {
15
- console.log('res===requestWifiSignal success', res);
16
15
  resolve({
17
16
  code: 0,
18
17
  data: res
19
18
  });
20
19
  },
21
20
  fail: err => {
22
- console.log('res===requestWifiSignal err', err);
23
21
  resolve({
24
22
  code: -1,
25
23
  msg: err
@@ -37,7 +35,7 @@ export const requestWifiSignal = function (deviceId) {
37
35
 
38
36
  /**
39
37
  * IPC-低功耗唤醒:低功耗唤醒,唤醒门铃设备
40
- * 需引入DeviceKit,且在>=3.1.0-ipcwake.1版本才可使用
38
+ * 需引入DeviceKit
41
39
  * @param deviceId
42
40
  * @returns
43
41
  */
@@ -49,14 +47,12 @@ export const wakeUpDevice = function (deviceId) {
49
47
  deviceId,
50
48
  dps: dps,
51
49
  success: res => {
52
- console.log('res===wakeUpDevice success', res);
53
50
  resolve({
54
51
  code: 0,
55
52
  data: res
56
53
  });
57
54
  },
58
55
  fail: err => {
59
- console.log('res===wakeUpDevice err', err);
60
56
  resolve({
61
57
  code: -1,
62
58
  msg: err
@@ -1,4 +1,4 @@
1
- import { IRes } from '../interface';
1
+ import { IRes, TalkMode } from '../../interface';
2
2
  /**
3
3
  *
4
4
  * @param deviceId 设备id
@@ -16,7 +16,7 @@ export declare const getNativeStorage: <T>(key: string) => Promise<IRes<T>>;
16
16
  * @param key 保存的key属性
17
17
  *
18
18
  */
19
- export declare const setNativeStorage: <T>(key: string, data: string) => Promise<IRes<T>>;
19
+ export declare const setNativeStorage: <T>(key: string, data: string | number | boolean | Record<string, any>) => Promise<IRes<T>>;
20
20
  /**
21
21
  * 清除本地缓存
22
22
  * @param key 保存的key属性
@@ -28,7 +28,7 @@ export declare const removeNativeStorage: <T>(key: string) => Promise<IRes<T>>;
28
28
  * @param key 保存的key属性
29
29
  *
30
30
  */
31
- export declare const publishDps: <T>(deviceId: string, dps: any) => Promise<IRes<T>>;
31
+ export declare const publishDps: <T>(deviceId: string, dps: Record<string, any>) => Promise<IRes<T>>;
32
32
  /**
33
33
  * 根据DPCode获取最新的DP点的值
34
34
  * @param key 保存的key属性
@@ -98,6 +98,13 @@ export declare const isSupportedTalk: <T>(deviceId: string, extendParam?: {}) =>
98
98
  * @returns 设备支持的对讲模式。回掉方法的参数为数值型,0 未知;1:单向对讲;2:双向对讲。
99
99
  */
100
100
  export declare const getCurrentSupportedTalkMode: <T>(deviceId: string, extendParam?: {}) => Promise<IRes<T>>;
101
+ /**
102
+ * 更新对讲方式
103
+ * @param deviceId
104
+ * @param mode 1:单向对讲;2:双向对讲
105
+ * @returns true
106
+ */
107
+ export declare const updateTalkMode: (deviceId: string, mode: TalkMode) => Promise<IRes<boolean>>;
101
108
  /**
102
109
  * 跳转 APP 原生页面
103
110
  * @param {string} url 页面路由
@@ -109,7 +116,7 @@ export declare const getCurrentSupportedTalkMode: <T>(deviceId: string, extendPa
109
116
  */
110
117
  export declare const goToIpcPageNativeRoute: <T>(url: string, deviceId: string, theme?: 'dark' | 'light', extraParams?: {
111
118
  [key: string]: any;
112
- } | undefined, isGeneral?: false) => Promise<IRes<T>>;
119
+ } | undefined, isGeneral?: boolean) => Promise<IRes<T>>;
113
120
  /**
114
121
  * 跳转 通用帮助反馈小程序
115
122
  */
@@ -128,15 +135,7 @@ export declare const goToIpcHelpMini: <T>(errCode: number, deviceId: string, hel
128
135
  * @param deviceId 设备id
129
136
  * @returns true/false
130
137
  */
131
- export declare const getIsSupportedCloudStorageSync: (deviceId: string) => Promise<{
132
- code: number;
133
- data: boolean;
134
- msg?: undefined;
135
- } | {
136
- code: number;
137
- data: boolean;
138
- msg: string | boolean | import("../interface").IApiError | undefined;
139
- }>;
138
+ export declare const getIsSupportedCloudStorageSync: (deviceId: string) => Promise<IRes<boolean>>;
140
139
  /**
141
140
  * 预埋业务日志
142
141
  * @param ipcLogString 日志字符串
@@ -587,6 +587,41 @@ export const getCurrentSupportedTalkMode = function (deviceId) {
587
587
  });
588
588
  };
589
589
 
590
+ /**
591
+ * 更新对讲方式
592
+ * @param deviceId
593
+ * @param mode 1:单向对讲;2:双向对讲
594
+ * @returns true
595
+ */
596
+ export const updateTalkMode = (deviceId, mode) => {
597
+ return new Promise(resolve => {
598
+ try {
599
+ var _ty;
600
+ (_ty = ty) === null || _ty === void 0 || _ty.ipc.updateCameraAudioMode({
601
+ devId: deviceId,
602
+ mode,
603
+ success: () => {
604
+ resolve({
605
+ code: 0,
606
+ data: true
607
+ });
608
+ },
609
+ fail: err => {
610
+ resolve({
611
+ code: -1,
612
+ msg: err
613
+ });
614
+ }
615
+ });
616
+ } catch (err) {
617
+ resolve({
618
+ code: -1,
619
+ msg: String(err)
620
+ });
621
+ }
622
+ });
623
+ };
624
+
590
625
  /**
591
626
  * 处理 IPC URL 跳转
592
627
  * @param {string} nativeUrl - 构建好的目标 URL。
@@ -682,7 +717,7 @@ const buildUrl = (url, param, isGeneral) => {
682
717
  export const goToIpcPageNativeRoute = async function (url, deviceId) {
683
718
  let theme = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
684
719
  let extraParams = arguments.length > 3 ? arguments[3] : undefined;
685
- let isGeneral = arguments.length > 4 ? arguments[4] : undefined;
720
+ let isGeneral = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
686
721
  try {
687
722
  const systemInfo = await ty.getSystemInfo();
688
723
  const pageTheme = theme || (systemInfo === null || systemInfo === void 0 ? void 0 : systemInfo.theme);
@@ -792,7 +827,6 @@ export const ipcTTTOperatorLog = ipcLogString => {
792
827
  });
793
828
  },
794
829
  fail: error => {
795
- console.log(error, 'error');
796
830
  resolve({
797
831
  code: -1,
798
832
  msg: error
@@ -1,5 +1,4 @@
1
- import { ServeTpe } from '../interface';
2
- import { IRes } from '@/kit/interface';
1
+ import { IRes, ServeTpe } from '../interface';
3
2
  /**
4
3
  * 获取IPC设备配置信息
5
4
  * @param deviceId 设备ID
@@ -9,7 +9,6 @@ import Strings from '../i18n';
9
9
  import { JsonUtil, getInitUtmTid } from '../utils';
10
10
  import { getDevInfo, getNativeStorage, setNativeStorage, publishDps, getDpStateValue, getDpIdByCode, jumpToWebView, goToMiniProgramByShortLink, getCurrentSupportedTalkMode, ipcTTTOperatorLog } from '../kit';
11
11
  import { ClarityType, IntercomMode, MuteMode, ServeTpe } from '../interface';
12
- const errStyle = 'background: red; color: #fff;';
13
12
 
14
13
  /**
15
14
  * @description: 对讲模式
@@ -112,7 +111,6 @@ export const getCameraConfigInfo = async function (deviceId) {
112
111
  const {
113
112
  isVirtualDevice
114
113
  } = devInfo === null || devInfo === void 0 ? void 0 : devInfo.data;
115
- console.log(isVirtualDevice, 'isVirtualDevice----');
116
114
  ipcTTTOperatorLog(`Utils: config info isVirtualDevice status: ${isVirtualDevice}`);
117
115
  // 配置默认值
118
116
  const defaultResolution = ClarityType.HD;
@@ -141,10 +139,10 @@ export const getCameraConfigInfo = async function (deviceId) {
141
139
 
142
140
  const nativeStorageInfo = await Promise.all([`${deviceId}_resolution`, `${deviceId}_intercom`, `${deviceId}_microphone`, `${deviceId}_maxZoomSettings`].map(key => getNativeStorage(key)));
143
141
  ipcTTTOperatorLog(`Utils: nativeStorageInfo: ${nativeStorageInfo}`);
144
- console.log(nativeStorageInfo, 'dsahdsahkdh');
145
142
  const [resolutionStorage, intercomStorage, microphoneStorage, maxZoomSettingsStorage] = nativeStorageInfo;
146
143
  // 任意缓存为空,则请求接口
147
144
 
145
+ console.log(nativeStorageInfo, 'nativeStorageInfo');
148
146
  const noCache = nativeStorageInfo.some(item => {
149
147
  var _item$data;
150
148
  return !(item !== null && item !== void 0 && (_item$data = item.data) !== null && _item$data !== void 0 && _item$data.data);
@@ -405,16 +403,6 @@ export const addCollectionPointsInfo = async (deviceId, name) => {
405
403
  };
406
404
  }
407
405
  const cruiseSwitchInfo = await getDpStateValue(deviceId, 'cruise_switch');
408
- if ((cruiseSwitchInfo === null || cruiseSwitchInfo === void 0 ? void 0 : cruiseSwitchInfo.code) === -1) {
409
- ty.showToast({
410
- icon: 'error',
411
- title: cruiseSwitchInfo.msg
412
- });
413
- return {
414
- code: -1,
415
- msg: cruiseSwitchInfo.msg
416
- };
417
- }
418
406
  if (cruiseSwitchInfo.data) {
419
407
  ty.showToast({
420
408
  icon: 'error',
@@ -425,7 +413,7 @@ export const addCollectionPointsInfo = async (deviceId, name) => {
425
413
  msg: Strings.getLang('ipc_utils_cruise_ing_tip')
426
414
  };
427
415
  }
428
- // 2. 下发DP删除收藏点 dpCode: memory_point_set
416
+ // 2. 获取收藏点 dpCode: memory_point_set
429
417
  const memoryPointSetDpId = await getDpIdByCode(deviceId, 'memory_point_set');
430
418
  if ((cruiseSwitchInfo === null || cruiseSwitchInfo === void 0 ? void 0 : cruiseSwitchInfo.code) === -1) {
431
419
  ty.showToast({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ray-ipc-utils",
3
- "version": "1.1.4",
3
+ "version": "1.1.6-beta-1",
4
4
  "description": "IPC 工具库",
5
5
  "main": "lib/index",
6
6
  "files": [
@@ -1,13 +0,0 @@
1
- export interface IApiError {
2
- errorMsg: string;
3
- errorCode: string | number;
4
- innerError: {
5
- errorMsg: string;
6
- errorCode: string | number;
7
- };
8
- }
9
- export interface IRes<T> {
10
- code?: number;
11
- data?: T;
12
- msg?: IApiError | string | boolean;
13
- }
@@ -1 +0,0 @@
1
- export {};