@ray-js/ipc-player-integration 0.0.1-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.
Files changed (108) hide show
  1. package/README.md +32 -0
  2. package/lib/core.d.ts +0 -0
  3. package/lib/core.js +0 -0
  4. package/lib/ctx/ctx.composition.d.ts +1 -0
  5. package/lib/ctx/ctx.composition.js +38 -0
  6. package/lib/ctx/ctx.d.ts +10 -0
  7. package/lib/ctx/ctx.js +159 -0
  8. package/lib/ctx/ctx.test.d.ts +1 -0
  9. package/lib/ctx/ctx.test.js +95 -0
  10. package/lib/ctx/index.d.ts +2 -0
  11. package/lib/ctx/index.js +2 -0
  12. package/lib/ctx/ports.output.d.ts +1 -0
  13. package/lib/ctx/ports.output.js +1 -0
  14. package/lib/ctx/useCtx.d.ts +0 -0
  15. package/lib/ctx/useCtx.js +0 -0
  16. package/lib/hooks/index.d.ts +5 -0
  17. package/lib/hooks/index.js +5 -0
  18. package/lib/hooks/useBattery/index.d.ts +2 -0
  19. package/lib/hooks/useBattery/index.js +17 -0
  20. package/lib/hooks/useDpState/index.d.ts +1 -0
  21. package/lib/hooks/useDpState/index.js +1 -0
  22. package/lib/hooks/useDpState/useDpState.d.ts +6 -0
  23. package/lib/hooks/useDpState/useDpState.js +79 -0
  24. package/lib/hooks/useHumidity/index.d.ts +1 -0
  25. package/lib/hooks/useHumidity/index.js +16 -0
  26. package/lib/hooks/useMuted/index.d.ts +1 -0
  27. package/lib/hooks/useMuted/index.js +3 -0
  28. package/lib/hooks/useTemperature/index.d.ts +5 -0
  29. package/lib/hooks/useTemperature/index.js +30 -0
  30. package/lib/hooks/useVideoBitKbps/index.d.ts +1 -0
  31. package/lib/hooks/useVideoBitKbps/index.js +44 -0
  32. package/lib/iconfont/demo.css +539 -0
  33. package/lib/iconfont/demo_index.html +556 -0
  34. package/lib/iconfont/iconfont.css +79 -0
  35. package/lib/iconfont/iconfont.js +42 -0
  36. package/lib/iconfont/iconfont.json +121 -0
  37. package/lib/iconfont/iconfont.ttf +0 -0
  38. package/lib/iconfont/iconfont.woff +0 -0
  39. package/lib/iconfont/iconfont.woff2 +0 -0
  40. package/lib/index.config.js +14 -0
  41. package/lib/index.d.ts +3 -0
  42. package/lib/index.js +3 -0
  43. package/lib/index.less +7 -0
  44. package/lib/interface.d.ts +59 -0
  45. package/lib/interface.js +19 -0
  46. package/lib/plugins/battery/battery.composition.d.ts +27 -0
  47. package/lib/plugins/battery/battery.composition.js +5 -0
  48. package/lib/plugins/battery/battery.d.ts +13 -0
  49. package/lib/plugins/battery/battery.js +39 -0
  50. package/lib/plugins/battery/battery.less +67 -0
  51. package/lib/plugins/battery/index.d.ts +1 -0
  52. package/lib/plugins/battery/index.js +1 -0
  53. package/lib/plugins/fullScreen/fullScreen.d.ts +6 -0
  54. package/lib/plugins/fullScreen/fullScreen.js +71 -0
  55. package/lib/plugins/fullScreen/fullScreen.less +16 -0
  56. package/lib/plugins/fullScreen/index.d.ts +1 -0
  57. package/lib/plugins/fullScreen/index.js +1 -0
  58. package/lib/plugins/fullScreen/verticalScreen.d.ts +8 -0
  59. package/lib/plugins/fullScreen/verticalScreen.js +15 -0
  60. package/lib/plugins/fullScreen/verticalScreen.less +11 -0
  61. package/lib/plugins/index.d.ts +8 -0
  62. package/lib/plugins/index.js +8 -0
  63. package/lib/plugins/muted/index.d.ts +1 -0
  64. package/lib/plugins/muted/index.js +1 -0
  65. package/lib/plugins/muted/muted.d.ts +4 -0
  66. package/lib/plugins/muted/muted.js +42 -0
  67. package/lib/plugins/muted/muted.less +5 -0
  68. package/lib/plugins/recordVideo/index.d.ts +1 -0
  69. package/lib/plugins/recordVideo/index.js +1 -0
  70. package/lib/plugins/recordVideo/recordVideo.d.ts +6 -0
  71. package/lib/plugins/recordVideo/recordVideo.js +93 -0
  72. package/lib/plugins/recordVideo/recordVideo.less +37 -0
  73. package/lib/plugins/screenshot/index.d.ts +1 -0
  74. package/lib/plugins/screenshot/index.js +1 -0
  75. package/lib/plugins/screenshot/screenshot.d.ts +6 -0
  76. package/lib/plugins/screenshot/screenshot.js +55 -0
  77. package/lib/plugins/screenshot/screenshot.less +38 -0
  78. package/lib/plugins/tempHumidity/index.d.ts +1 -0
  79. package/lib/plugins/tempHumidity/index.js +1 -0
  80. package/lib/plugins/tempHumidity/tempHumidity.d.ts +8 -0
  81. package/lib/plugins/tempHumidity/tempHumidity.js +54 -0
  82. package/lib/plugins/tempHumidity/tempHumidity.less +21 -0
  83. package/lib/plugins/videoBitKbps/index.d.ts +1 -0
  84. package/lib/plugins/videoBitKbps/index.js +1 -0
  85. package/lib/plugins/videoBitKbps/videoBitKbps.d.ts +6 -0
  86. package/lib/plugins/videoBitKbps/videoBitKbps.js +13 -0
  87. package/lib/plugins/videoBitKbps/videoBitKbps.less +11 -0
  88. package/lib/plugins/voiceIntercom/index.d.ts +1 -0
  89. package/lib/plugins/voiceIntercom/index.js +1 -0
  90. package/lib/plugins/voiceIntercom/voiceIntercom.d.ts +9 -0
  91. package/lib/plugins/voiceIntercom/voiceIntercom.js +67 -0
  92. package/lib/plugins/voiceIntercom/voiceIntercom.less +10 -0
  93. package/lib/ports.output.d.ts +6 -0
  94. package/lib/ports.output.js +1 -0
  95. package/lib/props.d.ts +14 -0
  96. package/lib/props.js +1 -0
  97. package/lib/ui/index.d.ts +1 -0
  98. package/lib/ui/index.js +1 -0
  99. package/lib/ui/ui.d.ts +21 -0
  100. package/lib/ui/ui.js +121 -0
  101. package/lib/ui/ui.less +44 -0
  102. package/lib/utils/authorize/index.d.ts +1 -0
  103. package/lib/utils/authorize/index.js +31 -0
  104. package/lib/utils/content/dpCode.d.ts +4 -0
  105. package/lib/utils/content/dpCode.js +7 -0
  106. package/lib/utils/device/index.d.ts +13 -0
  107. package/lib/utils/device/index.js +68 -0
  108. package/package.json +74 -0
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ English | [简体中文](./README-zh_CN.md)
2
+
3
+ # @ray-js/ipc-player-integration
4
+
5
+ [![latest](https://img.shields.io/npm/v/@ray-js/ipc-player-integration/latest.svg)](https://www.npmjs.com/package/@ray-js/ipc-player-integration) [![download](https://img.shields.io/npm/dt/@ray-js/ipc-player-integration.svg)](https://www.npmjs.com/package/@ray-js/ipc-player-integration)
6
+
7
+ > IPC 播放器功能集成
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ $ npm install @ray-js/ipc-player-integration
13
+ # or
14
+ $ yarn add @ray-js/ipc-player-integration
15
+ ```
16
+
17
+ ## Develop
18
+
19
+ ```sh
20
+ # install deps
21
+ yarn
22
+
23
+ # watch compile demo
24
+ yarn start:tuya
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```tsx
30
+ import Foo from '@ray-js/ipc-player-integration';
31
+ export default () => <Foo />;
32
+ ```
package/lib/core.d.ts ADDED
File without changes
package/lib/core.js ADDED
File without changes
@@ -0,0 +1 @@
1
+ export declare const useCtx: import("../interface").UseCtx;
@@ -0,0 +1,38 @@
1
+ import { createUseCtx } from './ctx';
2
+ import { Battery, Screenshot, TempHumidity, RecordVideo, FullScreen, VideoBitKbps, Muted } from '../plugins';
3
+ const createPlayContext = ty.createIpcPlayerContext;
4
+ // const createPlayContext = () => null;
5
+
6
+ const topContent = [{
7
+ id: 'Battery',
8
+ content: Battery,
9
+ initProps: {
10
+ className: 1
11
+ }
12
+ }, {
13
+ id: 'TempHumidity',
14
+ content: TempHumidity
15
+ }, {
16
+ id: 'VideoBitKbps',
17
+ content: VideoBitKbps
18
+ }];
19
+ const absoluteContent = [];
20
+ const bottomContent = [{
21
+ id: 'Screenshot',
22
+ content: Screenshot
23
+ }, {
24
+ id: 'RecordVideo',
25
+ content: RecordVideo
26
+ }, {
27
+ id: 'Muted',
28
+ content: Muted
29
+ }, {
30
+ id: 'FullScreen',
31
+ content: FullScreen
32
+ }];
33
+ export const useCtx = createUseCtx({
34
+ createPlayContext,
35
+ defaultTopContent: topContent,
36
+ defaultAbsoluteContent: absoluteContent,
37
+ defaultBottomContent: bottomContent
38
+ });
@@ -0,0 +1,10 @@
1
+ import { ComponentConfig, UseCtx } from '../interface';
2
+ import type { createPlayContext } from './ports.output';
3
+ type Depend = {
4
+ createPlayContext: createPlayContext;
5
+ defaultTopContent?: ComponentConfig[];
6
+ defaultBottomContent?: ComponentConfig[];
7
+ defaultAbsoluteContent?: ComponentConfig[];
8
+ };
9
+ export declare const createUseCtx: ({ createPlayContext, defaultTopContent, defaultBottomContent, defaultAbsoluteContent, }: Depend) => UseCtx;
10
+ export {};
package/lib/ctx/ctx.js ADDED
@@ -0,0 +1,159 @@
1
+ import { useState, useRef } from 'react';
2
+ import { authorizeStatus } from '../utils/authorize';
3
+ import { PlayState } from '../interface';
4
+ const SAVE_TO_ALBUM = 1;
5
+ export const createUseCtx = _ref => {
6
+ let {
7
+ createPlayContext,
8
+ defaultTopContent,
9
+ defaultBottomContent,
10
+ defaultAbsoluteContent
11
+ } = _ref;
12
+ return _ref2 => {
13
+ let {
14
+ devId,
15
+ initTopContent,
16
+ initBottomContent,
17
+ initAbsoluteContent,
18
+ saveToAlbum = SAVE_TO_ALBUM
19
+ } = _ref2;
20
+ const streamStatus = useRef();
21
+ // 全屏、竖屏
22
+ const [screenType, setScreenType] = useState('vertical');
23
+ // 录像中
24
+ const [recording, setRecording] = useState(false);
25
+ // 静音
26
+ const [mute, setMute] = useState(false);
27
+ // 对讲中
28
+ const [intercom, setIntercom] = useState(false);
29
+ const [playState, setPlayState] = useState(PlayState.CONNECTING);
30
+ const [topContent, setTopContent] = useState(initTopContent || defaultTopContent || []);
31
+ const [bottomContent, setBottomContent] = useState(initBottomContent || defaultBottomContent || []);
32
+ const [absoluteContent, setAbsoluteContent] = useState(initAbsoluteContent || defaultAbsoluteContent || []);
33
+ const IPCPlayerInstance = useRef();
34
+ if (!IPCPlayerInstance.current) {
35
+ IPCPlayerInstance.current = createPlayContext(devId);
36
+ }
37
+ return {
38
+ devId,
39
+ saveToAlbum,
40
+ screenType,
41
+ recording,
42
+ mute,
43
+ intercom,
44
+ playState,
45
+ setPlayState,
46
+ setIntercom: async target => {
47
+ const res = await authorizeStatus('scope.record');
48
+ if (!res) return false;
49
+ return new Promise((resolve, reject) => {
50
+ if (target) {
51
+ IPCPlayerInstance.current.startTalk({
52
+ success: () => {
53
+ setIntercom(true);
54
+ resolve(true);
55
+ },
56
+ fail: err => {
57
+ reject(err);
58
+ }
59
+ });
60
+ } else {
61
+ IPCPlayerInstance.current.stopTalk({
62
+ success: () => {
63
+ setIntercom(false);
64
+ resolve(true);
65
+ },
66
+ fail: err => {
67
+ setIntercom(true);
68
+ reject(err);
69
+ }
70
+ });
71
+ }
72
+ });
73
+ },
74
+ setMute: async target => {
75
+ return new Promise((resolve, reject) => {
76
+ setMute(target);
77
+ IPCPlayerInstance.current.setMuted({
78
+ mute: target,
79
+ success: () => {
80
+ setMute(true);
81
+ resolve(true);
82
+ },
83
+ fail: err => {
84
+ setMute(!target);
85
+ reject(err);
86
+ }
87
+ });
88
+ });
89
+ },
90
+ setRecording: async target => {
91
+ const res = await authorizeStatus('scope.writePhotosAlbum');
92
+ if (!res) return false;
93
+ return new Promise((resolve, reject) => {
94
+ if (target) {
95
+ IPCPlayerInstance.current.startRecord({
96
+ saveToAlbum,
97
+ success: () => {
98
+ setRecording(true);
99
+ resolve(true);
100
+ },
101
+ fail: err => {
102
+ reject(err);
103
+ }
104
+ });
105
+ } else {
106
+ IPCPlayerInstance.current.stopRecord({
107
+ saveToAlbum,
108
+ success: () => {
109
+ setRecording(false);
110
+ resolve(true);
111
+ },
112
+ fail: err => {
113
+ setRecording(true);
114
+ reject(err);
115
+ }
116
+ });
117
+ }
118
+ });
119
+ },
120
+ setScreenType,
121
+ topContent,
122
+ bottomContent,
123
+ absoluteContent,
124
+ addContent: (type, config) => {
125
+ function createNewData(originData, newData) {
126
+ if (newData instanceof Array) return [...originData, ...newData];
127
+ return [...originData, newData];
128
+ }
129
+ if (type === 'top') {
130
+ setTopContent(createNewData(topContent, config));
131
+ } else if (type === 'bottom') {
132
+ setBottomContent(createNewData(bottomContent, config));
133
+ } else {
134
+ setAbsoluteContent(createNewData(absoluteContent, config));
135
+ }
136
+ },
137
+ deleteContent: (type, id) => {
138
+ let newData;
139
+ if (type === 'top') {
140
+ newData = topContent.filter(item => item.id !== id);
141
+ setTopContent(newData);
142
+ } else if (type === 'bottom') {
143
+ newData = bottomContent.filter(item => item.id !== id);
144
+ setBottomContent(newData);
145
+ } else {
146
+ newData = absoluteContent.filter(item => item.id !== id);
147
+ setAbsoluteContent(newData);
148
+ }
149
+ },
150
+ IPCPlayerInstance: IPCPlayerInstance.current,
151
+ changeStreamStatus: status => {
152
+ streamStatus.current = status;
153
+ },
154
+ getStreamStatus: () => {
155
+ return streamStatus.current;
156
+ }
157
+ };
158
+ };
159
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,95 @@
1
+ import { act, renderHook } from '@testing-library/react-hooks';
2
+ import { createUseCtx } from './ctx';
3
+ describe('createCtx', () => {
4
+ it('init props', () => {
5
+ const topContent = {
6
+ id: 'top',
7
+ content: () => null
8
+ };
9
+ const bottomContent = {
10
+ id: 'bottom',
11
+ content: () => null,
12
+ initProps: {
13
+ name: 1
14
+ }
15
+ };
16
+ const IPCPlayerContext = {
17
+ name: 'IPCPlayerContext'
18
+ };
19
+ const useCtx = createUseCtx({
20
+ createPlayContext: () => IPCPlayerContext,
21
+ defaultTopContent: [topContent],
22
+ defaultAbsoluteContent: [{
23
+ id: 'absolute',
24
+ content: () => null,
25
+ initProps: {
26
+ name: 2
27
+ }
28
+ }]
29
+ });
30
+ const {
31
+ result
32
+ } = renderHook(() => useCtx({
33
+ devId: 'devId',
34
+ initBottomContent: [bottomContent],
35
+ initAbsoluteContent: []
36
+ }));
37
+ expect(result.current.topContent).toEqual([topContent]);
38
+ expect(result.current.bottomContent).toEqual([bottomContent]);
39
+ expect(result.current.absoluteContent).toEqual([]);
40
+ expect(result.current.IPCPlayerInstance).toBe(IPCPlayerContext);
41
+ });
42
+ it('createCtx, add a content and delete content', () => {
43
+ const useCtx = createUseCtx({
44
+ createPlayContext: () => null
45
+ });
46
+ const {
47
+ result
48
+ } = renderHook(() => useCtx({
49
+ devId: 'devId'
50
+ }));
51
+ const topContent = {
52
+ id: 'top',
53
+ content: () => null
54
+ };
55
+ const bottomContent = {
56
+ id: 'bottom',
57
+ content: () => null,
58
+ initProps: {
59
+ name: 1
60
+ }
61
+ };
62
+ act(() => {
63
+ result.current.addContent('top', topContent);
64
+ result.current.addContent('bottom', bottomContent);
65
+ });
66
+ expect(result.current.topContent).toEqual([topContent]);
67
+ expect(result.current.bottomContent).toEqual([bottomContent]);
68
+ act(() => {
69
+ result.current.deleteContent('bottom', 'bottom');
70
+ });
71
+ expect(result.current.bottomContent).toEqual([]);
72
+ });
73
+ it('add content list', () => {
74
+ const useCtx = createUseCtx({
75
+ createPlayContext: () => null
76
+ });
77
+ const {
78
+ result
79
+ } = renderHook(() => useCtx({
80
+ devId: 'devId'
81
+ }));
82
+ const topContent1 = {
83
+ id: 'top1',
84
+ content: () => null
85
+ };
86
+ const topContent2 = {
87
+ id: 'top2',
88
+ content: () => null
89
+ };
90
+ act(() => {
91
+ result.current.addContent('top', [topContent1, topContent2]);
92
+ });
93
+ expect(result.current.topContent).toEqual([topContent1, topContent2]);
94
+ });
95
+ });
@@ -0,0 +1,2 @@
1
+ export * from './ctx';
2
+ export * from './ctx.composition';
@@ -0,0 +1,2 @@
1
+ export * from './ctx';
2
+ export * from './ctx.composition';
@@ -0,0 +1 @@
1
+ export type createPlayContext = (devId: string) => IpcContext;
@@ -0,0 +1 @@
1
+ export {};
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ export * from './useBattery';
2
+ export * from './useHumidity';
3
+ export * from './useTemperature';
4
+ export * from './useVideoBitKbps';
5
+ export * from './useDpState';
@@ -0,0 +1,5 @@
1
+ export * from './useBattery';
2
+ export * from './useHumidity';
3
+ export * from './useTemperature';
4
+ export * from './useVideoBitKbps';
5
+ export * from './useDpState';
@@ -0,0 +1,2 @@
1
+ import type { UseBattery } from '../../ports.output';
2
+ export declare const useBattery: UseBattery;
@@ -0,0 +1,17 @@
1
+ import { useMemo } from 'react';
2
+ import { useDpState } from '../useDpState';
3
+ const POWER_MODE_DP_CODE = 'wireless_powermode';
4
+ const POWER_VALUE_DP_CODE = 'wireless_electricity';
5
+ export const useBattery = devId => {
6
+ const [dpState] = useDpState({
7
+ devId,
8
+ dpCodes: [POWER_MODE_DP_CODE, POWER_VALUE_DP_CODE]
9
+ });
10
+ const batteryInfo = useMemo(() => {
11
+ return {
12
+ batteryValue: dpState[POWER_VALUE_DP_CODE] || 0,
13
+ batteryCharging: dpState[POWER_MODE_DP_CODE] || false
14
+ };
15
+ }, [dpState]);
16
+ return batteryInfo;
17
+ };
@@ -0,0 +1 @@
1
+ export * from './useDpState';
@@ -0,0 +1 @@
1
+ export * from './useDpState';
@@ -0,0 +1,6 @@
1
+ type Options<T> = {
2
+ devId: string;
3
+ dpCodes: T[];
4
+ };
5
+ export declare function useDpState<T extends string>(options: Options<T>): [Record<T, number | string | boolean>];
6
+ export {};
@@ -0,0 +1,79 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import { useState, useEffect, useRef, useCallback } from 'react';
3
+ import { getDeviceInfo, onDpDataChange, offDpDataChange } from '@ray-js/ray';
4
+ function getInitData(codes) {
5
+ return codes.reduce((ret, key) => {
6
+ return _objectSpread(_objectSpread({}, ret), {}, {
7
+ [key]: undefined
8
+ });
9
+ }, {});
10
+ }
11
+ export function useDpState(options) {
12
+ const {
13
+ devId,
14
+ dpCodes
15
+ } = options;
16
+ const codeMapToIdRef = useRef();
17
+ const [values, setValues] = useState(() => {
18
+ return getInitData(options.dpCodes);
19
+ });
20
+ const valueRef = useRef(values);
21
+ if (valueRef.current !== values) {
22
+ valueRef.current = values;
23
+ }
24
+ const listenDpChange = useCallback(e => {
25
+ if (e.deviceId === devId) {
26
+ const {
27
+ dps
28
+ } = e;
29
+ let hasChange = false;
30
+ const newValue = _objectSpread({}, valueRef.current);
31
+ Object.keys(dps).forEach(dpId => {
32
+ const dpCode = codeMapToIdRef.current[dpId];
33
+ const currentValue = dps[dpId];
34
+ if (dpCode && typeof currentValue !== 'undefined') {
35
+ hasChange = hasChange || true;
36
+ newValue[dpCode] = currentValue;
37
+ }
38
+ });
39
+ if (hasChange) {
40
+ setValues(newValue);
41
+ }
42
+ }
43
+ }, [devId]);
44
+ useEffect(() => {
45
+ getDeviceInfo({
46
+ deviceId: devId,
47
+ success: res => {
48
+ const {
49
+ schema
50
+ } = res;
51
+ const IdMapToCode = {};
52
+ let count = 0;
53
+ for (const schemaItem of schema) {
54
+ // @ts-ignore
55
+ if (dpCodes.includes(schemaItem.code)) {
56
+ // @ts-ignore
57
+ IdMapToCode[schemaItem.id] = schemaItem.code;
58
+ count += 1;
59
+ }
60
+ if (count >= dpCodes.length) break;
61
+ }
62
+ codeMapToIdRef.current = IdMapToCode;
63
+ const initValue = options.dpCodes.reduce((ret, key) => {
64
+ return _objectSpread(_objectSpread({}, ret), {}, {
65
+ [key]: res.dpCodes[key]
66
+ });
67
+ }, {});
68
+ setValues(initValue);
69
+ }
70
+ });
71
+ }, [options.devId]);
72
+ useEffect(() => {
73
+ onDpDataChange(listenDpChange);
74
+ return () => {
75
+ offDpDataChange(listenDpChange);
76
+ };
77
+ }, [listenDpChange]);
78
+ return [values];
79
+ }
@@ -0,0 +1 @@
1
+ export declare const useHumidity: (devId: string) => string;
@@ -0,0 +1,16 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { useDpState } from '../useDpState';
3
+ import { SENSOR_HUMIDITY } from '../../utils/content/dpCode';
4
+ export const useHumidity = devId => {
5
+ const [humidity, setHumidity] = useState('');
6
+ const [dpState] = useDpState({
7
+ devId,
8
+ dpCodes: [SENSOR_HUMIDITY]
9
+ });
10
+ useEffect(() => {
11
+ if (dpState[SENSOR_HUMIDITY] !== undefined) {
12
+ setHumidity(dpState[SENSOR_HUMIDITY] + '%');
13
+ }
14
+ }, [dpState]);
15
+ return humidity;
16
+ };
@@ -0,0 +1 @@
1
+ export declare const useMuted: () => number;
@@ -0,0 +1,3 @@
1
+ export const useMuted = () => {
2
+ return 100;
3
+ };
@@ -0,0 +1,5 @@
1
+ export declare const useTemperature: (devId: string) => {
2
+ tempUnit: string;
3
+ tempC: string;
4
+ tempF: string;
5
+ };
@@ -0,0 +1,30 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { TEMP_REPORT_F, TEMP_UNIT_SELECT, SENSOR_TEMPERATURE } from '../../utils/content/dpCode';
3
+ import { useDpState } from '../useDpState';
4
+ export const useTemperature = devId => {
5
+ const [tempUnit, setTempUnit] = useState('');
6
+ const [tempC, setTempC] = useState('');
7
+ const [tempF, setTempF] = useState('');
8
+ const [dpState] = useDpState({
9
+ devId,
10
+ dpCodes: [TEMP_UNIT_SELECT, SENSOR_TEMPERATURE, TEMP_REPORT_F]
11
+ });
12
+ useEffect(() => {
13
+ console.log('res===1', dpState);
14
+ // 1=华氏度 0=摄氏度
15
+ if (dpState[TEMP_UNIT_SELECT] !== undefined) {
16
+ setTempUnit(dpState[TEMP_UNIT_SELECT] + '');
17
+ }
18
+ if (dpState[SENSOR_TEMPERATURE] !== undefined) {
19
+ setTempC(dpState[SENSOR_TEMPERATURE] + '°C');
20
+ }
21
+ if (dpState[TEMP_REPORT_F] !== undefined) {
22
+ setTempF(dpState[TEMP_REPORT_F] + '°F');
23
+ }
24
+ }, [dpState]);
25
+ return {
26
+ tempUnit,
27
+ tempC,
28
+ tempF
29
+ };
30
+ };
@@ -0,0 +1 @@
1
+ export declare const useVideoBitKbps: (devId: string) => string;
@@ -0,0 +1,44 @@
1
+ import { useEffect, useState } from 'react';
2
+ export const useVideoBitKbps = devId => {
3
+ const [bitKbps, setBitKbps] = useState('');
4
+ useEffect(() => {
5
+ // const timer = setInterval(() => {
6
+ init();
7
+ // }, 5000);
8
+ // return () => {
9
+ // clearInterval(timer);
10
+ // timer === null;
11
+ // };
12
+ }, []);
13
+ const init = async () => {
14
+ let res = await getVideoBitrateKbps();
15
+ console.log('res===bitKbps', res);
16
+ res += 'KB/S';
17
+ setBitKbps(res);
18
+ };
19
+ const getVideoBitrateKbps = () => {
20
+ return new Promise((resolve, reject) => {
21
+ ty.ipc.getVideoBitrateKbps({
22
+ devId,
23
+ extendParam: {},
24
+ success: _ref => {
25
+ let {
26
+ kpbs = '0'
27
+ } = _ref;
28
+ resolve(kpbs);
29
+ },
30
+ fail: _ref2 => {
31
+ let {
32
+ errorMsg,
33
+ errorCode
34
+ } = _ref2;
35
+ return reject(errorMsg);
36
+ }
37
+ });
38
+ }).catch(error => {
39
+ console.log('res===getVideoBitrateKbps', error);
40
+ return '0';
41
+ });
42
+ };
43
+ return bitKbps;
44
+ };