您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

InfoDialogButton.js 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. // @flow
  2. import InlineDialog from '@atlaskit/inline-dialog';
  3. import React, { Component } from 'react';
  4. import type { Dispatch } from 'redux';
  5. import { createToolbarEvent, sendAnalytics } from '../../../../analytics';
  6. import { openDialog } from '../../../../base/dialog';
  7. import { translate } from '../../../../base/i18n';
  8. import { IconInfo } from '../../../../base/icons';
  9. import { JitsiRecordingConstants } from '../../../../base/lib-jitsi-meet';
  10. import { getParticipantCount } from '../../../../base/participants';
  11. import { OverflowMenuItem } from '../../../../base/toolbox';
  12. import { connect } from '../../../../base/redux';
  13. import { getActiveSession } from '../../../../recording';
  14. import { ToolbarButton } from '../../../../toolbox';
  15. import { updateDialInNumbers } from '../../../actions';
  16. import InfoDialog from './InfoDialog';
  17. /**
  18. * The type of the React {@code Component} props of {@link InfoDialogButton}.
  19. */
  20. type Props = {
  21. /**
  22. * The redux state representing the dial-in numbers feature.
  23. */
  24. _dialIn: Object,
  25. /**
  26. * Whether or not the {@code InfoDialog} should display automatically when
  27. * in a lonely call.
  28. */
  29. _disableAutoShow: boolean,
  30. /**
  31. * Whether or not the local participant has joined a
  32. * {@code JitsiConference}. Used to trigger auto showing of the
  33. * {@code InfoDialog}.
  34. */
  35. _isConferenceJoined: Boolean,
  36. /**
  37. * The URL for a currently active live broadcast
  38. */
  39. _liveStreamViewURL: ?string,
  40. /**
  41. * The number of real participants in the call. If in a lonely call, the
  42. * {@code InfoDialog} will be automatically shown.
  43. */
  44. _participantCount: number,
  45. /**
  46. * Whether or not the toolbox, in which this component exists, is visible.
  47. */
  48. _toolboxVisible: boolean,
  49. /**
  50. * Invoked to toggle display of the info dialog.
  51. */
  52. dispatch: Dispatch<any>,
  53. /**
  54. * Whether to show the label or not.
  55. */
  56. showLabel: boolean,
  57. /**
  58. * Invoked to obtain translated strings.
  59. */
  60. t: Function
  61. };
  62. /**
  63. * The type of the React {@code Component} state of {@link InfoDialogButton}.
  64. */
  65. type State = {
  66. /**
  67. * Cache the conference connection state to derive when transitioning from
  68. * not joined to join, in order to auto-show the InfoDialog.
  69. */
  70. hasConnectedToConference: boolean,
  71. /**
  72. * Whether or not {@code InfoDialog} should be visible.
  73. */
  74. showDialog: boolean
  75. };
  76. /**
  77. * A React Component for displaying a button which opens a dialog with
  78. * information about the conference and with ways to invite people.
  79. *
  80. * @extends Component
  81. */
  82. class InfoDialogButton extends Component<Props, State> {
  83. /**
  84. * Implements React's {@link Component#getDerivedStateFromProps()}.
  85. *
  86. * @inheritdoc
  87. */
  88. static getDerivedStateFromProps(props, state) {
  89. return {
  90. hasConnectedToConference: props._isConferenceJoined,
  91. showDialog: (props._toolboxVisible && state.showDialog)
  92. || (!state.hasConnectedToConference
  93. && props._isConferenceJoined
  94. && props._participantCount < 2
  95. && props._toolboxVisible
  96. && !props._disableAutoShow)
  97. };
  98. }
  99. /**
  100. * Initializes new {@code InfoDialogButton} instance.
  101. *
  102. * @inheritdoc
  103. */
  104. constructor(props) {
  105. super(props);
  106. this.state = {
  107. hasConnectedToConference: props._isConferenceJoined,
  108. showDialog: false
  109. };
  110. // Bind event handlers so they are only bound once for every instance.
  111. this._onDialogClose = this._onDialogClose.bind(this);
  112. this._onDialogToggle = this._onDialogToggle.bind(this);
  113. this._onClickOverflowMenuButton
  114. = this._onClickOverflowMenuButton.bind(this);
  115. }
  116. /**
  117. * Update dial-in numbers {@code InfoDialog}.
  118. *
  119. * @inheritdoc
  120. */
  121. componentDidMount() {
  122. if (!this.props._dialIn.numbers) {
  123. this.props.dispatch(updateDialInNumbers());
  124. }
  125. }
  126. /**
  127. * Implements React's {@link Component#render()}.
  128. *
  129. * @inheritdoc
  130. * @returns {ReactElement}
  131. */
  132. render() {
  133. const { _dialIn, _liveStreamViewURL, showLabel, t } = this.props;
  134. const { showDialog } = this.state;
  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. icon = { IconInfo }
  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));