您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

LobbySection.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 { toggleLobbyMode } from '../../actions';
  8. type Props = {
  9. /**
  10. * True if lobby is currently enabled in the conference.
  11. */
  12. _lobbyEnabled: boolean,
  13. /**
  14. * True if the section should be visible.
  15. */
  16. _visible: boolean,
  17. /**
  18. * The Redux Dispatch function.
  19. */
  20. dispatch: Function,
  21. /**
  22. * Function to be used to translate i18n labels.
  23. */
  24. t: Function
  25. };
  26. type State = {
  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<Props, State> {
  36. /**
  37. * Instantiates a new component.
  38. *
  39. * @inheritdoc
  40. */
  41. constructor(props: Props) {
  42. super(props);
  43. this.state = {
  44. lobbyEnabled: props._lobbyEnabled
  45. };
  46. this._onToggleLobby = this._onToggleLobby.bind(this);
  47. }
  48. /**
  49. * Implements {@code PureComponent#componentDidUpdate}.
  50. *
  51. * @inheritdoc
  52. */
  53. componentDidUpdate(prevProps, prevState) {
  54. if (this.props._lobbyEnabled !== prevProps._lobbyEnabled
  55. && this.state.lobbyEnabled !== prevState.lobbyEnabled) {
  56. // eslint-disable-next-line react/no-did-update-set-state
  57. this.setState({
  58. lobbyEnabled: this.props._lobbyEnabled
  59. });
  60. }
  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 className = 'description'>
  76. { t('lobby.enableDialogText') }
  77. </p>
  78. <div className = 'control-row'>
  79. <label>
  80. { t('lobby.toggleLabel') }
  81. </label>
  82. <Switch
  83. onValueChange = { this._onToggleLobby }
  84. value = { this.state.lobbyEnabled } />
  85. </div>
  86. </div>
  87. <div className = 'separator-line' />
  88. </>
  89. );
  90. }
  91. _onToggleLobby: () => void;
  92. /**
  93. * Callback to be invoked when the user toggles the lobby feature on or off.
  94. *
  95. * @returns {void}
  96. */
  97. _onToggleLobby() {
  98. const newValue = !this.state.lobbyEnabled;
  99. this.setState({
  100. lobbyEnabled: newValue
  101. });
  102. this.props.dispatch(toggleLobbyMode(newValue));
  103. }
  104. }
  105. /**
  106. * Maps part of the Redux state to the props of this component.
  107. *
  108. * @param {Object} state - The Redux state.
  109. * @returns {Props}
  110. */
  111. function mapStateToProps(state: Object): $Shape<Props> {
  112. const { conference } = state['features/base/conference'];
  113. return {
  114. _lobbyEnabled: state['features/lobby'].lobbyEnabled,
  115. _visible: conference && conference.isLobbySupported() && isLocalParticipantModerator(state)
  116. };
  117. }
  118. export default translate(connect(mapStateToProps)(LobbySection));