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 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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() {
  89. const { buttonHandlers, splitterIndex } = this.state;
  90. const { _primaryToolbarButtons } = this.props;
  91. const { primaryToolbarClassName } = getToolbarClassNames(this.props);
  92. return (
  93. <Toolbar
  94. buttonHandlers = { buttonHandlers }
  95. className = { primaryToolbarClassName }
  96. splitterIndex = { splitterIndex }
  97. toolbarButtons = { _primaryToolbarButtons } />
  98. );
  99. }
  100. }
  101. /**
  102. * Maps some of the Redux actions to the component props.
  103. *
  104. * @param {Function} dispatch - Redux action dispatcher.
  105. * @returns {{
  106. * _onShowDesktopSharingButton: Function
  107. * }}
  108. * @private
  109. */
  110. function _mapDispatchToProps(dispatch: Function): Object {
  111. return {
  112. /**
  113. * Dispatches an action signalling that full screen mode is toggled.
  114. *
  115. * @param {boolean} isFullScreen - Show whether fullscreen mode is on.
  116. * @returns {Object} Dispatched action.
  117. */
  118. _onFullScreenToggled(isFullScreen: boolean) {
  119. return dispatch(toggleFullScreen(isFullScreen));
  120. },
  121. /**
  122. * Dispatches an action signalling that desktop sharing button
  123. * should be shown.
  124. *
  125. * @returns {Object} Dispatched action.
  126. */
  127. _onShowDesktopSharingButton() {
  128. dispatch(showDesktopSharingButton());
  129. }
  130. };
  131. }
  132. /**
  133. * Maps part of Redux store to React component props.
  134. *
  135. * @param {Object} state - Snapshot of Redux store.
  136. * @returns {{
  137. * _primaryToolbarButtons: Map,
  138. * _visible: boolean
  139. * }}
  140. * @private
  141. */
  142. function _mapStateToProps(state: Object): Object {
  143. const {
  144. primaryToolbarButtons,
  145. visible
  146. } = state['features/toolbox'];
  147. return {
  148. /**
  149. * Default toolbar buttons for primary toolbar.
  150. *
  151. * @protected
  152. * @type {Map}
  153. */
  154. _primaryToolbarButtons: primaryToolbarButtons,
  155. /**
  156. * Shows whether toolbox is visible.
  157. *
  158. * @protected
  159. * @type {boolean}
  160. */
  161. _visible: visible
  162. };
  163. }
  164. export default connect(_mapStateToProps, _mapDispatchToProps)(PrimaryToolbar);