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

InviteButton.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // @flow
  2. import { connect } from 'react-redux';
  3. import {
  4. beginAddPeople,
  5. isAddPeopleEnabled,
  6. isDialOutEnabled
  7. } from '../../../../invite';
  8. import { beginShareRoom } from '../../../../share-room';
  9. import AbstractButton from '../AbstractButton';
  10. import type { Props as AbstractButtonProps } from '../AbstractButton';
  11. type Props = AbstractButtonProps & {
  12. /**
  13. * Whether or not the feature to directly invite people into the
  14. * conference is available.
  15. */
  16. _addPeopleEnabled: boolean,
  17. /**
  18. * Whether or not the feature to dial out to number to join the
  19. * conference is available.
  20. */
  21. _dialOutEnabled: boolean,
  22. /**
  23. * Launches native invite dialog.
  24. *
  25. * @protected
  26. */
  27. _onAddPeople: Function,
  28. /**
  29. * Begins the UI procedure to share the conference/room URL.
  30. */
  31. _onShareRoom: Function
  32. };
  33. /**
  34. * The indicator which determines (at bundle time) whether there should be a
  35. * button in {@code Toolbox} to expose the functionality of the feature
  36. * share-room in the user interface of the app.
  37. *
  38. * @private
  39. * @type {boolean}
  40. */
  41. const _SHARE_ROOM_TOOLBAR_BUTTON = true;
  42. /**
  43. * Implements a {@link ToolbarButton} to enter Picture-in-Picture.
  44. */
  45. class InviteButton extends AbstractButton<Props, *> {
  46. accessibilityLabel = 'Share room';
  47. iconName = 'icon-link';
  48. label = 'toolbar.shareRoom';
  49. /**
  50. * Handles clicking / pressing the button, and opens the appropriate dialog.
  51. *
  52. * @private
  53. * @returns {void}
  54. */
  55. _handleClick() {
  56. const {
  57. _addPeopleEnabled,
  58. _dialOutEnabled,
  59. _onAddPeople,
  60. _onShareRoom
  61. } = this.props;
  62. if (_addPeopleEnabled || _dialOutEnabled) {
  63. _onAddPeople();
  64. } else if (_SHARE_ROOM_TOOLBAR_BUTTON) {
  65. _onShareRoom();
  66. }
  67. }
  68. /**
  69. * Indicates whether this button is disabled or not.
  70. *
  71. * @override
  72. * @private
  73. * @returns {boolean}
  74. */
  75. _isDisabled() {
  76. return false;
  77. }
  78. /**
  79. * Implements React's {@link Component#render()}.
  80. *
  81. * @inheritdoc
  82. * @returns {React$Node}
  83. */
  84. render() {
  85. const { _addPeopleEnabled, _dialOutEnabled } = this.props;
  86. return (
  87. _SHARE_ROOM_TOOLBAR_BUTTON
  88. || _addPeopleEnabled
  89. || _dialOutEnabled
  90. ? super.render()
  91. : null);
  92. }
  93. }
  94. /**
  95. * Maps redux actions to {@link InviteButton}'s React
  96. * {@code Component} props.
  97. *
  98. * @param {Function} dispatch - The redux action {@code dispatch} function.
  99. * @returns {{
  100. * _onAddPeople,
  101. * _onShareRoom
  102. * }}
  103. * @private
  104. */
  105. function _mapDispatchToProps(dispatch) {
  106. return {
  107. /**
  108. * Launches native invite dialog.
  109. *
  110. * @private
  111. * @returns {void}
  112. * @type {Function}
  113. */
  114. _onAddPeople() {
  115. dispatch(beginAddPeople());
  116. },
  117. /**
  118. * Begins the UI procedure to share the conference/room URL.
  119. *
  120. * @private
  121. * @returns {void}
  122. * @type {Function}
  123. */
  124. _onShareRoom() {
  125. dispatch(beginShareRoom());
  126. }
  127. };
  128. }
  129. /**
  130. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  131. * props.
  132. *
  133. * @param {Object} state - The redux store/state.
  134. * @private
  135. * @returns {{
  136. * }}
  137. */
  138. function _mapStateToProps(state) {
  139. return {
  140. /**
  141. * Whether or not the feature to directly invite people into the
  142. * conference is available.
  143. *
  144. * @type {boolean}
  145. */
  146. _addPeopleEnabled: isAddPeopleEnabled(state),
  147. /**
  148. * Whether or not the feature to dial out to number to join the
  149. * conference is available.
  150. *
  151. * @type {boolean}
  152. */
  153. _dialOutEnabled: isDialOutEnabled(state)
  154. };
  155. }
  156. export default connect(_mapStateToProps, _mapDispatchToProps)(InviteButton);