Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

LobbySection.tsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import React, { PureComponent } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { IReduxState } from '../../../app/types';
  4. import { translate } from '../../../base/i18n/functions';
  5. import { isLocalParticipantModerator } from '../../../base/participants/functions';
  6. import { connect } from '../../../base/redux/functions';
  7. import Switch from '../../../base/ui/components/web/Switch';
  8. import { isInBreakoutRoom } from '../../../breakout-rooms/functions';
  9. // eslint-disable-next-line lines-around-comment
  10. // @ts-ignore
  11. import { toggleLobbyMode } from '../../actions';
  12. interface IProps extends WithTranslation {
  13. /**
  14. * True if lobby is currently enabled in the conference.
  15. */
  16. _lobbyEnabled: boolean;
  17. /**
  18. * True if the section should be visible.
  19. */
  20. _visible: boolean;
  21. /**
  22. * The Redux Dispatch function.
  23. */
  24. dispatch: Function;
  25. }
  26. interface IState {
  27. /**
  28. * True if the lobby switch is toggled on.
  29. */
  30. lobbyEnabled: boolean;
  31. }
  32. /**
  33. * Implements a security feature section to control lobby mode.
  34. */
  35. class LobbySection extends PureComponent<IProps, IState> {
  36. /**
  37. * Instantiates a new component.
  38. *
  39. * @inheritdoc
  40. */
  41. constructor(props: IProps) {
  42. super(props);
  43. this.state = {
  44. lobbyEnabled: props._lobbyEnabled
  45. };
  46. this._onToggleLobby = this._onToggleLobby.bind(this);
  47. }
  48. /**
  49. * Implements React's {@link Component#getDerivedStateFromProps()}.
  50. *
  51. * @inheritdoc
  52. */
  53. static getDerivedStateFromProps(props: IProps, state: IState) {
  54. if (props._lobbyEnabled !== state.lobbyEnabled) {
  55. return {
  56. lobbyEnabled: props._lobbyEnabled
  57. };
  58. }
  59. return null;
  60. }
  61. /**
  62. * Implements {@code PureComponent#render}.
  63. *
  64. * @inheritdoc
  65. */
  66. render() {
  67. const { _visible, t } = this.props;
  68. if (!_visible) {
  69. return null;
  70. }
  71. return (
  72. <>
  73. <div id = 'lobby-section'>
  74. <p
  75. className = 'description'
  76. role = 'banner'>
  77. { t('lobby.enableDialogText') }
  78. </p>
  79. <div className = 'control-row'>
  80. <label htmlFor = 'lobby-section-switch'>
  81. { t('lobby.toggleLabel') }
  82. </label>
  83. <Switch
  84. checked = { this.state.lobbyEnabled }
  85. id = 'lobby-section-switch'
  86. onChange = { this._onToggleLobby } />
  87. </div>
  88. </div>
  89. <div className = 'separator-line' />
  90. </>
  91. );
  92. }
  93. /**
  94. * Callback to be invoked when the user toggles the lobby feature on or off.
  95. *
  96. * @returns {void}
  97. */
  98. _onToggleLobby() {
  99. const newValue = !this.state.lobbyEnabled;
  100. this.setState({
  101. lobbyEnabled: newValue
  102. });
  103. this.props.dispatch(toggleLobbyMode(newValue));
  104. }
  105. }
  106. /**
  107. * Maps part of the Redux state to the props of this component.
  108. *
  109. * @param {Object} state - The Redux state.
  110. * @returns {IProps}
  111. */
  112. function mapStateToProps(state: IReduxState): Partial<IProps> {
  113. const { conference } = state['features/base/conference'];
  114. const { hideLobbyButton } = state['features/base/config'];
  115. return {
  116. _lobbyEnabled: state['features/lobby'].lobbyEnabled,
  117. _visible: conference?.isLobbySupported() && isLocalParticipantModerator(state)
  118. && !hideLobbyButton && !isInBreakoutRoom(state)
  119. };
  120. }
  121. export default translate(connect(mapStateToProps)(LobbySection));