@ray-js/ray-ipc-utils 1.1.5 → 1.1.6
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 +9 -105
- package/lib/interface.d.ts +45 -0
- package/lib/interface.js +3 -1
- package/lib/kit/device/index.d.ts +2 -2
- package/lib/kit/device/index.js +1 -5
- package/lib/kit/ipc/index.d.ts +12 -13
- package/lib/kit/ipc/index.js +36 -2
- package/lib/service/index.d.ts +1 -2
- package/lib/service/index.js +0 -1
- package/package.json +1 -1
- package/lib/kit/interface.d.ts +0 -13
- package/lib/kit/interface.js +0 -1
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
|
-
[](https://www.npmjs.com/package/@ray/ray-ipc-utils) [](https://www.npmjs.com/package/@ray/ray-ipc-utils)
|
|
5
|
+
[](https://www.npmjs.com/package/@ray-js/ray-ipc-utils) [](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
|
-
##
|
|
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 {
|
|
20
|
+
import { goToIpcPageNativeRoute } from '@ray-js/ray-ipc-utils';
|
|
111
21
|
|
|
112
|
-
const
|
|
22
|
+
const id = 'ipc_album_panel';
|
|
23
|
+
const deviceId = '1234567890xxxxxx';
|
|
113
24
|
|
|
114
|
-
|
|
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.
|
package/lib/interface.d.ts
CHANGED
|
@@ -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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IRes } from '
|
|
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
|
|
11
|
+
* 需引入DeviceKit
|
|
12
12
|
* @param deviceId
|
|
13
13
|
* @returns
|
|
14
14
|
*/
|
package/lib/kit/device/index.js
CHANGED
|
@@ -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
|
|
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
|
package/lib/kit/ipc/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IRes } from '
|
|
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?:
|
|
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 日志字符串
|
package/lib/kit/ipc/index.js
CHANGED
|
@@ -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] :
|
|
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
|
package/lib/service/index.d.ts
CHANGED
package/lib/service/index.js
CHANGED
|
@@ -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: 对讲模式
|
package/package.json
CHANGED
package/lib/kit/interface.d.ts
DELETED
|
@@ -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
|
-
}
|
package/lib/kit/interface.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|