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.

RoomLockButton.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // @flow
  2. import { MEETING_PASSWORD_ENABLED, getFeatureFlag } from '../../base/flags';
  3. import { translate } from '../../base/i18n';
  4. import { IconRoomLock, IconRoomUnlock } from '../../base/icons';
  5. import { isLocalParticipantModerator } from '../../base/participants';
  6. import { connect } from '../../base/redux';
  7. import { AbstractButton } from '../../base/toolbox';
  8. import type { AbstractButtonProps } from '../../base/toolbox';
  9. import { beginRoomLockRequest, unlockRoom } from '../actions';
  10. type Props = AbstractButtonProps & {
  11. /**
  12. * Whether the current local participant is a moderator, therefore is
  13. * allowed to lock or unlock the conference.
  14. */
  15. _localParticipantModerator: boolean,
  16. /**
  17. * Whether the current conference is locked or not.
  18. */
  19. _locked: boolean,
  20. /**
  21. * The redux {@code dispatch} function.
  22. */
  23. dispatch: Function
  24. };
  25. /**
  26. * An implementation of a button for locking / unlocking a room.
  27. */
  28. class RoomLockButton extends AbstractButton<Props, *> {
  29. accessibilityLabel = 'toolbar.accessibilityLabel.lockRoom';
  30. icon = IconRoomLock;
  31. label = 'dialog.lockRoom';
  32. toggledIcon = IconRoomUnlock;
  33. toggledLabel = 'dialog.unlockRoom';
  34. /**
  35. * Handles clicking / pressing the button.
  36. *
  37. * @override
  38. * @protected
  39. * @returns {void}
  40. */
  41. _handleClick() {
  42. const { dispatch, _locked } = this.props;
  43. if (_locked) {
  44. dispatch(unlockRoom());
  45. } else {
  46. dispatch(beginRoomLockRequest());
  47. }
  48. }
  49. /**
  50. * Indicates whether this button is disabled or not.
  51. *
  52. * @override
  53. * @protected
  54. * @returns {boolean}
  55. */
  56. _isDisabled() {
  57. return !this.props._localParticipantModerator;
  58. }
  59. /**
  60. * Indicates whether this button is in toggled state or not.
  61. *
  62. * @override
  63. * @protected
  64. * @returns {boolean}
  65. */
  66. _isToggled() {
  67. return this.props._locked;
  68. }
  69. }
  70. /**
  71. * Maps (parts of) the redux state to the associated props for the
  72. * {@code RoomLockButton} component.
  73. *
  74. * @param {Object} state - The Redux state.
  75. * @param {Object} ownProps - The properties explicitly passed to the component instance.
  76. * @private
  77. * @returns {Props}
  78. */
  79. function _mapStateToProps(state, ownProps): Object {
  80. const { conference, locked } = state['features/base/conference'];
  81. const enabled = getFeatureFlag(state, MEETING_PASSWORD_ENABLED, true);
  82. const { visible = enabled } = ownProps;
  83. return {
  84. _localParticipantModerator: Boolean(conference && isLocalParticipantModerator(state)),
  85. _locked: Boolean(conference && locked),
  86. visible
  87. };
  88. }
  89. export default translate(connect(_mapStateToProps)(RoomLockButton));