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

PrimaryToolbar.web.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import UIEvents from '../../../../service/UI/UIEvents';
  5. import { showDesktopSharingButton, toggleFullScreen } from '../actions';
  6. import Toolbar from './Toolbar';
  7. import { getToolbarClassNames } from '../functions';
  8. declare var APP: Object;
  9. declare var interfaceConfig: Object;
  10. /**
  11. * Implementation of PrimaryToolbar React Component.
  12. *
  13. * @class PrimaryToolbar
  14. * @extends Component
  15. */
  16. class PrimaryToolbar extends Component {
  17. state: Object;
  18. static propTypes = {
  19. /**
  20. * Handler for toggling fullscreen mode.
  21. */
  22. _onFullScreenToggled: React.PropTypes.func,
  23. /**
  24. * Handler for showing desktop sharing button.
  25. */
  26. _onShowDesktopSharingButton: React.PropTypes.func,
  27. /**
  28. * Contains toolbar buttons for primary toolbar.
  29. */
  30. _primaryToolbarButtons: React.PropTypes.instanceOf(Map),
  31. /**
  32. * Shows whether toolbox is visible.
  33. */
  34. _visible: React.PropTypes.bool
  35. };
  36. /**
  37. * Constructs instance of primary toolbar React component.
  38. *
  39. * @param {Object} props - React component's properties.
  40. */
  41. constructor(props) {
  42. super(props);
  43. const buttonHandlers = {
  44. /**
  45. * Mount handler for desktop button.
  46. *
  47. * @type {Object}
  48. */
  49. desktop: {
  50. onMount: () => this.props._onShowDesktopSharingButton()
  51. },
  52. /**
  53. * Mount/Unmount handler for toggling fullscreen button.
  54. *
  55. * @type {Object}
  56. */
  57. fullscreen: {
  58. onMount: () =>
  59. APP.UI.addListener(UIEvents.FULLSCREEN_TOGGLED,
  60. this.props._onFullScreenToggled),
  61. onUnmount: () =>
  62. APP.UI.removeListener(UIEvents.FULLSCREEN_TOGGLED,
  63. this.props._onFullScreenToggled)
  64. }
  65. };
  66. const splitterIndex = interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX;
  67. this.state = {
  68. /**
  69. * Object containing on mount/unmount handlers for toolbar buttons.
  70. *
  71. * @type {Object}
  72. */
  73. buttonHandlers,
  74. /**
  75. * If deployment supports toolbar splitter this value contains its
  76. * index.
  77. *
  78. * @type {number}
  79. */
  80. splitterIndex
  81. };
  82. }
  83. /**
  84. * Renders primary toolbar component.
  85. *
  86. * @returns {ReactElement}
  87. */
  88. render(): ReactElement<*> | null {
  89. const { _primaryToolbarButtons } = this.props;
  90. // The number of buttons to show in the toolbar isn't fixed, it depends
  91. // on availability of features and configuration parameters, so if we
  92. // don't have anything to render we exit here.
  93. if (_primaryToolbarButtons.size === 0) {
  94. return null;
  95. }
  96. const { buttonHandlers, splitterIndex } = this.state;
  97. const { primaryToolbarClassName } = getToolbarClassNames(this.props);
  98. return (
  99. <Toolbar
  100. buttonHandlers = { buttonHandlers }
  101. className = { primaryToolbarClassName }
  102. splitterIndex = { splitterIndex }
  103. toolbarButtons = { _primaryToolbarButtons } />
  104. );
  105. }
  106. }
  107. /**
  108. * Maps some of the Redux actions to the component props.
  109. *
  110. * @param {Function} dispatch - Redux action dispatcher.
  111. * @returns {{
  112. * _onShowDesktopSharingButton: Function
  113. * }}
  114. * @private
  115. */
  116. function _mapDispatchToProps(dispatch: Function): Object {
  117. return {
  118. /**
  119. * Dispatches an action signalling that full screen mode is toggled.
  120. *
  121. * @param {boolean} isFullScreen - Show whether fullscreen mode is on.
  122. * @returns {Object} Dispatched action.
  123. */
  124. _onFullScreenToggled(isFullScreen: boolean) {
  125. return dispatch(toggleFullScreen(isFullScreen));
  126. },
  127. /**
  128. * Dispatches an action signalling that desktop sharing button
  129. * should be shown.
  130. *
  131. * @returns {Object} Dispatched action.
  132. */
  133. _onShowDesktopSharingButton() {
  134. dispatch(showDesktopSharingButton());
  135. }
  136. };
  137. }
  138. /**
  139. * Maps part of Redux store to React component props.
  140. *
  141. * @param {Object} state - Snapshot of Redux store.
  142. * @returns {{
  143. * _primaryToolbarButtons: Map,
  144. * _visible: boolean
  145. * }}
  146. * @private
  147. */
  148. function _mapStateToProps(state: Object): Object {
  149. const {
  150. primaryToolbarButtons,
  151. visible
  152. } = state['features/toolbox'];
  153. return {
  154. /**
  155. * Default toolbar buttons for primary toolbar.
  156. *
  157. * @protected
  158. * @type {Map}
  159. */
  160. _primaryToolbarButtons: primaryToolbarButtons,
  161. /**
  162. * Shows whether toolbox is visible.
  163. *
  164. * @protected
  165. * @type {boolean}
  166. */
  167. _visible: visible
  168. };
  169. }
  170. export default connect(_mapStateToProps, _mapDispatchToProps)(PrimaryToolbar);