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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. * Cache the conference connection state to derive when transitioning from
  60. * not joined to join, in order to auto-show the InfoDialog.
  61. */
  62. hasConnectedToConference: boolean,
  63. /**
  64. * Whether or not {@code InfoDialog} should be visible.
  65. */
  66. showDialog: boolean
  67. };
  68. /**
  69. * A React Component for displaying a button which opens a dialog with
  70. * information about the conference and with ways to invite people.
  71. *
  72. * @extends Component
  73. */
  74. class InfoDialogButton extends Component<Props, State> {
  75. /**
  76. * Implements React's {@link Component#getDerivedStateFromProps()}.
  77. *
  78. * @inheritdoc
  79. */
  80. static getDerivedStateFromProps(props, state) {
  81. return {
  82. hasConnectedToConference: props._isConferenceJoined,
  83. showDialog: (props._toolboxVisible && state.showDialog)
  84. || (!state.hasConnectedToConference
  85. && props._isConferenceJoined
  86. && props._participantCount < 2
  87. && props._toolboxVisible
  88. && !props._disableAutoShow)
  89. };
  90. }
  91. /**
  92. * Initializes new {@code InfoDialogButton} instance.
  93. *
  94. * @inheritdoc
  95. */
  96. constructor(props) {
  97. super(props);
  98. this.state = {
  99. hasConnectedToConference: props._isConferenceJoined,
  100. showDialog: false
  101. };
  102. // Bind event handlers so they are only bound once for every instance.
  103. this._onDialogClose = this._onDialogClose.bind(this);
  104. this._onDialogToggle = this._onDialogToggle.bind(this);
  105. }
  106. /**
  107. * Update dial-in numbers {@code InfoDialog}.
  108. *
  109. * @inheritdoc
  110. */
  111. componentDidMount() {
  112. if (!this.props._dialIn.numbers) {
  113. this.props.dispatch(updateDialInNumbers());
  114. }
  115. }
  116. /**
  117. * Implements React's {@link Component#render()}.
  118. *
  119. * @inheritdoc
  120. * @returns {ReactElement}
  121. */
  122. render() {
  123. const { _dialIn, _liveStreamViewURL, t } = this.props;
  124. const { showDialog } = this.state;
  125. const iconClass = `icon-info ${showDialog ? 'toggled' : ''}`;
  126. return (
  127. <div className = 'toolbox-button-wth-dialog'>
  128. <InlineDialog
  129. content = {
  130. <InfoDialog
  131. dialIn = { _dialIn }
  132. liveStreamViewURL = { _liveStreamViewURL }
  133. onClose = { this._onDialogClose } /> }
  134. isOpen = { showDialog }
  135. onClose = { this._onDialogClose }
  136. position = { 'top right' }>
  137. <ToolbarButton
  138. accessibilityLabel = { t('info.accessibilityLabel') }
  139. iconName = { iconClass }
  140. onClick = { this._onDialogToggle }
  141. tooltip = { t('info.tooltip') } />
  142. </InlineDialog>
  143. </div>
  144. );
  145. }
  146. _onDialogClose: () => void;
  147. /**
  148. * Hides {@code InfoDialog}.
  149. *
  150. * @private
  151. * @returns {void}
  152. */
  153. _onDialogClose() {
  154. this.setState({ showDialog: false });
  155. }
  156. _onDialogToggle: () => void;
  157. /**
  158. * Toggles the display of {@code InfoDialog}.
  159. *
  160. * @private
  161. * @returns {void}
  162. */
  163. _onDialogToggle() {
  164. sendAnalytics(createToolbarEvent('info'));
  165. this.setState({ showDialog: !this.state.showDialog });
  166. }
  167. }
  168. /**
  169. * Maps (parts of) the Redux state to the associated {@code InfoDialogButton}
  170. * component's props.
  171. *
  172. * @param {Object} state - The Redux state.
  173. * @private
  174. * @returns {{
  175. * _dialIn: Object,
  176. * _disableAutoShow: boolean,
  177. * _isConferenceIsJoined: boolean,
  178. * _liveStreamViewURL: string,
  179. * _participantCount: number,
  180. * _toolboxVisible: boolean
  181. * }}
  182. */
  183. function _mapStateToProps(state) {
  184. const currentLiveStreamingSession
  185. = getActiveSession(state, JitsiRecordingConstants.mode.STREAM);
  186. return {
  187. _dialIn: state['features/invite'],
  188. _disableAutoShow: state['features/base/config'].iAmRecorder,
  189. _isConferenceJoined:
  190. Boolean(state['features/base/conference'].conference),
  191. _liveStreamViewURL:
  192. currentLiveStreamingSession
  193. && currentLiveStreamingSession.liveStreamViewURL,
  194. _participantCount: getParticipantCount(state),
  195. _toolboxVisible: state['features/toolbox'].visible
  196. };
  197. }
  198. export default translate(connect(_mapStateToProps)(InfoDialogButton));