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

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