@ray-js/ipc-player-integration 0.0.1-beta-1 → 0.0.1-beta-2

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/lib/ctx/ctx.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { ComponentConfig, UseCtx } from '../interface';
2
- import type { createPlayContext } from './ports.output';
2
+ import type { createPlayContext, AuthorizeStatus } from './ports.output';
3
3
  type Depend = {
4
4
  createPlayContext: createPlayContext;
5
5
  defaultTopContent?: ComponentConfig[];
6
6
  defaultBottomContent?: ComponentConfig[];
7
7
  defaultAbsoluteContent?: ComponentConfig[];
8
+ authorizeStatus: AuthorizeStatus;
8
9
  };
9
- export declare const createUseCtx: ({ createPlayContext, defaultTopContent, defaultBottomContent, defaultAbsoluteContent, }: Depend) => UseCtx;
10
+ export declare const createUseCtx: ({ createPlayContext, defaultTopContent, defaultBottomContent, defaultAbsoluteContent, authorizeStatus, }: Depend) => UseCtx;
10
11
  export {};
package/lib/ctx/ctx.js CHANGED
@@ -1,5 +1,5 @@
1
- import { useState, useRef } from 'react';
2
- import { authorizeStatus } from '../utils/authorize';
1
+ import { useRef, useCallback } from 'react';
2
+ import { useAtom, updateAtom } from './store';
3
3
  import { PlayState } from '../interface';
4
4
  const SAVE_TO_ALBUM = 1;
