@ray-js/ipc-player-integration 0.0.1-beta-13 → 0.0.1-beta-14

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,7 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
3
  const _excluded = ["title", "duration"];
4
4
  import IPCUtils from '@ray-js/ray-ipc-utils';
5
- import { MuteMode } from '@ray-js/ray-ipc-utils/lib/interface';
5
+ import { IntercomMode, MuteMode } from '@ray-js/ray-ipc-utils/lib/interface';
6
6
  import { createUseCtx } from './ctx';
7
7
  import { Battery, Screenshot, TempHumidity, RecordVideo, FullScreen, VideoBitKbps, Muted, Resolution, Ptz } from '../plugins';
8
8
  import { authorizeStatus } from '../utils/authorize';
@@ -52,21 +52,22 @@ const toast = _ref => {
52
52
  }, config));
53
53
  };
54
54
  const getMemoryState = devId => {
55
+ const defaultValue = {
56
+ mute: true,
57
+ intercomMode: IntercomMode.TwoWay
58
+ };
55
59
  return new Promise(resolve => {
56
60
  IPCUtils.getCameraConfigInfo(devId).then(res => {
57
61
  if (res.code === -1) {
58
- return resolve({
59
- mute: true
60
- });
62
+ return resolve(defaultValue);
61
63
  }
62
64
  const value = res.data.microphoneSettings.cachedMuteMode === MuteMode.OFF;
63
65
  return resolve({
64
- mute: value
66
+ mute: value,
67
+ intercomMode: res.data.intercomInfo.cachedIntercomMode
65
68
  });
66
69
  }).catch(() => {
67
- resolve({
68
- mute: true
69
- });
70
+ resolve(defaultValue);
70
71
  });
71
72
  });
72
73
  };
package/lib/ctx/ctx.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { useRef, useCallback, useEffect } from 'react';
2
2
  import { useAtom, updateAtom, getDefaultStore, useStore } from './store';
3
- import { PlayState } from '../interface';
3
+ import { PlayState, IntercomMode } from '../interface';
4
4
  const SAVE_TO_ALBUM = 1;
