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.

MeetingParticipants.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // @flow
  2. import React, { useCallback, useRef, useState } from 'react';
  3. import { useTranslation } from 'react-i18next';
  4. import { useDispatch } from 'react-redux';
  5. import { isToolbarButtonEnabled } from '../../../base/config/functions.web';
  6. import { MEDIA_TYPE } from '../../../base/media';
  7. import {
  8. getParticipantCountWithFake,
  9. getSortedParticipantIds
  10. } from '../../../base/participants';
  11. import { connect } from '../../../base/redux';
  12. import { showOverflowDrawer } from '../../../toolbox/functions';
  13. import { muteRemote } from '../../../video-menu/actions.any';
  14. import { findStyledAncestor, shouldRenderInviteButton } from '../../functions';
  15. import { useParticipantDrawer } from '../../hooks';
  16. import { InviteButton } from './InviteButton';
  17. import MeetingParticipantContextMenu from './MeetingParticipantContextMenu';
  18. import MeetingParticipantItems from './MeetingParticipantItems';
  19. import { Heading, ParticipantContainer } from './styled';
  20. type NullProto = {
  21. [key: string]: any,
  22. __proto__: null
  23. };
  24. type RaiseContext = NullProto | {|
  25. /**
  26. * Target elements against which positioning calculations are made.
  27. */
  28. offsetTarget?: HTMLElement,
  29. /**
  30. * The ID of the participant.
  31. */
  32. participantID ?: string,
  33. |};
  34. const initialState = Object.freeze(Object.create(null));
  35. /**
  36. * Renders the MeetingParticipantList component.
  37. * NOTE: This component is not using useSelector on purpose. The child components MeetingParticipantItem
  38. * and MeetingParticipantContextMenu are using connect. Having those mixed leads to problems.
  39. * When this one was using useSelector and the other two were not -the other two were re-rendered before this one was
  40. * re-rendered, so when participant is leaving, we first re-render the item and menu components,
  41. * throwing errors (closing the page) before removing those components for the participant that left.
  42. *
  43. * @returns {ReactNode} - The component.
  44. */
  45. function MeetingParticipants({ participantsCount, showInviteButton, overflowDrawer, sortedParticipantIds = [] }) {
  46. const dispatch = useDispatch();
  47. const isMouseOverMenu = useRef(false);
  48. const [ raiseContext, setRaiseContext ] = useState < RaiseContext >(initialState);
  49. const { t } = useTranslation();
  50. const lowerMenu = useCallback(() => {
  51. /**
  52. * We are tracking mouse movement over the active participant item and
  53. * the context menu. Due to the order of enter/leave events, we need to
  54. * defer checking if the mouse is over the context menu with
  55. * queueMicrotask
  56. */
  57. window.queueMicrotask(() => {
  58. if (isMouseOverMenu.current) {
  59. return;
  60. }
  61. if (raiseContext !== initialState) {
  62. setRaiseContext(initialState);
  63. }
  64. });
  65. }, [ raiseContext ]);
  66. const raiseMenu = useCallback((participantID, target) => {
  67. setRaiseContext({
  68. participantID,
  69. offsetTarget: findStyledAncestor(target, ParticipantContainer)
  70. });
  71. }, [ raiseContext ]);
  72. const toggleMenu = useCallback(participantID => e => {
  73. const { participantID: raisedParticipant } = raiseContext;
  74. if (raisedParticipant && raisedParticipant === participantID) {
  75. lowerMenu();
  76. } else {
  77. raiseMenu(participantID, e.target);
  78. }
  79. }, [ raiseContext ]);
  80. const menuEnter = useCallback(() => {
  81. isMouseOverMenu.current = true;
  82. }, []);
  83. const menuLeave = useCallback(() => {
  84. isMouseOverMenu.current = false;
  85. lowerMenu();
  86. }, [ lowerMenu ]);
  87. const muteAudio = useCallback(id => () => {
  88. dispatch(muteRemote(id, MEDIA_TYPE.AUDIO));
  89. }, [ dispatch ]);
  90. const [ drawerParticipant, closeDrawer, openDrawerForParticipant ] = useParticipantDrawer();
  91. // FIXME:
  92. // It seems that useTranslation is not very scallable. Unmount 500 components that have the useTranslation hook is
  93. // taking more than 10s. To workaround the issue we need to pass the texts as props. This is temporary and dirty
  94. // solution!!!
  95. // One potential proper fix would be to use react-window component in order to lower the number of components
  96. // mounted.
  97. const participantActionEllipsisLabel = t('MeetingParticipantItem.ParticipantActionEllipsis.options');
  98. const youText = t('chat.you');
  99. const askUnmuteText = t('participantsPane.actions.askUnmute');
  100. const muteParticipantButtonText = t('dialog.muteParticipantButton');
  101. return (
  102. <>
  103. <Heading>{t('participantsPane.headings.participantsList', { count: participantsCount })}</Heading>
  104. {showInviteButton && <InviteButton />}
  105. <div>
  106. <MeetingParticipantItems
  107. askUnmuteText = { askUnmuteText }
  108. lowerMenu = { lowerMenu }
  109. muteAudio = { muteAudio }
  110. muteParticipantButtonText = { muteParticipantButtonText }
  111. openDrawerForParticipant = { openDrawerForParticipant }
  112. overflowDrawer = { overflowDrawer }
  113. participantActionEllipsisLabel = { participantActionEllipsisLabel }
  114. participantIds = { sortedParticipantIds }
  115. participantsCount = { participantsCount }
  116. raiseContextId = { raiseContext.participantID }
  117. toggleMenu = { toggleMenu }
  118. youText = { youText } />
  119. </div>
  120. <MeetingParticipantContextMenu
  121. closeDrawer = { closeDrawer }
  122. drawerParticipant = { drawerParticipant }
  123. muteAudio = { muteAudio }
  124. onEnter = { menuEnter }
  125. onLeave = { menuLeave }
  126. onSelect = { lowerMenu }
  127. overflowDrawer = { overflowDrawer }
  128. { ...raiseContext } />
  129. </>
  130. );
  131. }
  132. /**
  133. * Maps (parts of) the redux state to the associated props for this component.
  134. *
  135. * @param {Object} state - The Redux state.
  136. * @param {Object} ownProps - The own props of the component.
  137. * @private
  138. * @returns {Props}
  139. */
  140. function _mapStateToProps(state): Object {
  141. const sortedParticipantIds = getSortedParticipantIds(state);
  142. // This is very important as getRemoteParticipants is not changing its reference object
  143. // and we will not re-render on change, but if count changes we will do
  144. const participantsCount = getParticipantCountWithFake(state);
  145. const showInviteButton = shouldRenderInviteButton(state) && isToolbarButtonEnabled('invite', state);
  146. const overflowDrawer = showOverflowDrawer(state);
  147. return {
  148. sortedParticipantIds,
  149. participantsCount,
  150. showInviteButton,
  151. overflowDrawer
  152. };
  153. }
  154. export default connect(_mapStateToProps)(MeetingParticipants);