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.

LobbySection.tsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* eslint-disable lines-around-comment */
  2. import React, { PureComponent } from 'react';
  3. import { WithTranslation } from 'react-i18next';
  4. import { IState } from '../../../app/types';
  5. import { translate } from '../../../base/i18n/functions';
  6. import { isLocalParticipantModerator } from '../../../base/participants/functions';
  7. import { connect } from '../../../base/redux/functions';
  8. import Switch from '../../../base/ui/components/web/Switch';
  9. // @ts-ignore
  10. import { isInBreakoutRoom } from '../../../breakout-rooms/functions';
  11. // @ts-ignore
  12. import { toggleLobbyMode } from '../../actions';
  13. interface Props extends WithTranslation {
  14. /**
  15. * True if lobby is currently enabled in the conference.
  16. */
  17. _lobbyEnabled: boolean;
  18. /**
  19. * True if the section should be visible.
  20. */
  21. _visible: boolean;
  22. /**
  23. * The Redux Dispatch function.
  24. */
  25. dispatch: 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: State) {
  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. checked = { this.state.lobbyEnabled }
  86. id = 'lobby-section-switch'
  87. onChange = { this._onToggleLobby } />
  88. </div>
  89. </div>
  90. <div className = 'separator-line' />
  91. </>
  92. );
  93. }
  94. /**
  95. * Callback to be invoked when the user toggles the lobby feature on or off.
  96. *
  97. * @returns {void}
  98. */
  99. _onToggleLobby() {
  100. const newValue = !this.state.lobbyEnabled;
  101. this.setState({
  102. lobbyEnabled: newValue
  103. });
  104. this.props.dispatch(toggleLobbyMode(newValue));
  105. }
  106. }
  107. /**
  108. * Maps part of the Redux state to the props of this component.
  109. *
  110. * @param {Object} state - The Redux state.
  111. * @returns {Props}
  112. */
  113. function mapStateToProps(state: IState): Partial<Props> {
  114. const { conference } = state['features/base/conference'];
  115. const { hideLobbyButton } = state['features/base/config'];
  116. return {
  117. _lobbyEnabled: state['features/lobby'].lobbyEnabled,
  118. _visible: conference?.isLobbySupported() && isLocalParticipantModerator(state)
  119. && !hideLobbyButton && !isInBreakoutRoom(state)
  120. };
  121. }
  122. export default translate(connect(mapStateToProps)(LobbySection));