Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

FakeParticipantContextMenu.tsx 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import React, { useCallback } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { useDispatch, useSelector } from 'react-redux';
  4. import TogglePinToStageButton from '../../../../features/video-menu/components/web/TogglePinToStageButton';
  5. import Avatar from '../../../base/avatar/components/Avatar';
  6. import { getButtonNotifyMode, getParticipantMenuButtonsWithNotifyClick } from '../../../base/config/functions.web';
  7. import { IconPlay } from '../../../base/icons/svg';
  8. import { isWhiteboardParticipant } from '../../../base/participants/functions';
  9. import { IParticipant } from '../../../base/participants/types';
  10. import ContextMenu from '../../../base/ui/components/web/ContextMenu';
  11. import ContextMenuItemGroup from '../../../base/ui/components/web/ContextMenuItemGroup';
  12. import { stopSharedVideo } from '../../../shared-video/actions.any';
  13. import { NOTIFY_CLICK_MODE } from '../../../toolbox/constants';
  14. import { showOverflowDrawer } from '../../../toolbox/functions.web';
  15. import { setWhiteboardOpen } from '../../../whiteboard/actions';
  16. import { WHITEBOARD_ID } from '../../../whiteboard/constants';
  17. import { PARTICIPANT_MENU_BUTTONS as BUTTONS } from '../../constants';
  18. interface IProps {
  19. /**
  20. * Class name for the context menu.
  21. */
  22. className?: string;
  23. /**
  24. * Closes a drawer if open.
  25. */
  26. closeDrawer?: () => void;
  27. /**
  28. * The participant for which the drawer is open.
  29. * It contains the displayName & participantID.
  30. */
  31. drawerParticipant?: {
  32. displayName: string;
  33. participantID: string;
  34. };
  35. /**
  36. * Shared video local participant owner.
  37. */
  38. localVideoOwner?: boolean;
  39. /**
  40. * Target elements against which positioning calculations are made.
  41. */
  42. offsetTarget?: HTMLElement;
  43. /**
  44. * Callback for the mouse entering the component.
  45. */
  46. onEnter?: (e?: React.MouseEvent) => void;
  47. /**
  48. * Callback for the mouse leaving the component.
  49. */
  50. onLeave?: (e?: React.MouseEvent) => void;
  51. /**
  52. * Callback for making a selection in the menu.
  53. */
  54. onSelect: (value?: boolean | React.MouseEvent) => void;
  55. /**
  56. * Participant reference.
  57. */
  58. participant: IParticipant;
  59. /**
  60. * Whether or not the menu is displayed in the thumbnail remote video menu.
  61. */
  62. thumbnailMenu?: boolean;
  63. }
  64. const FakeParticipantContextMenu = ({
  65. className,
  66. closeDrawer,
  67. drawerParticipant,
  68. localVideoOwner,
  69. offsetTarget,
  70. onEnter,
  71. onLeave,
  72. onSelect,
  73. participant,
  74. thumbnailMenu
  75. }: IProps) => {
  76. const dispatch = useDispatch();
  77. const { t } = useTranslation();
  78. const _overflowDrawer: boolean = useSelector(showOverflowDrawer);
  79. const buttonsWithNotifyClick = useSelector(getParticipantMenuButtonsWithNotifyClick);
  80. const notifyClick = useCallback(
  81. (buttonKey: string, participantId?: string) => {
  82. const notifyMode = getButtonNotifyMode(buttonKey, buttonsWithNotifyClick);
  83. if (!notifyMode) {
  84. return;
  85. }
  86. APP.API.notifyParticipantMenuButtonClicked(
  87. buttonKey,
  88. participantId,
  89. notifyMode === NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY
  90. );
  91. }, [ buttonsWithNotifyClick, getButtonNotifyMode ]);
  92. const clickHandler = useCallback(() => onSelect(true), [ onSelect ]);
  93. const _onStopSharedVideo = useCallback(() => {
  94. clickHandler();
  95. dispatch(stopSharedVideo());
  96. }, [ stopSharedVideo ]);
  97. const _onHideWhiteboard = useCallback(() => {
  98. clickHandler();
  99. dispatch(setWhiteboardOpen(false));
  100. }, [ setWhiteboardOpen ]);
  101. const _getActions = useCallback(() => {
  102. if (isWhiteboardParticipant(participant)) {
  103. return [ {
  104. accessibilityLabel: t('toolbar.hideWhiteboard'),
  105. icon: IconPlay,
  106. onClick: _onHideWhiteboard,
  107. text: t('toolbar.hideWhiteboard')
  108. } ];
  109. }
  110. if (localVideoOwner) {
  111. return [ {
  112. accessibilityLabel: t('toolbar.stopSharedVideo'),
  113. icon: IconPlay,
  114. onClick: _onStopSharedVideo,
  115. text: t('toolbar.stopSharedVideo')
  116. } ];
  117. }
  118. }, [ localVideoOwner, participant.fakeParticipant ]);
  119. return (
  120. <ContextMenu
  121. className = { className }
  122. entity = { participant }
  123. hidden = { thumbnailMenu ? false : undefined }
  124. inDrawer = { thumbnailMenu && _overflowDrawer }
  125. isDrawerOpen = { Boolean(drawerParticipant) }
  126. offsetTarget = { offsetTarget }
  127. onClick = { onSelect }
  128. onDrawerClose = { thumbnailMenu ? onSelect : closeDrawer }
  129. onMouseEnter = { onEnter }
  130. onMouseLeave = { onLeave }>
  131. {!thumbnailMenu && _overflowDrawer && drawerParticipant && <ContextMenuItemGroup
  132. actions = { [ {
  133. accessibilityLabel: drawerParticipant.displayName,
  134. customIcon: <Avatar
  135. participantId = { drawerParticipant.participantID }
  136. size = { 20 } />,
  137. text: drawerParticipant.displayName
  138. } ] } />}
  139. <ContextMenuItemGroup
  140. actions = { _getActions() }>
  141. {isWhiteboardParticipant(participant) && (
  142. <TogglePinToStageButton
  143. key = 'pinToStage'
  144. // eslint-disable-next-line react/jsx-no-bind
  145. notifyClick = { () => notifyClick(BUTTONS.PIN_TO_STAGE, WHITEBOARD_ID) }
  146. notifyMode = { getButtonNotifyMode(BUTTONS.PIN_TO_STAGE, buttonsWithNotifyClick) }
  147. participantID = { WHITEBOARD_ID } />
  148. )}
  149. </ContextMenuItemGroup>
  150. </ContextMenu>
  151. );
  152. };
  153. export default FakeParticipantContextMenu;