You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FakeParticipantContextMenu.tsx 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import React, { useCallback } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { useDispatch, useSelector } from 'react-redux';
  4. // @ts-ignore
  5. import TogglePinToStageButton from '../../../../features/video-menu/components/web/TogglePinToStageButton';
  6. // eslint-disable-next-line lines-around-comment
  7. // @ts-ignore
  8. import { Avatar } from '../../../base/avatar';
  9. import { IconPlay } from '../../../base/icons/svg';
  10. import { isWhiteboardParticipant } from '../../../base/participants/functions';
  11. import { IParticipant } from '../../../base/participants/types';
  12. import ContextMenu from '../../../base/ui/components/web/ContextMenu';
  13. import ContextMenuItemGroup from '../../../base/ui/components/web/ContextMenuItemGroup';
  14. import { stopSharedVideo } from '../../../shared-video/actions.any';
  15. import { showOverflowDrawer } from '../../../toolbox/functions.web';
  16. import { setWhiteboardOpen } from '../../../whiteboard/actions';
  17. import { WHITEBOARD_ID } from '../../../whiteboard/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 clickHandler = useCallback(() => onSelect(true), [ onSelect ]);
  80. const _onStopSharedVideo = useCallback(() => {
  81. clickHandler();
  82. dispatch(stopSharedVideo());
  83. }, [ stopSharedVideo ]);
  84. const _onHideWhiteboard = useCallback(() => {
  85. clickHandler();
  86. dispatch(setWhiteboardOpen(false));
  87. }, [ setWhiteboardOpen ]);
  88. const _getActions = useCallback(() => {
  89. if (isWhiteboardParticipant(participant)) {
  90. return [ {
  91. accessibilityLabel: t('toolbar.hideWhiteboard'),
  92. icon: IconPlay,
  93. onClick: _onHideWhiteboard,
  94. text: t('toolbar.hideWhiteboard')
  95. } ];
  96. }
  97. if (localVideoOwner) {
  98. return [ {
  99. accessibilityLabel: t('toolbar.stopSharedVideo'),
  100. icon: IconPlay,
  101. onClick: _onStopSharedVideo,
  102. text: t('toolbar.stopSharedVideo')
  103. } ];
  104. }
  105. }, [ localVideoOwner, participant.fakeParticipant ]);
  106. return (
  107. <ContextMenu
  108. className = { className }
  109. entity = { participant }
  110. hidden = { thumbnailMenu ? false : undefined }
  111. inDrawer = { thumbnailMenu && _overflowDrawer }
  112. isDrawerOpen = { Boolean(drawerParticipant) }
  113. offsetTarget = { offsetTarget }
  114. onClick = { onSelect }
  115. onDrawerClose = { thumbnailMenu ? onSelect : closeDrawer }
  116. onMouseEnter = { onEnter }
  117. onMouseLeave = { onLeave }>
  118. {!thumbnailMenu && _overflowDrawer && drawerParticipant && <ContextMenuItemGroup
  119. actions = { [ {
  120. accessibilityLabel: drawerParticipant.displayName,
  121. customIcon: <Avatar
  122. participantId = { drawerParticipant.participantID }
  123. size = { 20 } />,
  124. text: drawerParticipant.displayName
  125. } ] } />}
  126. <ContextMenuItemGroup
  127. actions = { _getActions() }>
  128. {isWhiteboardParticipant(participant) && (
  129. <TogglePinToStageButton
  130. key = 'pinToStage'
  131. participantID = { WHITEBOARD_ID } />
  132. )}
  133. </ContextMenuItemGroup>
  134. </ContextMenu>
  135. );
  136. };
  137. export default FakeParticipantContextMenu;