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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. * Implements React's {@link Component#render()}.
  67. *
  68. * @inheritdoc
  69. * @returns {React$Node}
  70. */
  71. render() {
  72. const { _addPeopleEnabled, _dialOutEnabled } = this.props;
  73. return (
  74. _SHARE_ROOM_TOOLBAR_BUTTON
  75. || _addPeopleEnabled
  76. || _dialOutEnabled
  77. ? super.render()
  78. : null);
  79. }
  80. }
  81. /**
  82. * Maps redux actions to {@link InviteButton}'s React
  83. * {@code Component} props.
  84. *
  85. * @param {Function} dispatch - The redux action {@code dispatch} function.
  86. * @returns {{
  87. * _onAddPeople,
  88. * _onShareRoom
  89. * }}
  90. * @private
  91. */
  92. function _mapDispatchToProps(dispatch) {
  93. return {
  94. /**
  95. * Launches native invite dialog.
  96. *
  97. * @private
  98. * @returns {void}
  99. * @type {Function}
  100. */
  101. _onAddPeople() {
  102. dispatch(beginAddPeople());
  103. },
  104. /**
  105. * Begins the UI procedure to share the conference/room URL.
  106. *
  107. * @private
  108. * @returns {void}
  109. * @type {Function}
  110. */
  111. _onShareRoom() {
  112. dispatch(beginShareRoom());
  113. }
  114. };
  115. }
  116. /**
  117. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  118. * props.
  119. *
  120. * @param {Object} state - The redux store/state.
  121. * @private
  122. * @returns {{
  123. * }}
  124. */
  125. function _mapStateToProps(state) {
  126. return {
  127. /**
  128. * Whether or not the feature to directly invite people into the
  129. * conference is available.
  130. *
  131. * @type {boolean}
  132. */
  133. _addPeopleEnabled: isAddPeopleEnabled(state),
  134. /**
  135. * Whether or not the feature to dial out to number to join the
  136. * conference is available.
  137. *
  138. * @type {boolean}
  139. */
  140. _dialOutEnabled: isDialOutEnabled(state)
  141. };
  142. }
  143. export default connect(_mapStateToProps, _mapDispatchToProps)(InviteButton);