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.

PrimaryToolbar.web.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 { getToolbarClassNames } from '../functions';
  7. import Toolbar from './Toolbar';
  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. static propTypes = {
  18. /**
  19. * Handler for toggling fullscreen mode.
  20. */
  21. _onFullScreenToggled: React.PropTypes.func,
  22. /**
  23. * Handler for showing desktop sharing button.
  24. */
  25. _onShowDesktopSharingButton: React.PropTypes.func,
  26. /**
  27. * Contains toolbar buttons for primary toolbar.
  28. */
  29. _primaryToolbarButtons: React.PropTypes.instanceOf(Map),
  30. /**
  31. * Shows whether toolbox is visible.
  32. */
  33. _visible: React.PropTypes.bool
  34. };
  35. state: Object;
  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(
  60. UIEvents.FULLSCREEN_TOGGLED,
  61. this.props._onFullScreenToggled),
  62. onUnmount: () =>
  63. APP.UI.removeListener(
  64. UIEvents.FULLSCREEN_TOGGLED,
  65. this.props._onFullScreenToggled)
  66. }
  67. };
  68. const splitterIndex = interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX;
  69. this.state = {
  70. /**
  71. * Object containing on mount/unmount handlers for toolbar buttons.
  72. *
  73. * @type {Object}
  74. */
  75. buttonHandlers,
  76. /**
  77. * If deployment supports toolbar splitter this value contains its
  78. * index.
  79. *
  80. * @type {number}
  81. */
  82. splitterIndex
  83. };
  84. }
  85. /**
  86. * Renders primary toolbar component.
  87. *
  88. * @returns {ReactElement}
  89. */
  90. render(): ReactElement<*> | null {
  91. const { _primaryToolbarButtons } = this.props;
  92. // The number of buttons to show in the toolbar isn't fixed, it depends
  93. // on the availability of features and configuration parameters. So
  94. // there may be nothing to render.
  95. if (_primaryToolbarButtons.size === 0) {
  96. return null;
  97. }
  98. const { buttonHandlers, splitterIndex } = this.state;
  99. const { primaryToolbarClassName } = getToolbarClassNames(this.props);
  100. const tooltipPosition
  101. = interfaceConfig.filmStripOnly ? 'left' : 'bottom';
  102. return (
  103. <Toolbar
  104. buttonHandlers = { buttonHandlers }
  105. className = { primaryToolbarClassName }
  106. splitterIndex = { splitterIndex }
  107. toolbarButtons = { _primaryToolbarButtons }
  108. tooltipPosition = { tooltipPosition } />
  109. );
  110. }
  111. }
  112. /**
  113. * Maps some of the Redux actions to the component props.
  114. *
  115. * @param {Function} dispatch - Redux action dispatcher.
  116. * @returns {{
  117. * _onShowDesktopSharingButton: Function
  118. * }}
  119. * @private
  120. */
  121. function _mapDispatchToProps(dispatch: Function): Object {
  122. return {
  123. /**
  124. * Dispatches an action signalling that full screen mode is toggled.
  125. *
  126. * @param {boolean} isFullScreen - Show whether fullscreen mode is on.
  127. * @returns {Object} Dispatched action.
  128. */
  129. _onFullScreenToggled(isFullScreen: boolean) {
  130. return dispatch(toggleFullScreen(isFullScreen));
  131. },
  132. /**
  133. * Dispatches an action signalling that desktop sharing button
  134. * should be shown.
  135. *
  136. * @returns {Object} Dispatched action.
  137. */
  138. _onShowDesktopSharingButton() {
  139. dispatch(showDesktopSharingButton());
  140. }
  141. };
  142. }
  143. /**
  144. * Maps part of Redux store to React component props.
  145. *
  146. * @param {Object} state - Snapshot of Redux store.
  147. * @returns {{
  148. * _primaryToolbarButtons: Map,
  149. * _visible: boolean
  150. * }}
  151. * @private
  152. */
  153. function _mapStateToProps(state: Object): Object {
  154. const {
  155. primaryToolbarButtons,
  156. visible
  157. } = state['features/toolbox'];
  158. return {
  159. /**
  160. * Default toolbar buttons for primary toolbar.
  161. *
  162. * @private
  163. * @type {Map}
  164. */
  165. _primaryToolbarButtons: primaryToolbarButtons,
  166. /**
  167. * Shows whether toolbox is visible.
  168. *
  169. * @private
  170. * @type {boolean}
  171. */
  172. _visible: visible
  173. };
  174. }
  175. export default connect(_mapStateToProps, _mapDispatchToProps)(PrimaryToolbar);