Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

VideoQualityButton.web.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import AKInlineDialog from '@atlaskit/inline-dialog';
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { VideoQualityDialog } from './';
  5. import { ToolbarButton } from '../../toolbox';
  6. const DEFAULT_BUTTON_CONFIGURATION = {
  7. buttonName: 'videoquality',
  8. classNames: [ 'button', 'icon-visibility' ],
  9. enabled: true,
  10. id: 'toolbar_button_videoquality',
  11. tooltipKey: 'videoStatus.qualityButtonTip'
  12. };
  13. const TOOLTIP_TO_DIALOG_POSITION = {
  14. bottom: 'bottom center',
  15. left: 'left middle',
  16. right: 'right middle',
  17. top: 'top center'
  18. };
  19. /**
  20. * React {@code Component} for displaying an inline dialog for changing receive
  21. * video settings.
  22. *
  23. * @extends Component
  24. */
  25. class VideoQualityButton extends Component {
  26. /**
  27. * {@code VideoQualityButton}'s property types.
  28. *
  29. * @static
  30. */
  31. static propTypes = {
  32. /**
  33. * Whether or not the button is visible, based on the visibility of the
  34. * toolbar. Used to automatically hide the inline dialog if not visible.
  35. */
  36. _visible: React.PropTypes.bool,
  37. /**
  38. * From which side tooltips should display. Will be re-used for
  39. * displaying the inline dialog for video quality adjustment.
  40. */
  41. tooltipPosition: React.PropTypes.string
  42. };
  43. /**
  44. * Initializes a new {@code VideoQualityButton} instance.
  45. *
  46. * @param {Object} props - The read-only properties with which the new
  47. * instance is to be initialized.
  48. */
  49. constructor(props) {
  50. super(props);
  51. this.state = {
  52. /**
  53. * Whether or not the inline dialog for adjusting received video
  54. * quality is displayed.
  55. */
  56. showVideoQualityDialog: false
  57. };
  58. // Bind event handlers so they are only bound once for every instance.
  59. this._onDialogClose = this._onDialogClose.bind(this);
  60. this._onDialogToggle = this._onDialogToggle.bind(this);
  61. }
  62. /**
  63. * Automatically close the inline dialog if the button will not be visible.
  64. *
  65. * @inheritdoc
  66. * @returns {void}
  67. */
  68. componentWillReceiveProps(nextProps) {
  69. if (!nextProps._visible) {
  70. this._onDialogClose();
  71. }
  72. }
  73. /**
  74. * Implements React's {@link Component#render()}.
  75. *
  76. * @inheritdoc
  77. * @returns {ReactElement}
  78. */
  79. render() {
  80. const { _visible, tooltipPosition } = this.props;
  81. const buttonConfiguration = {
  82. ...DEFAULT_BUTTON_CONFIGURATION,
  83. classNames: [
  84. ...DEFAULT_BUTTON_CONFIGURATION.classNames,
  85. this.state.showVideoQualityDialog ? 'toggled button-active' : ''
  86. ]
  87. };
  88. return (
  89. <AKInlineDialog
  90. content = { <VideoQualityDialog /> }
  91. isOpen = { _visible && this.state.showVideoQualityDialog }
  92. onClose = { this._onDialogClose }
  93. position = { TOOLTIP_TO_DIALOG_POSITION[tooltipPosition] }>
  94. <ToolbarButton
  95. button = { buttonConfiguration }
  96. onClick = { this._onDialogToggle }
  97. tooltipPosition = { tooltipPosition } />
  98. </AKInlineDialog>
  99. );
  100. }
  101. /**
  102. * Hides the attached inline dialog.
  103. *
  104. * @private
  105. * @returns {void}
  106. */
  107. _onDialogClose() {
  108. this.setState({ showVideoQualityDialog: false });
  109. }
  110. /**
  111. * Toggles the display of the dialog.
  112. *
  113. * @private
  114. * @returns {void}
  115. */
  116. _onDialogToggle() {
  117. this.setState({
  118. showVideoQualityDialog: !this.state.showVideoQualityDialog
  119. });
  120. }
  121. }
  122. /**
  123. * Maps (parts of) the Redux state to the associated {@code VideoQualityButton}
  124. * component's props.
  125. *
  126. * @param {Object} state - The Redux state.
  127. * @private
  128. * @returns {{
  129. * _visible: boolean
  130. * }}
  131. */
  132. function _mapStateToProps(state) {
  133. return {
  134. _visible: state['features/toolbox'].visible
  135. };
  136. }
  137. export default connect(_mapStateToProps)(VideoQualityButton);