Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

FakeParticipantContextMenu.tsx 5.7KB

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