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

LobbySection.tsx 3.6KB

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