@ray-js/ipc-player-integration 0.0.1-beta-16 → 0.0.1-beta-17

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.
@@ -2,5 +2,19 @@ type Options<T> = {
2
2
  devId: string;
3
3
  dpCodes: T[];
4
4
  };
5
- export declare function useDpState<T extends string>(options: Options<T>): [Record<T, number | string | boolean>];
5
+ type Schema = {
6
+ id: number;
7
+ code: string;
8
+ mode: string;
9
+ property: {
10
+ type: 'value' | 'enum' | 'bool';
11
+ unit?: string;
12
+ min?: number;
13
+ max?: number;
14
+ scale?: number;
15
+ step?: number;
16
+ range?: Array<unknown>;
17
+ };
18
+ };
19
+ export declare function useDpState<T extends string>(options: Options<T>): [Record<T, number | string | boolean>, Record<string, Schema>];
6
20
  export {};
@@ -14,6 +14,7 @@ export function useDpState(options) {
14
14
  dpCodes
15
15
  } = options;
16
16
  const codeMapToIdRef = useRef();
17
+ const dpCodeSchemaMapsRef = useRef();
17
18
  const [values, setValues] = useState(() => {
18
19
  return getInitData(options.dpCodes);
19
20
  });
@@ -42,38 +43,44 @@ export function useDpState(options) {
42
43
  }
43
44
  }, [devId]);
44
45
  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)) {
46
+ if (devId) {
47
+ getDeviceInfo({
48
+ deviceId: devId,
49
+ success: res => {
50
+ const {
51
+ schema
52
+ } = res;
53
+ const IdMapToCode = {};
54
+ const dpCodeSchemaMaps = {};
55
+ let count = 0;
56
+ for (const schemaItem of schema) {
56
57
  // @ts-ignore
57
- IdMapToCode[schemaItem.id] = schemaItem.code;
58
- count += 1;
58
+ if (dpCodes.includes(schemaItem.code)) {
59
+ // @ts-ignore
60
+ IdMapToCode[schemaItem.id] = schemaItem.code;
61
+ // @ts-ignore
62
+ dpCodeSchemaMaps[schemaItem.code] = schemaItem;
63
+ count += 1;
64
+ }
65
+ if (count >= dpCodes.length) break;
59
66
  }
60
- if (count >= dpCodes.length) break;
67
+ codeMapToIdRef.current = IdMapToCode;
68
+ dpCodeSchemaMapsRef.current = dpCodeSchemaMaps;
69
+ const initValue = options.dpCodes.reduce((ret, key) => {
70
+ return _objectSpread(_objectSpread({}, ret), {}, {
71
+ [key]: res.dpCodes[key]
72
+ });
73
+ }, {});
74
+ setValues(initValue);
61
75
  }
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]);
76
+ });
77
+ }
78
+ }, [devId]);
72
79
  useEffect(() => {
73
80
  onDpDataChange(listenDpChange);
74
81
  return () => {
75
82
  offDpDataChange(listenDpChange);
76
83
  };
77
84
  }, [listenDpChange]);
78
- return [values];
85
+ return [values, dpCodeSchemaMapsRef.current];
79
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ipc-player-integration",
3
- "version": "0.0.1-beta-16",
3
+ "version": "0.0.1-beta-17",
4
4
  "description": "IPC 播放器功能集成",
5
5
  "main": "lib/index",
6
6
  "files": [