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.9KB

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