@ray-js/ray-ipc-utils 1.1.0-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 ADDED
@@ -0,0 +1,126 @@
1
+ [English](./README.md) | 简体中文
2
+
3
+ # @ray/ray-ipc-utils
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)
6
+
7
+ > IPC utility library
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ $ npm install @ray-js/ray-ipc-utils
13
+ // or
14
+ $ yarn add @ray-js/ray-ipc-utils
15
+ ```
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
+ 示例
108
+
109
+ ```tsx
110
+ import { openPanel } from '@ray/ray-ipc-utils';
111
+
112
+ const emitMessage = useEmitMessage();
113
+
114
+ useEmitMessage({
115
+ type: 'exitMiniProgram',
116
+ });
117
+ ```
118
+
119
+ ### 其他方法
120
+
121
+ | 方法名称 | 描述 | 返回值类型 |
122
+ | ------------ | ------------- | ---------- |
123
+ | isIos | 是否 ios 系统 | boolean |
124
+ | isIphoneX | 是否 iPhoneX | boolean |
125
+ | smallScreen | 是否小屏幕 | boolean |
126
+ | middleScreen | 是否中屏幕 | boolean |
@@ -0,0 +1 @@
1
+ export * from './useTrafficViewTip';
@@ -0,0 +1,2 @@
1
+ // hooks相关分类
2
+ export * from './useTrafficViewTip';
@@ -0,0 +1 @@
1
+ export declare const useTrafficViewTip: () => boolean;
@@ -0,0 +1,3 @@
1
+ export const useTrafficViewTip = () => {
2
+ return false;
3
+ };
@@ -0,0 +1,14 @@
1
+ export const tuya = {
2
+ backgroundColor: '#f2f4f6',
3
+ navigationBarTitleText: 'Ray 跨端组件'
4
+ };
5
+ export const wechat = {
6
+ backgroundColor: '#f2f4f6',
7
+ navigationBarTitleText: 'Ray 跨端组件'
8
+ };
9
+ export const native = {
10
+ backgroundColor: 'transparent',
11
+ isBleOfflineOverlay: false,
12
+ useSafeAreaView: true,
13
+ navigationBarTitleText: 'Ray 跨端组件'
14
+ };
package/lib/index.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ declare const IpcUtils: {
2
+ getCameraConfigInfo: (deviceId: string) => Promise<import("./interface").IpcConfigInfo>;
3
+ getCollectionPointsInfo: (deviceId: string) => Promise<any>;
4
+ updateCollectionPointsInfo: (deviceId: string, id: number, name: string) => Promise<any>;
5
+ delCollectionPointsInfo: (deviceId: string, pointData: [{
6
+ devId: string;
7
+ mpId: number;
8
+ }]) => Promise<import("./kit/interface").IRes>;
9
+ addCollectionPointsInfo: (deviceId: string, name: string) => Promise<any>;
10
+ getServiceUrl: (deviceId: string, serveType: import("./interface").ServeTpe, paramData?: Record<string, any>, action?: boolean, utm_rtid?: string) => Promise<{
11
+ code: number;
12
+ msg?: string | undefined;
13
+ url?: string | undefined;
14
+ type?: number | undefined;
15
+ }>;
16
+ JsonUtil: any;
17
+ getInitUtmTid: () => string;
18
+ getDevInfo: <T>(deviceId: string) => Promise<import("./kit/interface").IRes>;
19
+ getNativeStorage: <T_1>(key: string) => Promise<import("./kit/interface").IRes>;
20
+ setNativeStorage: <T_2>(key: string, data: T_2) => Promise<import("./kit/interface").IRes>;
21
+ removeNativeStorage: <T_3>(key: string) => Promise<import("./kit/interface").IRes>;
22
+ publishDps: <T_4>(deviceId: string, dps: T_4) => Promise<import("./kit/interface").IRes>;
23
+ getDpStateValue: (deviceId: string, dpCode: string) => Promise<import("./kit/interface").IRes>;
24
+ getDpIdByCode: (deviceId: string, dpCode: string) => Promise<import("./kit/interface").IRes>;
25
+ goToMiniProgramByShortLink: <T_5>(url: string, position?: string) => Promise<import("./kit/interface").IRes>;
26
+ getVideoBitrateKbps: <T_6>(deviceId: string, extendParam?: {}) => Promise<import("./kit/interface").IRes>;
27
+ networkStatusDidChangedEvent: (callback: any) => void;
28
+ getMobileOrientation: <T_7>() => Promise<import("./kit/interface").IRes>;
29
+ jumpToWebView: <T_8>(url: string) => Promise<import("./kit/interface").IRes>;
30
+ setScreenOrientation: <T_9>(pageOrientation: string) => Promise<import("./kit/interface").IRes>;
31
+ isSupportFloatWindow: <T_10>(deviceId: string, extendParam?: {}) => Promise<import("./kit/interface").IRes>;
32
+ openFloatWindow: <T_11>(deviceId: string, extendParam?: {}) => Promise<import("./kit/interface").IRes>;
33
+ isSupportedTalk: <T_12>(deviceId: string, extendParam?: {}) => Promise<import("./kit/interface").IRes>;
34
+ getCurrentSupportedTalkMode: <T_13>(deviceId: string, extendParam?: {}) => Promise<import("./kit/interface").IRes>;
35
+ goToIpcPageNativeRoute: (url: string, deviceId: string, theme?: "dark" | "light", extraParams?: {
36
+ [key: string]: any;
37
+ } | undefined, isGeneral?: false | undefined) => Promise<import("./kit/interface").IRes>;
38
+ goToGeneralHelpMini: () => Promise<import("./kit/interface").IRes>;
39
+ goToIpcHelpMini: (errCode: number, deviceId: string, helpNum: number, helpFeedBack: boolean, brandColor?: string) => Promise<import("./kit/interface").IRes>;
40
+ requestWifiSignal: <T_14>(deviceId: string, dps?: {}) => Promise<import("./kit/interface").IRes>;
41
+ wakeUpDevice: <T_15>(deviceId: string, dps?: {}) => Promise<import("./kit/interface").IRes>;
42
+ useTrafficViewTip: () => boolean;
43
+ };
44
+ export default IpcUtils;
package/lib/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import * as hooks from './hooks';
3
+ import * as kit from './kit';
4
+ import * as utils from './utils';
5
+ import * as service from './service';
6
+ const IpcUtils = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, hooks), kit), utils), service);
7
+ export default IpcUtils;
@@ -0,0 +1,5 @@
1
+ .text {
2
+ color: #000;
3
+ font-size: 48rpx;
4
+ font-weight: bold;
5
+ }
@@ -0,0 +1,63 @@
1
+ export declare enum ClarityType {
2
+ SS = "SS",
3
+ SD = "SD",
4
+ HD = "HD",
5
+ UD = "UD",
6
+ SSP = "SSP",
7
+ AUDIO = "AUDIO"
8
+ }
9
+ export declare enum IntercomMode {
10
+ OneWay = "OneWay",
11
+ TwoWay = "TwoWay"
12
+ }
13
+ export declare enum ServeTpe {
14
+ trafficService = "traffic_service",
15
+ securityCloudService = "security_cloud_service",
16
+ aiService = "ai_service",
17
+ aiInspectionReport = "aiInspectionReport"
18
+ }
19
+ export declare enum MuteMode {
20
+ ON = "ON",
21
+ OFF = "OFF"
22
+ }
23
+ export interface IpcConfigInfo {
24
+ /**
25
+ * 清晰度信息
26
+ */
27
+ videoResolution: {
28
+ /** 默认清晰度 */
29
+ defaultResolution: ClarityType;
30
+ /** 缓存的清晰度 */
31
+ cachedResolution: ClarityType;
32
+ /** 支持的清晰度列表 */
33
+ availableResolutions: ClarityType[];
34
+ };
35
+ /**
36
+ * 对讲设置信息
37
+ */
38
+ intercomInfo: {
39
+ /** 是否支持对讲 */
40
+ isIntercomSupported: boolean;
41
+ /** 默认对讲方式 */
42
+ defaultIntercomMode: IntercomMode;
43
+ /** 缓存的对讲方式 */
44
+ cachedIntercomMode: IntercomMode;
45
+ /** 支持的对讲方式 */
46
+ supportedIntercomModes: IntercomMode[];
47
+ };
48
+ /**
49
+ * 拾音器信息
50
+ */
51
+ microphoneSettings: {
52
+ /** 是否支持拾音 */
53
+ isMicrophoneSupported: boolean;
54
+ /** 默认拾音模式 */
55
+ defaultMuteMode: MuteMode;
56
+ /** 缓存的拾音模式 */
57
+ cachedMuteMode: MuteMode;
58
+ };
59
+ /**
60
+ * 最大放大倍数
61
+ */
62
+ maxZoomSettings: number;
63
+ }
@@ -0,0 +1,26 @@
1
+ export let ClarityType = /*#__PURE__*/function (ClarityType) {
2
+ ClarityType["SS"] = "SS";
3
+ ClarityType["SD"] = "SD";
4
+ ClarityType["HD"] = "HD";
5
+ ClarityType["UD"] = "UD";
6
+ ClarityType["SSP"] = "SSP";
7
+ ClarityType["AUDIO"] = "AUDIO";
8
+ return ClarityType;
9
+ }({}); // 音频模式
10
+ export let IntercomMode = /*#__PURE__*/function (IntercomMode) {
11
+ IntercomMode["OneWay"] = "OneWay";
12
+ IntercomMode["TwoWay"] = "TwoWay";
13
+ return IntercomMode;
14
+ }({});
15
+ export let ServeTpe = /*#__PURE__*/function (ServeTpe) {
16
+ ServeTpe["trafficService"] = "traffic_service";
17
+ ServeTpe["securityCloudService"] = "security_cloud_service";
18
+ ServeTpe["aiService"] = "ai_service";
19
+ ServeTpe["aiInspectionReport"] = "aiInspectionReport";
20
+ return ServeTpe;
21
+ }({});
22
+ export let MuteMode = /*#__PURE__*/function (MuteMode) {
23
+ MuteMode["ON"] = "ON";
24
+ MuteMode["OFF"] = "OFF";
25
+ return MuteMode;
26
+ }({});
@@ -0,0 +1,15 @@
1
+ import { IRes } from '../interface';
2
+ /**
3
+ * 获取信号强度
4
+ * @param deviceId
5
+ * @param dps 扩展参数
6
+ * @returns
7
+ */
8
+ export declare const requestWifiSignal: <T>(deviceId: string, dps?: {}) => Promise<IRes>;
9
+ /**
10
+ * IPC-低功耗唤醒:低功耗唤醒,唤醒门铃设备
11
+ * 需引入DeviceKit,且在>=3.1.0-ipcwake.1版本才可使用
12
+ * @param deviceId
13
+ * @returns
14
+ */
15
+ export declare const wakeUpDevice: <T>(deviceId: string, dps?: {}) => Promise<IRes>;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * 获取信号强度
3
+ * @param deviceId
4
+ * @param dps 扩展参数
5
+ * @returns
6
+ */
7
+ export const requestWifiSignal = function (deviceId) {
8
+ let dps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9
+ return new Promise(resolve => {
10
+ try {
11
+ ty.device.requestWifiSignal({
12
+ deviceId,
13
+ dps: dps,
14
+ success: res => {
15
+ resolve({
16
+ code: 0,
17
+ data: res
18
+ });
19
+ },
20
+ fail: err => {
21
+ resolve({
22
+ code: -1,
23
+ msg: err
24
+ });
25
+ }
26
+ });
27
+ } catch (err) {
28
+ resolve({
29
+ code: -1,
30
+ msg: String(err)
31
+ });
32
+ }
33
+ });
34
+ };
35
+
36
+ /**
37
+ * IPC-低功耗唤醒:低功耗唤醒,唤醒门铃设备
38
+ * 需引入DeviceKit,且在>=3.1.0-ipcwake.1版本才可使用
39
+ * @param deviceId
40
+ * @returns
41
+ */
42
+ export const wakeUpDevice = function (deviceId) {
43
+ let dps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
44
+ return new Promise(resolve => {
45
+ try {
46
+ ty.device.wakeUpDevice({
47
+ deviceId,
48
+ dps: dps,
49
+ success: res => {
50
+ resolve({
51
+ data: res
52
+ });
53
+ },
54
+ fail: error => {
55
+ resolve({
56
+ code: -1,
57
+ msg: error
58
+ });
59
+ }
60
+ });
61
+ } catch (err) {
62
+ resolve({
63
+ code: -1,
64
+ msg: String(err)
65
+ });
66
+ }
67
+ });
68
+ };
@@ -0,0 +1,2 @@
1
+ export * from './ipc';
2
+ export * from './device';
@@ -0,0 +1,2 @@
1
+ export * from './ipc';
2
+ export * from './device';
@@ -0,0 +1,13 @@
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 {
10
+ code?: number;
11
+ data?: any;
12
+ msg?: IApiError | string | boolean;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,124 @@
1
+ import { IRes } from '../interface';
2
+ /**
3
+ *
4
+ * @param deviceId 设备id
5
+ * @returns 获取设备信息
6
+ */
7
+ export declare const getDevInfo: <T>(deviceId: string) => Promise<IRes>;
8
+ /**
9
+ * 获取本地缓存
10
+ * @param key 保存的key属性
11
+ *
12
+ */
13
+ export declare const getNativeStorage: <T>(key: string) => Promise<IRes>;
14
+ /**
15
+ * 存储数据到本地缓存
16
+ * @param key 保存的key属性
17
+ *
18
+ */
19
+ export declare const setNativeStorage: <T>(key: string, data: T) => Promise<IRes>;
20
+ /**
21
+ * 清除本地缓存
22
+ * @param key 保存的key属性
23
+ *
24
+ */
25
+ export declare const removeNativeStorage: <T>(key: string) => Promise<IRes>;
26
+ /**
27
+ * DP点下发, 包含针对低功耗设备情况下的DP点下发
28
+ * @param key 保存的key属性
29
+ *
30
+ */
31
+ export declare const publishDps: <T>(deviceId: string, dps: T) => Promise<IRes>;
32
+ /**
33
+ * 根据DPCode获取最新的DP点的值
34
+ * @param key 保存的key属性
35
+ *
36
+ */
37
+ export declare const getDpStateValue: (deviceId: string, dpCode: string) => Promise<IRes>;
38
+ /**
39
+ * 根据DPCode获取DpId
40
+ * @param key 保存的key属性
41
+ *
42
+ */
43
+ export declare const getDpIdByCode: (deviceId: string, dpCode: string) => Promise<IRes>;
44
+ /**
45
+ * 通过短链形式跳转小程序
46
+ * @param url 小程序链接
47
+ * @param position 弹出位置 bottom|right
48
+ *
49
+ */
50
+ export declare const goToMiniProgramByShortLink: <T>(url: string, position?: string) => Promise<IRes>;
51
+ /**
52
+ * 获取视频码率
53
+ * @param deviceId
54
+ * @param extendParam 扩展参数
55
+ * @returns
56
+ */
57
+ export declare const getVideoBitrateKbps: <T>(deviceId: string, extendParam?: {}) => Promise<IRes>;
58
+ export declare const networkStatusDidChangedEvent: (callback: any) => void;
59
+ /**
60
+ * 获取手机当前横竖屏状态
61
+ * 需引入IPCKit,且在>=1.0.0-TTT432.1版本才可使用
62
+ * @returns
63
+ */
64
+ export declare const getMobileOrientation: <T>() => Promise<IRes>;
65
+ /**
66
+ * 跳转到webView
67
+ * @param key 保存的key属性
68
+ *
69
+ */
70
+ export declare const jumpToWebView: <T>(url: string) => Promise<IRes>;
71
+ export declare const setScreenOrientation: <T>(pageOrientation: string) => Promise<IRes>;
72
+ /**
73
+ * 画中画:是否支持画中画:只有安卓在用
74
+ * @param deviceId
75
+ * @param extendParam 扩展参数
76
+ * @returns
77
+ */
78
+ export declare const isSupportFloatWindow: <T>(deviceId: string, extendParam?: {}) => Promise<IRes>;
79
+ /**
80
+ * 画中画:开启画中画
81
+ * @param deviceId
82
+ * @param extendParam 扩展参数
83
+ * @returns
84
+ */
85
+ export declare const openFloatWindow: <T>(deviceId: string, extendParam?: {}) => Promise<IRes>;
86
+ /**
87
+ * IPC-APP 缓存支持的对讲方式:是否支持对讲
88
+ * @param deviceId
89
+ * @param extendParam 扩展参数
90
+ * @returns
91
+ */
92
+ export declare const isSupportedTalk: <T>(deviceId: string, extendParam?: {}) => Promise<IRes>;
93
+ /**
94
+ * 设备支持的对讲模式
95
+ * @param deviceId
96
+ * @param extendParam 扩展参数
97
+ * @returns 设备支持的对讲模式。回掉方法的参数为数值型,0 未知;1:单向对讲;2:双向对讲。
98
+ */
99
+ export declare const getCurrentSupportedTalkMode: <T>(deviceId: string, extendParam?: {}) => Promise<IRes>;
100
+ /**
101
+ * 跳转 APP 原生页面
102
+ * @param {string} url 页面路由
103
+ * @param {string} deviceId 设备Id
104
+ * @param {string} theme 主题 dark|light 默认取APP 主题色
105
+ * @param {Object} extraParams 额外参数, 额外页面需要单独拼接的参数
106
+ * @param {boolean} isGeneral 是否为通用页面,IPC原生业务页面不用传, 默认false
107
+ *
108
+ */
109
+ export declare const goToIpcPageNativeRoute: (url: string, deviceId: string, theme?: 'dark' | 'light', extraParams?: {
110
+ [key: string]: any;
111
+ } | undefined, isGeneral?: false) => Promise<IRes>;
112
+ /**
113
+ * 跳转 通用帮助反馈小程序
114
+ */
115
+ export declare const goToGeneralHelpMini: () => Promise<IRes>;
116
+ /**
117
+ * 跳转 Ipc帮助反馈小程序
118
+ * @param {number} errCode 错误码
119
+ * @param {string} deviceId 设备id
120
+ * @param {number} helpNum 帮助编号
121
+ * @param {boolean} helpFeedBack 是否是反馈
122
+ * @param {string} brandColor 品牌色
123
+ */
124
+ export declare const goToIpcHelpMini: (errCode: number, deviceId: string, helpNum: number, helpFeedBack: boolean, brandColor?: string) => Promise<IRes>;