You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SecurityDialogButton.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { createToolbarEvent, sendAnalytics } from '../../../analytics';
  4. import {
  5. getFeatureFlag,
  6. LOBBY_MODE_ENABLED,
  7. MEETING_PASSWORD_ENABLED,
  8. SECURITY_OPTIONS_ENABLED
  9. } from '../../../base/flags';
  10. import { translate } from '../../../base/i18n';
  11. import { IconSecurityOff, IconSecurityOn } from '../../../base/icons';
  12. import { isLocalParticipantModerator } from '../../../base/participants';
  13. import { connect } from '../../../base/redux';
  14. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  15. import { toggleSecurityDialog } from '../../actions';
  16. type Props = AbstractButtonProps & {
  17. /**
  18. * Whether the shared document is being edited or not.
  19. */
  20. _locked: boolean,
  21. /**
  22. * The redux {@code dispatch} function.
  23. */
  24. dispatch: Dispatch<any>
  25. };
  26. /**
  27. * Implements an {@link AbstractButton} to open the security dialog.
  28. */
  29. class SecurityDialogButton extends AbstractButton<Props, *> {
  30. accessibilityLabel = 'toolbar.accessibilityLabel.security';
  31. icon = IconSecurityOff;
  32. label = 'toolbar.security';
  33. toggledIcon = IconSecurityOn;
  34. /**
  35. * Handles clicking / pressing the button, and opens / closes the appropriate dialog.
  36. *
  37. * @private
  38. * @returns {void}
  39. */
  40. _handleClick() {
  41. sendAnalytics(createToolbarEvent('toggle.security', { enable: !this.props._locked }));
  42. this.props.dispatch(toggleSecurityDialog());
  43. }
  44. /**
  45. * Indicates whether this button is in toggled state or not.
  46. *
  47. * @override
  48. * @returns {boolean}
  49. */
  50. _isToggled() {
  51. return this.props._locked;
  52. }
  53. }
  54. /**
  55. * Maps part of the redux state to the component's props.
  56. *
  57. * @param {Object} state - The redux store/state.
  58. * @returns {Props}
  59. */
  60. function mapStateToProps(state: Object) {
  61. const { conference } = state['features/base/conference'];
  62. const { hideLobbyButton } = state['features/base/config'];
  63. const { locked } = state['features/base/conference'];
  64. const { lobbyEnabled } = state['features/lobby'];
  65. const lobbySupported = conference && conference.isLobbySupported();
  66. const lobby = lobbySupported && isLocalParticipantModerator(state) && !hideLobbyButton;
  67. const enabledFlag = getFeatureFlag(state, SECURITY_OPTIONS_ENABLED, true);
  68. const enabledLobbyModeFlag = getFeatureFlag(state, LOBBY_MODE_ENABLED, true) && lobby;
  69. const enabledMeetingPassFlag = getFeatureFlag(state, MEETING_PASSWORD_ENABLED, true);
  70. return {
  71. _locked: locked || lobbyEnabled,
  72. visible: enabledFlag || (enabledLobbyModeFlag || enabledMeetingPassFlag)
  73. };
  74. }
  75. export default translate(connect(mapStateToProps)(SecurityDialogButton));