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

RoomLockButton.js 2.3KB

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