5
5
  export const createUseCtx = _ref => {
@@ -7,7 +7,8 @@ export const createUseCtx = _ref => {
7
7
  createPlayContext,
8
8
  defaultTopContent,
9
9
  defaultBottomContent,
10
- defaultAbsoluteContent
10
+ defaultAbsoluteContent,
11
+ authorizeStatus
11
12
  } = _ref;
12
13
  return _ref2 => {
13
14
  let {
@@ -19,17 +20,22 @@ export const createUseCtx = _ref => {
19
20
  } = _ref2;
20
21
  const streamStatus = useRef();
21
22
  // 全屏、竖屏
22
- const [screenType, setScreenType] = useState('vertical');
23
+ const screenType = useAtom('vertical');
23
24
  // 录像中
24
- const [recording, setRecording] = useState(false);
25
+ const recording = useAtom(false);
26
+
25
27
  // 静音
26
- const [mute, setMute] = useState(false);
28
+ const mute = useAtom(false);
29
+
27
30
  // 对讲中
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 || []);
31
+ const intercom = useAtom(false);
32
+ const playState = useAtom(PlayState.CONNECTING);
33
+ const setPlayState = useCallback(value => {
34
+ updateAtom(playState, value);
35
+ }, [playState]);
36
+ const topContent = useAtom(initTopContent || defaultTopContent || []);
37
+ const bottomContent = useAtom(initBottomContent || defaultBottomContent || []);
38
+ const absoluteContent = useAtom(initAbsoluteContent || defaultAbsoluteContent || []);
33
39
  const IPCPlayerInstance = useRef();
34
40
  if (!IPCPlayerInstance.current) {
35
41
  IPCPlayerInstance.current = createPlayContext(devId);
@@ -50,7 +56,7 @@ export const createUseCtx = _ref => {
50
56
  if (target) {
51
57
  IPCPlayerInstance.current.startTalk({
52
58
  success: () => {
53
- setIntercom(true);
59
+ updateAtom(intercom, true);
54
60
  resolve(true);
55
61
  },
56
62
  fail: err => {
@@ -60,11 +66,11 @@ export const createUseCtx = _ref => {
60
66
  } else {
61
67
  IPCPlayerInstance.current.stopTalk({
62
68
  success: () => {
63
- setIntercom(false);
69
+ updateAtom(intercom, false);
64
70
  resolve(true);
65
71
  },
66
72
  fail: err => {
67
- setIntercom(true);
73
+ updateAtom(intercom, true);
68
74
  reject(err);
69
75
  }
70
76
  });
@@ -73,15 +79,15 @@ export const createUseCtx = _ref => {
73
79
  },
74
80
  setMute: async target => {
75
81
  return new Promise((resolve, reject) => {
76
- setMute(target);
82
+ updateAtom(mute, target);
77
83
  IPCPlayerInstance.current.setMuted({
78
84
  mute: target,
79
85
  success: () => {
80
- setMute(true);
86
+ updateAtom(mute, true);
81
87
  resolve(true);
82
88
  },
83
89
  fail: err => {
84
- setMute(!target);
90
+ updateAtom(mute, !target);
85
91
  reject(err);
86
92
  }
87
93
  });
@@ -95,7 +101,7 @@ export const createUseCtx = _ref => {
95
101
  IPCPlayerInstance.current.startRecord({
96
102
  saveToAlbum,
97
103
  success: () => {
98
- setRecording(true);
104
+ updateAtom(recording, true);
99
105
  resolve(true);
100
106
  },
101
107
  fail: err => {
@@ -106,18 +112,20 @@ export const createUseCtx = _ref => {
106
112
  IPCPlayerInstance.current.stopRecord({
107
113
  saveToAlbum,
108
114
  success: () => {
109
- setRecording(false);
115
+ updateAtom(recording, false);
110
116
  resolve(true);
111
117
  },
112
118
  fail: err => {
113
- setRecording(true);
119
+ updateAtom(recording, true);
114
120
  reject(err);
115
121
  }
116
122
  });
117
123
  }
118
124
  });
119
125
  },
120
- setScreenType,
126
+ setScreenType: value => {
127
+ updateAtom(screenType, value);
128
+ },
121
129
  topContent,
122
130
  bottomContent,
123
131
  absoluteContent,
@@ -127,24 +135,20 @@ export const createUseCtx = _ref => {
127
135
  return [...originData, newData];
128
136
  }
129
137
  if (type === 'top') {
130
- setTopContent(createNewData(topContent, config));
138
+ updateAtom(topContent, prevValue => createNewData(prevValue, config));
131
139
  } else if (type === 'bottom') {
132
- setBottomContent(createNewData(bottomContent, config));
140
+ updateAtom(bottomContent, prevValue => createNewData(prevValue, config));
133
141
  } else {
134
- setAbsoluteContent(createNewData(absoluteContent, config));
142
+ updateAtom(absoluteContent, prevValue => createNewData(prevValue, config));
135
143
  }
136
144
  },
137
145
  deleteContent: (type, id) => {
138
- let newData;
139
146
  if (type === 'top') {
140
- newData = topContent.filter(item => item.id !== id);
141
- setTopContent(newData);
147
+ updateAtom(topContent, prevValue => prevValue.filter(item => item.id !== id));
142
148
  } else if (type === 'bottom') {
143
- newData = bottomContent.filter(item => item.id !== id);
144
- setBottomContent(newData);
149
+ updateAtom(bottomContent, prevValue => prevValue.filter(item => item.id !== id));
145
150
  } else {
146
- newData = absoluteContent.filter(item => item.id !== id);
147
- setAbsoluteContent(newData);
151
+ updateAtom(absoluteContent, prevValue => prevValue.filter(item => item.id !== id));
148
152
  }
149
153
  },
150
154
  IPCPlayerInstance: IPCPlayerInstance.current,
@@ -1,12 +1,13 @@
1
1
  import { act, renderHook } from '@testing-library/react-hooks';
2
2
  import { createUseCtx } from './ctx';
3
+ import { useStore } from './store';
3
4
  describe('createCtx', () => {
4
5
  it('init props', () => {
5
6
  const topContent = {
6
7
  id: 'top',
7
8
  content: () => null
8
9
  };
9
- const bottomContent = {
10
+ const defaultBottomContent = {
10
11
  id: 'bottom',
11
12
  content: () => null,
12
13
  initProps: {
@@ -25,29 +26,66 @@ describe('createCtx', () => {
25
26
  initProps: {
26
27
  name: 2
27
28
  }
28
- }]
29
+ }],
30
+ authorizeStatus: () => Promise.resolve(true)
29
31
  });
30
32
  const {
31
33
  result
32
- } = renderHook(() => useCtx({
33
- devId: 'devId',
34
- initBottomContent: [bottomContent],
35
- initAbsoluteContent: []
36
- }));
34
+ } = renderHook(() => {
35
+ const {
36
+ topContent,
37
+ bottomContent,
38
+ absoluteContent,
39
+ IPCPlayerInstance
40
+ } = useCtx({
41
+ devId: 'devId',
42
+ initBottomContent: [defaultBottomContent],
43
+ initAbsoluteContent: []
44
+ });
45
+ const store = useStore({
46
+ topContent: topContent,
47
+ bottomContent: bottomContent,
48
+ absoluteContent: absoluteContent
49
+ });
50
+ return {
51
+ topContent: store.topContent,
52
+ bottomContent: store.bottomContent,
53
+ absoluteContent: store.absoluteContent,
54
+ IPCPlayerInstance
55
+ };
56
+ });
37
57
  expect(result.current.topContent).toEqual([topContent]);
38
- expect(result.current.bottomContent).toEqual([bottomContent]);
58
+ expect(result.current.bottomContent).toEqual([defaultBottomContent]);
39
59
  expect(result.current.absoluteContent).toEqual([]);
40
60
  expect(result.current.IPCPlayerInstance).toBe(IPCPlayerContext);
41
61
  });
42
- it('createCtx, add a content and delete content', () => {
62
+ it('createCtx, add a content and delete content', async () => {
43
63
  const useCtx = createUseCtx({
44
- createPlayContext: () => null
64
+ createPlayContext: () => null,
65
+ authorizeStatus: () => Promise.resolve(true)
45
66
  });
46
67
  const {
47
68
  result
48
- } = renderHook(() => useCtx({
49
- devId: 'devId'
50
- }));
69
+ } = renderHook(() => {
70
+ const {
71
+ addContent,
72
+ topContent,
73
+ bottomContent,
74
+ deleteContent
75
+ } = useCtx({
76
+ devId: 'devId'
77
+ });
78
+ const store = useStore({
79
+ topContent,
80
+ bottomContent
81
+ });
82
+ return {
83
+ addContent,
84
+ topContent: store.topContent,
85
+ bottomContent: store.bottomContent,
86
+ deleteContent
87
+ };
88
+ });
51
89
  const topContent = {
52
90
  id: 'top',
53
91
  content: () => null
@@ -72,13 +110,26 @@ describe('createCtx', () => {
72
110
  });
73
111
  it('add content list', () => {
74
112
  const useCtx = createUseCtx({
75
- createPlayContext: () => null
113
+ createPlayContext: () => null,
114
+ authorizeStatus: () => Promise.resolve(true)
76
115
  });
77
116
  const {
78
117
  result
79
- } = renderHook(() => useCtx({
80
- devId: 'devId'
81
- }));
118
+ } = renderHook(() => {
119
+ const {
120
+ addContent,
121
+ topContent
122
+ } = useCtx({
123
+ devId: 'devId'
124
+ });
125
+ const store = useStore({
126
+ topContent
127
+ });
128
+ return {
129
+ addContent,
130
+ topContent: store.topContent
131
+ };
132
+ });
82
133
  const topContent1 = {
83
134
  id: 'top1',
84
135
  content: () => null
@@ -92,4 +143,28 @@ describe('createCtx', () => {
92
143
  });
93
144
  expect(result.current.topContent).toEqual([topContent1, topContent2]);
94
145
  });
146
+
147
+ // it('Select Update', () => {
148
+ // const useCtx = createUseCtx({
149
+ // createPlayContext: () => null,
150
+ // authorizeStatus: () => Promise.resolve(true),
151
+ // });
152
+ // const { result } = renderHook(() =>
153
+ // useCtx({
154
+ // devId: 'devId',
155
+ // })
156
+ // );
157
+ // const { result: re1 } = renderHook(() => {
158
+ // const store = useStore({
159
+ // topContent: result.current.topContent,
160
+ // });
161
+ // return store;
162
+ // });
163
+ // const { result: re2 } = renderHook(() => {
164
+ // const store = useStore({
165
+ // bottomContent: result.current.bottomContent,
166
+ // });
167
+ // return store;
168
+ // });
169
+ // });
95
170
  });
@@ -1,2 +1,3 @@
1
1
  export * from './ctx';
2
2
  export * from './ctx.composition';
3
+ export * from './store';
package/lib/ctx/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './ctx';
2
- export * from './ctx.composition';
2
+ export * from './ctx.composition';
3
+ export * from './store';
@@ -1 +1,2 @@
1
1
  export type createPlayContext = (devId: string) => IpcContext;
2
+ export type AuthorizeStatus = (type: string) => Promise<boolean>;
@@ -0,0 +1,11 @@
1
+ import { RetAtom } from '../interface';
2
+ export declare const topContent: import("jotai").PrimitiveAtom<never[]> & {
3
+ init: never[];
4
+ };
5
+ export declare const useAtom: <T extends unknown>(defaultValue: T) => RetAtom<T>;
6
+ type ExtractReturnType<T> = {
7
+ [K in keyof T]: T[K] extends RetAtom<infer R> ? R : never;
8
+ };
9
+ export declare const useStore: <V, T extends Record<string, RetAtom<V>>>(options: T) => ExtractReturnType<T>;
10
+ export declare const updateAtom: <T>(atom: RetAtom<T>, value: T | ((prevValue: T) => T)) => void;
11
+ export {};
@@ -0,0 +1,37 @@
1
+ import { useRef } from 'react';
2
+ import { atom, useAtomValue, getDefaultStore } from 'jotai';
3
+ export const topContent = atom([]);
4
+ export const useAtom = defaultValue => {
5
+ const ref = useRef();
6
+ if (!ref.current) {
7
+ // @ts-ignore
8
+ ref.current = atom(defaultValue);
9
+ }
10
+ return ref.current;
11
+ };
12
+ export const useStore = options => {
13
+ const combinedAtomRef = useRef();
14
+ if (!combinedAtomRef.current) {
15
+ // @ts-ignore
16
+ combinedAtomRef.current = atom(get => {
17
+ const ret = {};
18
+ Object.keys(options).forEach(key => {
19
+ ret[key] = get(options[key]);
20
+ });
21
+ return ret;
22
+ });
23
+ }
24
+ const state = useAtomValue(combinedAtomRef.current);
25
+ return state;
26
+ };
27
+ export const updateAtom = (atom, value) => {
28
+ const store = getDefaultStore();
29
+ const oldValue = store.get(atom);
30
+ if (typeof value === 'function') {
31
+ // @ts-ignore
32
+ const newValue = value(oldValue);
33
+ store.set(atom, newValue);
34
+ } else {
35
+ store.set(atom, value);
36
+ }
37
+ };
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './ui';
2
2
  export * from './ctx';
3
3
  export * from './plugins';
4
+ export * from './interface';
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './ui';
2
2
  export * from './ctx';
3
- export * from './plugins';
3
+ export * from './plugins';
4
+ export * from './interface';
@@ -1,4 +1,9 @@
1
1
  import React from 'react';
2
+ import { PrimitiveAtom } from 'jotai';
3
+ type WithInitialValue<Value> = {
4
+ init: Value;
5
+ };
6
+ export type RetAtom<T> = PrimitiveAtom<T> & WithInitialValue<T>;
2
7
  export type ComponentConfig<T = Record<string, unknown>> = {
3
8
  id: string;
4
9
  content: (props: T) => React.ReactElement;
@@ -31,15 +36,15 @@ export type UseCtx = (options: {
31
36
  }) => {
32
37
  devId: string;
33
38
  saveToAlbum: 0 | 1;
34
- screenType: ScreenType;
35
- recording: boolean;
36
- mute: boolean;
37
- intercom: boolean;
38
- playState: PlayState;
39
+ screenType: RetAtom<ScreenType>;
40
+ recording: RetAtom<boolean>;
41
+ mute: RetAtom<boolean>;
42
+ intercom: RetAtom<boolean>;
43
+ playState: RetAtom<PlayState>;
39
44
  IPCPlayerInstance: IpcContext;
40
- topContent: ComponentConfig[];
41
- bottomContent: ComponentConfig[];
42
- absoluteContent: ComponentConfig[];
45
+ topContent: RetAtom<ComponentConfig[]>;
46
+ bottomContent: RetAtom<ComponentConfig[]>;
47
+ absoluteContent: RetAtom<ComponentConfig[]>;
43
48
  setScreenType: (type: ScreenType) => void;
44
49
  setRecording: (value: boolean) => Promise<boolean>;
45
50
  setIntercom: (value: boolean) => Promise<boolean>;
@@ -57,3 +62,4 @@ export type PlayStatusData = {
57
62
  playState: PlayState;
58
63
  playCode: number;
59
64
  };
65
+ export {};
@@ -4,23 +4,23 @@ export declare const Battery: import("react").FunctionComponent<{
4
4
  } & {
5
5
  devId: string;
6
6
  saveToAlbum: 0 | 1;
7
- screenType: import("../../interface").ScreenType;
8
- recording: boolean;
9
- mute: boolean;
10
- intercom: boolean;
11
- playState: import("../../interface").PlayState;
7
+ screenType: import("../..").RetAtom<import("../..").ScreenType>;
8
+ recording: import("../..").RetAtom<boolean>;
9
+ mute: import("../..").RetAtom<boolean>;
10
+ intercom: import("../..").RetAtom<boolean>;
11
+ playState: import("../..").RetAtom<import("../..").PlayState>;
12
12
  IPCPlayerInstance: IpcContext;
13
- topContent: import("../../interface").ComponentConfig<Record<string, unknown>>[];
14
- bottomContent: import("../../interface").ComponentConfig<Record<string, unknown>>[];
15
- absoluteContent: import("../../interface").ComponentConfig<Record<string, unknown>>[];
16
- setScreenType: (type: import("../../interface").ScreenType) => void;
13
+ topContent: import("../..").RetAtom<import("../..").ComponentConfig<Record<string, unknown>>[]>;
14
+ bottomContent: import("../..").RetAtom<import("../..").ComponentConfig<Record<string, unknown>>[]>;
15
+ absoluteContent: import("../..").RetAtom<import("../..").ComponentConfig<Record<string, unknown>>[]>;
16
+ setScreenType: (type: import("../..").ScreenType) => void;
17
17
  setRecording: (value: boolean) => Promise<boolean>;
18
18
  setIntercom: (value: boolean) => Promise<boolean>;
19
19
  setMute: (value: boolean) => Promise<boolean>;
20
- changeStreamStatus: (value: import("../../interface").PlayerStreamStatus) => void;
21
- getStreamStatus: () => import("../../interface").PlayerStreamStatus;
22
- setPlayState: (value: import("../../interface").PlayState) => void;
23
- addContent: <T>(type: "absolute" | "top" | "bottom", config: import("../../interface").ComponentConfig<T> | import("../../interface").ComponentConfig<T>[]) => void;
20
+ changeStreamStatus: (value: import("../..").PlayerStreamStatus) => void;
21
+ getStreamStatus: () => import("../..").PlayerStreamStatus;
22
+ setPlayState: (value: import("../..").PlayState) => void;
23
+ addContent: <T>(type: "absolute" | "top" | "bottom", config: import("../..").ComponentConfig<T> | import("../..").ComponentConfig<T>[]) => void;
24
24
  deleteContent: (type: "absolute" | "top" | "bottom", id: string) => void;
25
25
  } & {
26
26
  className?: string | undefined;
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { View, Text } from '@ray-js/ray';
3
3
  import clsx from 'clsx';
4
+ import { useStore } from '../../ctx/store';
4
5
  import './battery.less';
5
6
  export const createBattery = _ref => {
6
7
  let {
@@ -12,14 +13,17 @@ export const createBattery = _ref => {
12
13
  devId,
13
14
  screenType
14
15
  } = props;
16
+ const store = useStore({
17
+ screenType
18
+ });
15
19
  const {
16
20
  batteryValue,
17
21
  batteryCharging
18
22
  } = useBattery(devId);
19
23
  return /*#__PURE__*/React.createElement(View, {
20
24
  className: clsx('ipc-player-plugin-battery', {
21
- 'ipc-player-plugin-battery-relative': screenType === 'full',
22
- 'ipc-player-plugin-battery-absolute': screenType === 'vertical'
25
+ 'ipc-player-plugin-battery-relative': store.screenType === 'full',
26
+ 'ipc-player-plugin-battery-absolute': store.screenType === 'vertical'
23
27
  }, className)
24
28
  }, /*#__PURE__*/React.createElement(View, {
25
29
  className: "ipc-player-plugin-battery-border"
@@ -1,6 +1,7 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import React from 'react';
3
3
  import { View, setPageOrientation, CoverView } from '@ray-js/ray';
4
+ import { useStore } from '../../ctx/store';
4
5
  import { VerticalScreen } from './verticalScreen';
5
6
  import { VoiceIntercom } from '../voiceIntercom';
6
7
  import './fullScreen.less';
@@ -8,12 +9,16 @@ const VerticalScreenId = 'VerticalScreen';
8
9
  const VoiceIntercomId = 'VoiceIntercom';
9
10
  export function FullScreen(props) {
10
11
  const {
11
- screenType,
12
+ screenType: screenTypeAtom,
12
13
  setScreenType,
13
- devId,
14
14
  addContent,
15
15
  deleteContent
16
16
  } = props;
17
+ const {
18
+ screenType
19
+ } = useStore({
20
+ screenType: screenTypeAtom
21
+ });
17
22
  const handFull = () => {
18
23
  ty.hideMenuButton();
19
24
  ty.hideStatusBar();
@@ -10,6 +10,6 @@ export function VerticalScreen(_ref) {
10
10
  className: "ipc-player-plugin-vertical-screen",
11
11
  onClick: onClick
12
12
  }, /*#__PURE__*/React.createElement(View, {
13
- className: "icon-panel icon-panel-fanhui ipc-player-plugin-vertical-screen-icon"
13
+ className: "icon-panel icon-panel-fanhui-copy ipc-player-plugin-vertical-screen-icon"
14
14
  }));
15
15
  }
@@ -1,11 +1,20 @@
1
1
  import { View, Text } from '@ray-js/ray';
2
- import React, { useEffect, useState } from 'react';
2
+ import React, { useEffect } from 'react';
3
+ import { useStore, updateAtom } from '../../ctx/store';
3
4
  import './muted.less';
4
5
  export const Muted = props => {
5
6
  const {
6
- IPCPlayerContext
7
+ IPCPlayerContext,
8
+ mute
7
9
  } = props;
8
- const [isMuted, setIsMuted] = useState(true);
10
+ const {
11
+ isMuted
12
+ } = useStore({
13
+ isMuted: mute
14
+ });
15
+ const setIsMuted = value => {
16
+ updateAtom(mute, value);
17
+ };
9
18
  useEffect(() => {
10
19
  init();
11
20
  }, []);
@@ -1,5 +1,6 @@
1
1
  import React, { useState, useEffect, useRef } from 'react';
2
2
  import { View } from '@ray-js/ray';
3
+ import { useStore } from '../../ctx/store';
3
4
  import './recordVideo.less';
4
5
  const RECORD_VIDEO_TOAST_ID = 'record_video_toast_id';
5
6
  function formatTimeDiff(diff) {
@@ -62,15 +63,18 @@ function TimeRecord() {
62
63
  }
63
64
  export function RecordVideo(props) {
64
65
  const {
65
- IPCPlayerContext,
66
66
  addContent,
67
67
  deleteContent
68
68
  } = props;
69
- // const [recording, setRecording] = useState(false);
70
69
  const {
71
- recording,
70
+ recording: recordingAtom,
72
71
  setRecording
73
72
  } = props;
73
+ const {
74
+ recording
75
+ } = useStore({
76
+ recording: recordingAtom
77
+ });
74
78
  const handRecordVideo = async target => {
75
79
  await setRecording(target);
76
80
  if (target) {
@@ -5,5 +5,5 @@ type Props = ComponentConfigProps & {
5
5
  style?: React.CSSProperties;
6
6
  className?: string;
7
7
  };
8
- export declare function VoiceIntercom({ style, className, recording, intercom, setIntercom, mute, setMute, getStreamStatus, }: Props): React.JSX.Element;
8
+ export declare function VoiceIntercom({ style, className, recording: recordingAtom, intercom: intercomAtom, setIntercom, mute: muteAtom, setMute, getStreamStatus, }: Props): React.JSX.Element;
9
9
  export {};
@@ -2,19 +2,29 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import React, { useRef } from 'react';
3
3
  import { View } from '@ray-js/ray';
4
4
  import clsx from 'clsx';
5
+ import { useStore } from '../../ctx/store';
5
6
  import './voiceIntercom.less';
6
7
  import { PlayerStreamStatus } from '../../interface';
7
8
  export function VoiceIntercom(_ref) {
8
9
  let {
9
10
  style,
10
11
  className,
11
- recording,
12
- intercom,
12
+ recording: recordingAtom,
13
+ intercom: intercomAtom,
13
14
  setIntercom,
14
- mute,
15
+ mute: muteAtom,
15
16
  setMute,
16
17
  getStreamStatus
17
18
  } = _ref;
19
+ const {
20
+ recording,
21
+ mute,
22
+ intercom
23
+ } = useStore({
24
+ recording: recordingAtom,
25
+ mute: muteAtom,
26
+ intercom: intercomAtom
27
+ });
18
28
  const longClickStartedRef = useRef(false);
19
29
  // 对讲开始之前的静音状态
20
30
  const originMuteStatusBeforeVoice = useRef(mute);
package/lib/ui/ui.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import React from 'react';
2
- import { PlayStatusData } from '../interface';
3
- import { useCtx } from '../ctx/ctx.composition';
2
+ import { PlayStatusData, UseCtx } from '../interface';
4
3
  import './ui.less';
5
- type CtxInstance = ReturnType<typeof useCtx>;
4
+ type CtxInstance = ReturnType<UseCtx>;
6
5
  type CSSVariable = {
7
6
  '--iconColor': string;
8
7
  '--iconFontSize': string;
package/lib/ui/ui.js CHANGED
@@ -5,6 +5,7 @@ import clsx from 'clsx';
5
5
  import IPCPlayer from '@ray-js/ray-ipc-player';
6
6
  import { PlayState, PlayerStreamStatus } from '../interface';
7
7
  import { useCtx } from '../ctx/ctx.composition';
8
+ import { useStore } from '../ctx/store';
8
9
  import './ui.less';
9
10
  function getCtxInstance(instance, devId) {
10
11
  if (instance) return instance;
@@ -31,25 +32,35 @@ export const IPCPlayerIntegration = props => {
31
32
  } = props;
32
33
  const instance = getCtxInstance(props.instance, devId);
33
34
  const {
34
- topContent,
35
- absoluteContent,
36
- bottomContent,
37
- playState,
38
35
  setPlayState
39
36
  } = instance;
40
37
  const systemInfo = useRef(null);
41
38
  if (!systemInfo.current) {
42
39
  systemInfo.current = getSystemInfoSync();
43
40
  }
41
+ const {
42
+ topContent,
43
+ bottomContent,
44
+ absoluteContent,
45
+ screenType,
46
+ playState
47
+ } = useStore({
48
+ topContent: instance.topContent,
49
+ bottomContent: instance.bottomContent,
50
+ absoluteContent: instance.absoluteContent,
51
+ screenType: instance.screenType,
52
+ playState: instance.playState
53
+ });
44
54
 
45
55
  /**
46
56
  * 视频流加载状态封装
47
57
  */
48
58
 
59
+ const playerReady = playState === PlayState.PLAYING;
49
60
  return /*#__PURE__*/React.createElement(View, {
50
61
  className: clsx('ipc-player-content', className),
51
62
  style: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, defaultCSSVariable), CSSVariable), style), {}, {
52
- height: instance.screenType === 'full' ? `${systemInfo.current.screenWidth}px` : style === null || style === void 0 ? void 0 : style.height
63
+ height: screenType === 'full' ? `${systemInfo.current.screenWidth}px` : style === null || style === void 0 ? void 0 : style.height
53
64
  })
54
65
  }, /*#__PURE__*/React.createElement(View, {
55
66
  style: {
@@ -88,9 +99,9 @@ export const IPCPlayerIntegration = props => {
88
99
  privateState: false
89
100
  })), /*#__PURE__*/React.createElement(CoverView, {
90
101
  style: {
91
- height: instance.screenType === 'vertical' ? '48px' : '69px'
102
+ height: screenType === 'vertical' ? '48px' : '69px'
92
103
  },
93
- className: clsx('ipc-player-top-content', playState === PlayState.PLAYING ? 'ipc-player-element-visible' : 'ipc-player-element-hidden')
104
+ className: clsx('ipc-player-top-content', playerReady ? 'ipc-player-element-visible' : 'ipc-player-element-hidden')
94
105
  }, (() => {
95
106
  if (!topContent || !(topContent !== null && topContent !== void 0 && topContent.length)) return null;
96
107
  return topContent.map(item => /*#__PURE__*/React.createElement(item.content, _objectSpread(_objectSpread(_objectSpread({
@@ -100,9 +111,9 @@ export const IPCPlayerIntegration = props => {
100
111
  })));
101
112
  })()), /*#__PURE__*/React.createElement(CoverView, {
102
113
  style: {
103
- height: instance.screenType === 'vertical' ? '48px' : '69px'
114
+ height: screenType === 'vertical' ? '48px' : '69px'
104
115
  },
105
- className: clsx('ipc-player-bottom-content', playState === PlayState.PLAYING ? 'ipc-player-element-visible' : 'ipc-player-element-hidden')
116
+ className: clsx('ipc-player-bottom-content', playerReady ? 'ipc-player-element-visible' : 'ipc-player-element-hidden')
106
117
  }, (() => {
107
118
  if (!bottomContent || !(bottomContent !== null && bottomContent !== void 0 && bottomContent.length)) return null;
108
119
  return bottomContent.map(item => /*#__PURE__*/React.createElement(item.content, _objectSpread(_objectSpread(_objectSpread({}, item.initProps), {}, {
@@ -110,7 +121,7 @@ export const IPCPlayerIntegration = props => {
110
121
  }, instance), {}, {
111
122
  IPCPlayerContext: instance.IPCPlayerInstance
112
123
  })));
113
- })()), playState === PlayState.PLAYING && (() => {
124
+ })()), playerReady && (() => {
114
125
  if (!absoluteContent || !(absoluteContent !== null && absoluteContent !== void 0 && absoluteContent.length)) return null;
115
126
  return absoluteContent.map(item => /*#__PURE__*/React.createElement(item.content, _objectSpread(_objectSpread(_objectSpread({
116
127
  key: item.id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ipc-player-integration",
3
- "version": "0.0.1-beta-1",
3
+ "version": "0.0.1-beta-2",
4
4
  "description": "IPC 播放器功能集成",
5
5
  "main": "lib/index",
6
6
  "files": [
@@ -49,6 +49,7 @@
49
49
  "core-js": "^3.19.1",
50
50
  "eslint-config-tuya-panel": "^0.4.2",
51
51
  "husky": "^1.2.0",
52
+ "jotai": "^2.10.1",
52
53
  "lint-staged": "^10.2.11",
53
54
  "standard-version": "9.3.2"
54
55
  },