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.

InviteButton.native.js 3.9KB

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