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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 { ToolbarButton } 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. * The redux state representing the dial-in numbers feature.
  33. */
  34. _dialIn: PropTypes.object,
  35. /**
  36. * Whether or not the {@code InfoDialog} should display automatically
  37. * after {@link INFO_DIALOG_AUTO_SHOW_TIMEOUT}.
  38. */
  39. _disableAutoShow: PropTypes.bool,
  40. /**
  41. * The URL for a currently active live broadcast
  42. */
  43. _liveStreamViewURL: PropTypes.string,
  44. /**
  45. * The number of real participants in the call. If in a lonely call,
  46. * the {@code InfoDialog} will be automatically shown.
  47. */
  48. _participantCount: PropTypes.number,
  49. /**
  50. * Whether or not the toolbox, in which this component exists, are
  51. * visible.
  52. */
  53. _toolboxVisible: PropTypes.bool,
  54. /**
  55. * Invoked to toggle display of the info dialog
  56. */
  57. dispatch: PropTypes.func,
  58. /**
  59. * Invoked to obtain translated strings.
  60. */
  61. t: PropTypes.func,
  62. /**
  63. * From which side tooltips should display. Will be re-used for
  64. * displaying the inline dialog for video quality adjustment.
  65. */
  66. tooltipPosition: PropTypes.string
  67. };
  68. /**
  69. * Initializes new {@code InfoDialogButton} instance.
  70. *
  71. * @param {Object} props - The read-only properties with which the new
  72. * instance is to be initialized.
  73. */
  74. constructor(props) {
  75. super(props);
  76. /**
  77. * The timeout to automatically show the {@code InfoDialog} if it has
  78. * not been shown yet in a lonely call.
  79. *
  80. * @type {timeoutID}
  81. */
  82. this._autoShowTimeout = null;
  83. this.state = {
  84. /**
  85. * Whether or not {@code InfoDialog} should be visible.
  86. */
  87. showDialog: false
  88. };
  89. // Bind event handlers so they are only bound once for every instance.
  90. this._onDialogClose = this._onDialogClose.bind(this);
  91. this._onDialogToggle = this._onDialogToggle.bind(this);
  92. }
  93. /**
  94. * Set a timeout to automatically hide the {@code InfoDialog}.
  95. *
  96. * @inheritdoc
  97. */
  98. componentDidMount() {
  99. this._autoShowTimeout = setTimeout(() => {
  100. this._maybeAutoShowDialog();
  101. }, INFO_DIALOG_AUTO_SHOW_TIMEOUT);
  102. if (!this.props._dialIn.numbers) {
  103. this.props.dispatch(updateDialInNumbers());
  104. }
  105. }
  106. /**
  107. * Update the visibility of the {@code InfoDialog}.
  108. *
  109. * @inheritdoc
  110. */
  111. componentWillReceiveProps(nextProps) {
  112. // Ensure the dialog is closed when the toolbox becomes hidden.
  113. if (this.state.showDialog && !nextProps._toolboxVisible) {
  114. this._onDialogClose();
  115. }
  116. }
  117. /**
  118. * Clear the timeout to automatically show the {@code InfoDialog}.
  119. *
  120. * @inheritdoc
  121. */
  122. componentWillUnmount() {
  123. clearTimeout(this._autoShowTimeout);
  124. }
  125. /**
  126. * Implements React's {@link Component#render()}.
  127. *
  128. * @inheritdoc
  129. * @returns {ReactElement}
  130. */
  131. render() {
  132. const { _dialIn, _liveStreamViewURL, t } = this.props;
  133. const { showDialog } = this.state;
  134. const iconClass = `icon-info ${showDialog ? 'toggled' : ''}`;
  135. return (
  136. <div className = 'toolbox-button-wth-dialog'>
  137. <InlineDialog
  138. content = {
  139. <InfoDialog
  140. dialIn = { _dialIn }
  141. liveStreamViewURL = { _liveStreamViewURL }
  142. onClose = { this._onDialogClose } /> }
  143. isOpen = { showDialog }
  144. onClose = { this._onDialogClose }
  145. position = { 'top right' }>
  146. <ToolbarButton
  147. accessibilityLabel = 'Info'
  148. iconName = { iconClass }
  149. onClick = { this._onDialogToggle }
  150. tooltip = { t('info.tooltip') } />
  151. </InlineDialog>
  152. </div>
  153. );
  154. }
  155. /**
  156. * Callback invoked after a timeout to trigger display of the
  157. * {@code InfoDialog} if certain conditions are met.
  158. *
  159. * @private
  160. * @returns {void}
  161. */
  162. _maybeAutoShowDialog() {
  163. if (this.props._participantCount < 2 && !this.props._disableAutoShow) {
  164. this.setState({ showDialog: true });
  165. }
  166. }
  167. /**
  168. * Hides {@code InfoDialog}.
  169. *
  170. * @private
  171. * @returns {void}
  172. */
  173. _onDialogClose() {
  174. this.setState({ showDialog: false });
  175. }
  176. /**
  177. * Toggles the display of {@code InfoDialog}.
  178. *
  179. * @private
  180. * @returns {void}
  181. */
  182. _onDialogToggle() {
  183. sendAnalytics(createToolbarEvent('info'));
  184. this.setState({ showDialog: !this.state.showDialog });
  185. }
  186. }
  187. /**
  188. * Maps (parts of) the Redux state to the associated {@code InfoDialogButton}
  189. * component's props.
  190. *
  191. * @param {Object} state - The Redux state.
  192. * @private
  193. * @returns {{
  194. * _dialIn: Object,
  195. * _disableAutoShow: boolean,
  196. * _liveStreamViewURL: string,
  197. * _participantCount: number,
  198. * _toolboxVisible: boolean
  199. * }}
  200. */
  201. function _mapStateToProps(state) {
  202. return {
  203. _dialIn: state['features/invite'],
  204. _disableAutoShow: state['features/base/config'].iAmRecorder,
  205. _liveStreamViewURL: state['features/recording'].liveStreamViewURL,
  206. _participantCount:
  207. getParticipantCount(state['features/base/participants']),
  208. _toolboxVisible: state['features/toolbox'].visible
  209. };
  210. }
  211. export default translate(connect(_mapStateToProps)(InfoDialogButton));