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 4.8KB

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