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.

ParticipantsPane.js 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { ThemeProvider } from 'styled-components';
  4. import { openDialog } from '../../base/dialog';
  5. import { translate } from '../../base/i18n';
  6. import {
  7. getParticipantCount,
  8. isLocalParticipantModerator
  9. } from '../../base/participants';
  10. import { connect } from '../../base/redux';
  11. import { MuteEveryoneDialog } from '../../video-menu/components/';
  12. import { close } from '../actions';
  13. import { classList, findStyledAncestor, getParticipantsPaneOpen } from '../functions';
  14. import theme from '../theme.json';
  15. import { FooterContextMenu } from './FooterContextMenu';
  16. import { LobbyParticipantList } from './LobbyParticipantList';
  17. import { MeetingParticipantList } from './MeetingParticipantList';
  18. import {
  19. AntiCollapse,
  20. Close,
  21. Container,
  22. Footer,
  23. FooterButton,
  24. FooterEllipsisButton,
  25. FooterEllipsisContainer,
  26. Header
  27. } from './styled';
  28. /**
  29. * The type of the React {@code Component} props of {@link ParticipantsPane}.
  30. */
  31. type Props = {
  32. /**
  33. * Is the participants pane open.
  34. */
  35. _paneOpen: boolean,
  36. /**
  37. * Whether to show context menu.
  38. */
  39. _showContextMenu: boolean,
  40. /**
  41. * Whether to show the footer menu.
  42. */
  43. _showFooter: boolean,
  44. /**
  45. * The Redux dispatch function.
  46. */
  47. dispatch: Function,
  48. /**
  49. * The i18n translate function.
  50. */
  51. t: Function
  52. };
  53. /**
  54. * The type of the React {@code Component} state of {@link ParticipantsPane}.
  55. */
  56. type State = {
  57. /**
  58. * Indicates if the footer context menu is open.
  59. */
  60. contextOpen: boolean,
  61. };
  62. /**
  63. * Implements the participants list.
  64. */
  65. class ParticipantsPane extends Component<Props, State> {
  66. /**
  67. * Initializes a new {@code ParticipantsPane} instance.
  68. *
  69. * @inheritdoc
  70. */
  71. constructor(props) {
  72. super(props);
  73. this.state = {
  74. contextOpen: false
  75. };
  76. // Bind event handlers so they are only bound once per instance.
  77. this._onClosePane = this._onClosePane.bind(this);
  78. this._onKeyPress = this._onKeyPress.bind(this);
  79. this._onMuteAll = this._onMuteAll.bind(this);
  80. this._onToggleContext = this._onToggleContext.bind(this);
  81. this._onWindowClickListener = this._onWindowClickListener.bind(this);
  82. }
  83. /**
  84. * Implements React's {@link Component#componentDidMount()}.
  85. *
  86. * @inheritdoc
  87. */
  88. componentDidMount() {
  89. window.addEventListener('click', this._onWindowClickListener);
  90. }
  91. /**
  92. * Implements React's {@link Component#componentWillUnmount()}.
  93. *
  94. * @inheritdoc
  95. */
  96. componentWillUnmount() {
  97. window.removeEventListener('click', this._onWindowClickListener);
  98. }
  99. /**
  100. * Implements React's {@link Component#render}.
  101. *
  102. * @inheritdoc
  103. */
  104. render() {
  105. const {
  106. _paneOpen,
  107. _showContextMenu,
  108. _showFooter,
  109. t
  110. } = this.props;
  111. // when the pane is not open optimize to not
  112. // execute the MeetingParticipantList render for large list of participants
  113. if (!_paneOpen) {
  114. return null;
  115. }
  116. return (
  117. <ThemeProvider theme = { theme }>
  118. <div className = { classList('participants_pane', !_paneOpen && 'participants_pane--closed') }>
  119. <div className = 'participants_pane-content'>
  120. <Header>
  121. <Close
  122. aria-label = { t('participantsPane.close', 'Close') }
  123. onClick = { this._onClosePane }
  124. onKeyPress = { this._onKeyPress }
  125. role = 'button'
  126. tabIndex = { 0 } />
  127. </Header>
  128. <Container>
  129. <LobbyParticipantList />
  130. <AntiCollapse />
  131. <MeetingParticipantList />
  132. </Container>
  133. {_showFooter && (
  134. <Footer>
  135. <FooterButton onClick = { this._onMuteAll }>
  136. {t('participantsPane.actions.muteAll')}
  137. </FooterButton>
  138. {_showContextMenu && (
  139. <FooterEllipsisContainer>
  140. <FooterEllipsisButton
  141. id = 'participants-pane-context-menu'
  142. onClick = { this._onToggleContext } />
  143. {this.state.contextOpen
  144. && <FooterContextMenu onMouseLeave = { this._onToggleContext } />}
  145. </FooterEllipsisContainer>
  146. )}
  147. </Footer>
  148. )}
  149. </div>
  150. </div>
  151. </ThemeProvider>
  152. );
  153. }
  154. _onClosePane: () => void;
  155. /**
  156. * Callback for closing the participant pane.
  157. *
  158. * @private
  159. * @returns {void}
  160. */
  161. _onClosePane() {
  162. this.props.dispatch(close());
  163. }
  164. _onKeyPress: (Object) => void;
  165. /**
  166. * KeyPress handler for accessibility for closing the participants pane.
  167. *
  168. * @param {Object} e - The key event to handle.
  169. *
  170. * @returns {void}
  171. */
  172. _onKeyPress(e) {
  173. if (e.key === ' ' || e.key === 'Enter') {
  174. e.preventDefault();
  175. this._onClosePane();
  176. }
  177. }
  178. _onMuteAll: () => void;
  179. /**
  180. * The handler for clicking mute all button.
  181. *
  182. * @returns {void}
  183. */
  184. _onMuteAll() {
  185. this.props.dispatch(openDialog(MuteEveryoneDialog));
  186. }
  187. _onToggleContext: () => void;
  188. /**
  189. * Handler for toggling open/close of the footer context menu.
  190. *
  191. * @returns {void}
  192. */
  193. _onToggleContext() {
  194. this.setState({
  195. contextOpen: !this.state.contextOpen
  196. });
  197. }
  198. _onWindowClickListener: (event: Object) => void;
  199. /**
  200. * Window click event listener.
  201. *
  202. * @param {Event} e - The click event.
  203. * @returns {void}
  204. */
  205. _onWindowClickListener(e) {
  206. if (this.state.contextOpen && !findStyledAncestor(e.target, FooterEllipsisContainer)) {
  207. this.setState({
  208. contextOpen: false
  209. });
  210. }
  211. }
  212. }
  213. /**
  214. * Maps (parts of) the redux state to the React {@code Component} props of
  215. * {@code ParticipantsPane}.
  216. *
  217. * @param {Object} state - The redux state.
  218. * @protected
  219. * @returns {{
  220. * _paneOpen: boolean,
  221. * _showContextMenu: boolean,
  222. * _showFooter: boolean
  223. * }}
  224. */
  225. function _mapStateToProps(state: Object) {
  226. const isPaneOpen = getParticipantsPaneOpen(state);
  227. return {
  228. _paneOpen: isPaneOpen,
  229. _showContextMenu: isPaneOpen && getParticipantCount(state) > 2,
  230. _showFooter: isPaneOpen && isLocalParticipantModerator(state)
  231. };
  232. }
  233. export default translate(connect(_mapStateToProps)(ParticipantsPane));