Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

LobbySection.js 3.6KB

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