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

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