@ray-js/ipc-player-integration 0.0.62 → 0.0.63

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.
@@ -17,13 +17,19 @@ export const Muted = props => {
17
17
  } = useContext(UIEventContext);
18
18
  const event = propsEvent !== null && propsEvent !== void 0 ? propsEvent : ctxEvent;
19
19
  const {
20
- isMuted
20
+ isMuted,
21
+ intercom
21
22
  } = useStore({
22
- isMuted: mute
23
+ isMuted: mute,
24
+ intercom: props.intercom
23
25
  });
26
+ const disabled = intercom;
24
27
  return /*#__PURE__*/React.createElement(View, {
25
- className: clsx(className),
28
+ className: clsx(className, {
29
+ 'ipc-player-plugin-muted-disabled': disabled
30
+ }),
26
31
  onClick: () => {
32
+ if (disabled) return;
27
33
  event.emit(widgetClick, {
28
34
  widgetId: widgetLabs.MUTED
29
35
  });
@@ -8,4 +8,8 @@
8
8
  .ipc-player-plugin-muted-text-icon {
9
9
  color: var(--iconColor);
10
10
  font-size: calc(var(--iconPlayerSize) * var(--ipc-player-size-scale, 1)) !important;
11
- }
11
+ }
12
+
13
+ .ipc-player-plugin-muted-disabled {
14
+ opacity: 0.4;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ import { act, renderHook } from '@testing-library/react-hooks/dom';
2
+ import { atom, getDefaultStore } from 'jotai';
3
+ import { IntercomMode } from '../../interface';
4
+ import { Muted } from './muted';
5
+ jest.mock('@ray-js/ray', () => ({
6
+ View: 'div',
7
+ Text: 'span'
8
+ }));
9
+ jest.mock('@ray-js/ray-ipc-utils/lib/interface', () => ({
10
+ IntercomMode: {
11
+ OneWay: 'OneWay',
12
+ TwoWay: 'TwoWay'
13
+ }
14
+ }));
15
+ jest.mock('./muted.less', () => ({}));
16
+ const createProps = function () {
17
+ let talking = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
18
+ let mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : IntercomMode.OneWay;
19
+ let muted = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
20
+ return {
21
+ mute: atom(muted),
22
+ intercom: atom(talking),
23
+ intercomMode: atom(mode),
24
+ setMute: jest.fn(),
25
+ event: {
26
+ emit: jest.fn()
27
+ }
28
+ };
29
+ };
30
+ it.each([[IntercomMode.OneWay, true], [IntercomMode.OneWay, false], [IntercomMode.TwoWay, true], [IntercomMode.TwoWay, false]])('blocks speaker changes and control events during talk in mode=%s, muted=%s', (mode, muted) => {
31
+ const props = createProps(true, mode, muted);
32
+ const {
33
+ result,
34
+ unmount
35
+ } = renderHook(() => Muted(props));
36
+ act(() => result.current.props.onClick());
37
+ expect(props.setMute).not.toHaveBeenCalled();
38
+ expect(props.event.emit).not.toHaveBeenCalled();
39
+ expect(result.current.props.className).toContain('ipc-player-plugin-muted-disabled');
40
+ unmount();
41
+ });
42
+ it.each([[false, IntercomMode.OneWay, true, false], [false, IntercomMode.OneWay, false, true], [false, IntercomMode.TwoWay, true, false], [false, IntercomMode.TwoWay, false, true]])('keeps speaker switching when talking=%s, mode=%s, muted=%s', (talking, mode, muted, target) => {
43
+ const props = createProps(talking, mode, muted);
44
+ const {
45
+ result,
46
+ unmount
47
+ } = renderHook(() => Muted(props));
48
+ act(() => result.current.props.onClick());
49
+ expect(props.setMute).toHaveBeenCalledTimes(1);
50
+ expect(props.setMute).toHaveBeenCalledWith(target);
51
+ expect(result.current.props.className).not.toContain('ipc-player-plugin-muted-disabled');
52
+ unmount();
53
+ });
54
+ it.each([IntercomMode.OneWay, IntercomMode.TwoWay])('uses shared talk state after remount and unlocks when talk ends in mode=%s', mode => {
55
+ const props = createProps(false, mode);
56
+ const store = getDefaultStore();
57
+ const first = renderHook(() => Muted(props));
58
+ act(() => store.set(props.intercom, true));
59
+ act(() => first.result.current.props.onClick());
60
+ expect(props.setMute).not.toHaveBeenCalled();
61
+ first.unmount();
62
+ const second = renderHook(() => Muted(props));
63
+ act(() => second.result.current.props.onClick());
64
+ expect(props.setMute).not.toHaveBeenCalled();
65
+ act(() => store.set(props.intercom, false));
66
+ act(() => second.result.current.props.onClick());
67
+ expect(props.setMute).toHaveBeenCalledWith(false);
68
+ second.unmount();
69
+ });
70
+ it.each([[IntercomMode.OneWay, IntercomMode.TwoWay], [IntercomMode.TwoWay, IntercomMode.OneWay]])('keeps the speaker locked when active talk changes from %s to %s', (mode, nextMode) => {
71
+ const props = createProps(true, mode);
72
+ const {
73
+ result,
74
+ unmount
75
+ } = renderHook(() => Muted(props));
76
+ act(() => getDefaultStore().set(props.intercomMode, nextMode));
77
+ act(() => result.current.props.onClick());
78
+ expect(props.setMute).not.toHaveBeenCalled();
79
+ expect(props.event.emit).not.toHaveBeenCalled();
80
+ unmount();
81
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ipc-player-integration",
3
- "version": "0.0.62",
3
+ "version": "0.0.63",
4
4
  "description": "IPC 融合播放器",
5
5
  "main": "lib/index",
6
6
  "files": [