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 7.0KB

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