5
5
  export const createUseCtx = _ref => {
6
6
  let {
@@ -23,29 +23,35 @@ export const createUseCtx = _ref => {
23
23
  } = _ref2;
24
24
  const streamStatus = useRef();
25
25
  // 全屏、竖屏
26
- const screenType = useAtom('vertical');
26
+ const [screenType, setScreenType] = useAtom('vertical');
27
+
27
28
  // 录像中
28
- const recording = useAtom(false);
29
+ const [recording] = useAtom(false);
29
30
 
30
31
  // 静音 true 代表静音 false 代表不静音
31
- const mute = useAtom(false);
32
+ const [mute] = useAtom(false);
32
33
 
33
34
  // 清晰度
34
- const resolution = useAtom('HD');
35
+ const [resolution] = useAtom('HD');
35
36
 
36
37
  // ptz 是否点击
37
- const ptzActive = useAtom(false);
38
+ const [ptzActive, setPtzActive] = useAtom(false);
39
+
40
+ // 单向对讲还是双向对讲
41
+ const [intercomMode, setIntercomMode] = useAtom(IntercomMode.TwoWay);
42
+
38
43
  // 全屏清晰度UI切换是否展示
39
- const fullResolutionActive = useAtom(false);
44
+ const [fullResolutionActive, setFullResolutionActive] = useAtom(false);
45
+
40
46
  // 对讲中
41
- const intercom = useAtom(false);
42
- const playState = useAtom(PlayState.CONNECTING);
47
+ const [intercom] = useAtom(false);
48
+ const [playState] = useAtom(PlayState.CONNECTING);
43
49
  const setPlayState = useCallback(value => {
44
50
  updateAtom(playState, value);
45
51
  }, [playState]);
46
- const topContent = useAtom(initTopContent || defaultTopContent || []);
47
- const bottomContent = useAtom(initBottomContent || defaultBottomContent || []);
48
- const absoluteContent = useAtom(initAbsoluteContent || defaultAbsoluteContent || []);
52
+ const [topContent] = useAtom(initTopContent || defaultTopContent || []);
53
+ const [bottomContent] = useAtom(initBottomContent || defaultBottomContent || []);
54
+ const [absoluteContent] = useAtom(initAbsoluteContent || defaultAbsoluteContent || []);
49
55
  const {
50
56
  _playState
51
57
  } = useStore({
@@ -55,7 +61,9 @@ export const createUseCtx = _ref => {
55
61
  if (devId && _playState === PlayState.PLAYING) {
56
62
  // 获取缓存的值且同步
57
63
  getMemoryState(devId).then(res => {
64
+ console.log('==== getMemoryState ====', res);
58
65
  _setMute(res.mute);
66
+ setIntercomMode(res.intercomMode);
59
67
  });
60
68
  }
61
69
  }, [devId, _playState]);
@@ -106,6 +114,7 @@ export const createUseCtx = _ref => {
106
114
  ptzActive,
107
115
  fullResolutionActive,
108
116
  intercom,
117
+ intercomMode,
109
118
  playState,
110
119
  setPlayState,
111
120
  setIntercom: async target => {
@@ -204,15 +213,9 @@ export const createUseCtx = _ref => {
204
213
  }
205
214
  });
206
215
  },
207
- setPtzActive: value => {
208
- updateAtom(ptzActive, value);
209
- },
210
- setFullResolutionActive: value => {
211
- updateAtom(fullResolutionActive, value);
212
- },
213
- setScreenType: value => {
214
- updateAtom(screenType, value);
215
- },
216
+ setPtzActive,
217
+ setFullResolutionActive,
218
+ setScreenType,
216
219
  topContent,
217
220
  bottomContent,
218
221
  absoluteContent,
@@ -1,7 +1,9 @@
1
- export type { Toast } from '../ports.output';
1
+ import { IntercomMode } from '../ports.output';
2
+ export type { Toast, IntercomMode } from '../ports.output';
2
3
  export type createPlayContext = (devId: string) => IpcContext;
3
4
  export type AuthorizeStatus = (type: string) => Promise<boolean>;
4
5
  export type GetMemoryState = (devId: string) => Promise<{
5
6
  mute: boolean;
7
+ intercomMode: IntercomMode;
6
8
  }>;
7
9
  export type SetMuteMemoryState = (devId: string, value: boolean) => void;
@@ -3,9 +3,10 @@ export { getDefaultStore } from 'jotai';
3
3
  export declare const topContent: import("jotai").PrimitiveAtom<never[]> & {
4
4
  init: never[];
5
5
  };
6
- export declare const useAtom: <T extends unknown>(defaultValue: T) => RetAtom<T>;
6
+ type Action<T> = T | ((prevValue: T) => T);
7
+ export declare const useAtom: <T extends unknown>(defaultValue: T) => [RetAtom<T>, (value: Action<T>) => void];
7
8
  type ExtractReturnType<T> = {
8
9
  [K in keyof T]: T[K] extends RetAtom<infer R> ? R : never;
9
10
  };
10
11
  export declare const useStore: <V, T extends Record<string, RetAtom<V>>>(options: T) => ExtractReturnType<T>;
11
- export declare const updateAtom: <T>(atom: RetAtom<T>, value: T | ((prevValue: T) => T)) => void;
12
+ export declare const updateAtom: <T>(atom: RetAtom<T>, value: Action<T>) => void;
package/lib/ctx/store.js CHANGED
@@ -8,7 +8,7 @@ export const useAtom = defaultValue => {
8
8
  // @ts-ignore
9
9
  ref.current = atom(defaultValue);
10
10
  }
11
- return ref.current;
11
+ return [ref.current, value => updateAtom(ref.current, value)];
12
12
  };
13
13
  export const useStore = options => {
14
14
  const combinedAtomRef = useRef();
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { PrimitiveAtom } from 'jotai';
3
- import type { Toast } from './ports.output';
3
+ import type { Toast, IntercomMode } from './ports.output';
4
+ export { IntercomMode } from './ports.output';
4
5
  type WithInitialValue<Value> = {
5
6
  init: Value;
6
7
  };
@@ -36,6 +37,7 @@ export type UseCtx = (options: {
36
37
  recording: RetAtom<boolean>;
37
38
  mute: RetAtom<boolean>;
38
39
  intercom: RetAtom<boolean>;
40
+ intercomMode: RetAtom<IntercomMode>;
39
41
  ptzActive: RetAtom<boolean>;
40
42
  fullResolutionActive: RetAtom<boolean>;
41
43
  playState: RetAtom<PlayState>;
@@ -70,4 +72,3 @@ export type PlayStatusData = {
70
72
  playState: PlayState;
71
73
  playCode: number;
72
74
  };
73
- export {};
package/lib/interface.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { IntercomMode } from './ports.output';
1
2
  export let PlayerStreamStatus = /*#__PURE__*/function (PlayerStreamStatus) {
2
3
  PlayerStreamStatus[PlayerStreamStatus["UnknownException"] = -1000] = "UnknownException";
3
4
  PlayerStreamStatus[PlayerStreamStatus["ConnectSuccess"] = 1001] = "ConnectSuccess";
@@ -8,6 +8,7 @@ export declare const Battery: import("react").FunctionComponent<{
8
8
  recording: import("../..").RetAtom<boolean>;
9
9
  mute: import("../..").RetAtom<boolean>;
10
10
  intercom: import("../..").RetAtom<boolean>;
11
+ intercomMode: import("../..").RetAtom<import("@ray-js/ray-ipc-utils/lib/interface").IntercomMode>;
11
12
  ptzActive: import("../..").RetAtom<boolean>;
12
13
  fullResolutionActive: import("../..").RetAtom<boolean>;
13
14
  playState: import("../..").RetAtom<import("../..").PlayState>;
@@ -3,7 +3,7 @@
3
3
  color: var(--iconColor);
4
4
  }
5
5
  .ipc-player-plugin-record-video-toast-wrap {
6
- z-index: 2;
6
+ z-index: 110;
7
7
  position: absolute;
8
8
  top: calc(7px * var(--ipc-player-size-scale, 1));
9
9
  left: 50%;
@@ -15,6 +15,8 @@
15
15
  align-items: center;
16
16
  background-color: var(--bg-color);
17
17
  border-radius: calc(8px * var(--ipc-player-size-scale, 1));
18
+ // background-color: #fff;
19
+ background: linear-gradient(0deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.15)), #000000;
18
20
  .ipc-player-plugin-record-video-toast-point {
19
21
  width: calc(6px * var(--ipc-player-size-scale, 1));
20
22
  height: calc(6px * var(--ipc-player-size-scale, 1));
@@ -9,5 +9,5 @@ type Props = ComponentConfigProps & {
9
9
  onTouchStart?: TouchEventHandler['onTouchStart'];
10
10
  onTouchEnd?: TouchEventHandler['onTouchEnd'];
11
11
  };
12
- export declare function VoiceIntercom({ style, className, iconClassName, recording: recordingAtom, intercom: intercomAtom, setIntercom, mute: muteAtom, setMute, getStreamStatus, onTouchStart, onTouchEnd, }: Props): React.JSX.Element;
12
+ export declare function VoiceIntercom({ style, className, iconClassName, recording: recordingAtom, intercom: intercomAtom, intercomMode: intercomModeAtom, setIntercom, mute: muteAtom, setMute, getStreamStatus, onTouchStart, onTouchEnd, }: Props): React.JSX.Element;
13
13
  export {};
@@ -5,7 +5,7 @@ import clsx from 'clsx';
5
5
  import Res from './voice.gif';
6
6
  import { useStore, getDefaultStore } from '../../ctx/store';
7
7
  import './voiceIntercom.less';
8
- import { PlayerStreamStatus } from '../../interface';
8
+ import { PlayerStreamStatus, IntercomMode } from '../../interface';
9
9
  import { UIEventContext } from '../../ui/context';
10
10
  import { startTimeToHideAllComponent, pauseTimeToHideAllComponent } from '../../ui/constant';
11
11
  const NILL = () => null;
@@ -16,6 +16,7 @@ export function VoiceIntercom(_ref) {
16
16
  iconClassName,
17
17
  recording: recordingAtom,
18
18
  intercom: intercomAtom,
19
+ intercomMode: intercomModeAtom,
19
20
  setIntercom,
20
21
  mute: muteAtom,
21
22
  setMute,
@@ -28,10 +29,12 @@ export function VoiceIntercom(_ref) {
28
29
  } = useContext(UIEventContext);
29
30
  const {
30
31
  mute,
31
- intercom
32
+ intercom,
33
+ intercomMode
32
34
  } = useStore({
33
35
  mute: muteAtom,
34
- intercom: intercomAtom
36
+ intercom: intercomAtom,
37
+ intercomMode: intercomModeAtom
35
38
  });
36
39
  // 对讲开始之前的静音状态
37
40
  const originMuteStatusBeforeVoice = useRef(mute);
@@ -41,16 +44,28 @@ export function VoiceIntercom(_ref) {
41
44
  console.log('PlayerStreamStatus not 1002');
42
45
  return;
43
46
  }
47
+ console.log('==== 开始对讲 =====');
44
48
  originMuteStatusBeforeVoice.current = _mute;
45
- // 如果对讲开始之前,是静音的,则需要关闭静音
46
- if (_mute) {
47
- await setMute(false);
49
+ // 单路对讲,开始对讲前需要静音
50
+ // 双路对讲,开始对讲前需要打开拾音器
51
+ const muteTarget = intercomMode === IntercomMode.OneWay;
52
+ if (_mute !== muteTarget) {
53
+ console.log(`=== 切换静音状态: ${_mute}`, `${intercomMode}`);
54
+ await setMute(muteTarget);
48
55
  }
49
56
  await setIntercom(true);
50
57
  event.emit(pauseTimeToHideAllComponent);
51
58
  };
52
59
  const endVoice = async () => {
53
- await setMute(originMuteStatusBeforeVoice.current);
60
+ console.log('=== 结束对讲 ====');
61
+ // 单向对讲,结束对讲之后,强制关闭静态状态
62
+ if (intercomMode === IntercomMode.OneWay) {
63
+ console.log('=== 单向对讲,强制关闭静音状态 ===');
64
+ await setMute(false);
65
+ } else {
66
+ console.log(`=== 双向对讲,恢复对讲之前的静音状态 ${originMuteStatusBeforeVoice.current}===`);
67
+ await setMute(originMuteStatusBeforeVoice.current);
68
+ }
54
69
  await setIntercom(false);
55
70
  event.emit(startTimeToHideAllComponent);
56
71
  };
@@ -70,12 +85,17 @@ export function VoiceIntercom(_ref) {
70
85
  loading.current = false;
71
86
  return;
72
87
  }
73
- if (target) {
74
- await startVoice(mute);
75
- } else {
76
- await endVoice();
88
+ try {
89
+ if (target) {
90
+ await startVoice(mute);
91
+ } else {
92
+ await endVoice();
93
+ }
94
+ } catch (err) {
95
+ loading.current = false;
96
+ } finally {
97
+ loading.current = false;
77
98
  }
78
- loading.current = false;
79
99
  },
80
100
  onTouchEnd: onTouchEnd
81
101
  }, intercom ? /*#__PURE__*/React.createElement(Image, {
@@ -1,3 +1,4 @@
1
+ export { IntercomMode } from '@ray-js/ray-ipc-utils/lib/interface';
1
2
  export type UseBattery = (devId: string) => {
2
3
  batteryValue: number;
3
4
  batteryCharging: boolean;
@@ -1 +1,7 @@
1
- export {};
1
+ export { IntercomMode } from '@ray-js/ray-ipc-utils/lib/interface';
2
+
3
+ // plugin 获取电池电量 todo
4
+
5
+ // plugin 获取温度
6
+
7
+ // plugin 获取湿度
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ipc-player-integration",
3
- "version": "0.0.1-beta-13",
3
+ "version": "0.0.1-beta-14",
4
4
  "description": "IPC 播放器功能集成",
5
5
  "main": "lib/index",
6
6
  "files": [