您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FakeParticipantContextMenu.tsx 4.9KB

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