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

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