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.

InfoDialogButton.web.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import InlineDialog from '@atlaskit/inline-dialog';
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import { connect } from 'react-redux';
  5. import { createToolbarEvent, sendAnalytics } from '../../analytics';
  6. import { translate } from '../../base/i18n';
  7. import { getParticipantCount } from '../../base/participants';
  8. import { ToolbarButtonV2 } from '../../toolbox';
  9. import { updateDialInNumbers } from '../actions';
  10. import { InfoDialog } from './info-dialog';
  11. /**
  12. * The amount of time, in milliseconds, to wait until automatically showing
  13. * the {@code InfoDialog}. This is essentially a hack as automatic showing
  14. * should happen in a lonely call and some time is needed to populate
  15. * participants already in the call.
  16. */
  17. const INFO_DIALOG_AUTO_SHOW_TIMEOUT = 1500;
  18. /**
  19. * A React Component for displaying a button which opens a dialog with
  20. * information about the conference and with ways to invite people.
  21. *
  22. * @extends Component
  23. */
  24. class InfoDialogButton extends Component {
  25. /**
  26. * {@code InfoDialogButton} component's property types.
  27. *
  28. * @static
  29. */
  30. static propTypes = {
  31. /**
  32. * Phone numbers for dialing into the conference.
  33. */
  34. _dialInNumbers: PropTypes.oneOfType([
  35. PropTypes.object,
  36. PropTypes.array
  37. ]),
  38. /**
  39. * Whether or not the {@code InfoDialog} should display automatically
  40. * after {@link INFO_DIALOG_AUTO_SHOW_TIMEOUT}.
  41. */
  42. _disableAutoShow: PropTypes.bool,
  43. /**
  44. * The number of real participants in the call. If in a lonely call,
  45. * the {@code InfoDialog} will be automatically shown.
  46. */
  47. _participantCount: PropTypes.number,
  48. /**
  49. * Whether or not the toolbox, in which this component exists, are
  50. * visible.
  51. */
  52. _toolboxVisible: PropTypes.bool,
  53. /**
  54. * Invoked to toggle display of the info dialog
  55. */
  56. dispatch: PropTypes.func,
  57. /**
  58. * Invoked to obtain translated strings.
  59. */
  60. t: PropTypes.func,
  61. /**
  62. * From which side tooltips should display. Will be re-used for
  63. * displaying the inline dialog for video quality adjustment.
  64. */
  65. tooltipPosition: PropTypes.string
  66. };
  67. /**
  68. * Initializes new {@code ToolbarButtonWithDialog} instance.
  69. *
  70. * @param {Object} props - The read-only properties with which the new
  71. * instance is to be initialized.
  72. */
  73. constructor(props) {
  74. super(props);
  75. /**
  76. * The timeout to automatically show the {@code InfoDialog} if it has
  77. * not been shown yet in a lonely call.
  78. *
  79. * @type {timeoutID}
  80. */
  81. this._autoShowTimeout = null;
  82. this.state = {
  83. /**
  84. * Whether or not {@code InfoDialog} should be visible.
  85. */
  86. showDialog: false
  87. };
  88. // Bind event handlers so they are only bound once for every instance.
  89. this._onDialogClose = this._onDialogClose.bind(this);
  90. this._onDialogToggle = this._onDialogToggle.bind(this);
  91. }
  92. /**
  93. * Set a timeout to automatically hide the {@code InfoDialog}.
  94. *
  95. * @inheritdoc
  96. */
  97. componentDidMount() {
  98. this._autoShowTimeout = setTimeout(() => {
  99. this._maybeAutoShowDialog();
  100. }, INFO_DIALOG_AUTO_SHOW_TIMEOUT);
  101. if (!this.props._dialInNumbers) {
  102. this.props.dispatch(updateDialInNumbers());
  103. }
  104. }
  105. /**
  106. * Update the visibility of the {@code InfoDialog}.
  107. *
  108. * @inheritdoc
  109. */
  110. componentWillReceiveProps(nextProps) {
  111. // Ensure the dialog is closed when the toolbox becomes hidden.
  112. if (this.state.showDialog && !nextProps._toolboxVisible) {
  113. this._onDialogClose();
  114. }
  115. }
  116. /**
  117. * Clear the timeout to automatically show the {@code InfoDialog}.
  118. *
  119. * @inheritdoc
  120. */
  121. componentWillUnmount() {
  122. clearTimeout(this._autoShowTimeout);
  123. }
  124. /**
  125. * Implements React's {@link Component#render()}.
  126. *
  127. * @inheritdoc
  128. * @returns {ReactElement}
  129. */
  130. render() {
  131. const { t } = this.props;
  132. const { showDialog } = this.state;
  133. const iconClass = `icon-info ${showDialog ? 'toggled' : ''}`;
  134. return (
  135. <div className = 'toolbox-button-wth-dialog'>
  136. <InlineDialog
  137. content = {
  138. <InfoDialog onClose = { this._onDialogClose } /> }
  139. isOpen = { showDialog }
  140. onClose = { this._onDialogClose }
  141. position = { 'top right' }>
  142. <ToolbarButtonV2
  143. accessibilityLabel = 'Info'
  144. iconName = { iconClass }
  145. onClick = { this._onDialogToggle }
  146. tooltip = { t('info.tooltip') } />
  147. </InlineDialog>
  148. </div>
  149. );
  150. }
  151. /**
  152. * Callback invoked after a timeout to trigger display of the
  153. * {@code InfoDialog} if certain conditions are met.
  154. *
  155. * @private
  156. * @returns {void}
  157. */
  158. _maybeAutoShowDialog() {
  159. if (this.props._participantCount < 2 && !this.props._disableAutoShow) {
  160. this.setState({ showDialog: true });
  161. }
  162. }
  163. /**
  164. * Hides {@code InfoDialog}.
  165. *
  166. * @private
  167. * @returns {void}
  168. */
  169. _onDialogClose() {
  170. this.setState({ showDialog: false });
  171. }
  172. /**
  173. * Toggles the display of {@code InfoDialog}.
  174. *
  175. * @private
  176. * @returns {void}
  177. */
  178. _onDialogToggle() {
  179. sendAnalytics(createToolbarEvent('info'));
  180. this.setState({ showDialog: !this.state.showDialog });
  181. }
  182. }
  183. /**
  184. * Maps (parts of) the Redux state to the associated {@code InfoDialogButton}
  185. * component's props.
  186. *
  187. * @param {Object} state - The Redux state.
  188. * @private
  189. * @returns {{
  190. * _dialInNumbers: Array,
  191. * _disableAutoShow: bolean,
  192. * _participantCount: number,
  193. * _toolboxVisible: boolean
  194. * }}
  195. */
  196. function _mapStateToProps(state) {
  197. return {
  198. _dialInNumbers: state['features/invite'].numbers,
  199. _disableAutoShow: state['features/base/config'].iAmRecorder,
  200. _participantCount:
  201. getParticipantCount(state['features/base/participants']),
  202. _toolboxVisible: state['features/toolbox'].visible
  203. };
  204. }
  205. export default translate(connect(_mapStateToProps)(InfoDialogButton));