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.

VideoStatusLabel.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { toggleAudioOnly } from '../../base/conference';
  4. import { translate } from '../../base/i18n';
  5. /**
  6. * React {@code Component} responsible for displaying a label that indicates
  7. * the displayed video state of the current conference. {@code AudioOnlyLabel}
  8. * will display when the conference is in audio only mode. {@code HDVideoLabel}
  9. * will display if not in audio only mode and a high-definition large video is
  10. * being displayed.
  11. */
  12. export class VideoStatusLabel extends Component {
  13. /**
  14. * {@code VideoStatusLabel}'s property types.
  15. *
  16. * @static
  17. */
  18. static propTypes = {
  19. /**
  20. * Whether or not the conference is in audio only mode.
  21. */
  22. _audioOnly: React.PropTypes.bool,
  23. /**
  24. * Whether or not a connection to a conference has been established.
  25. */
  26. _conferenceStarted: React.PropTypes.bool,
  27. /**
  28. * Whether or not a high-definition large video is displayed.
  29. */
  30. _largeVideoHD: React.PropTypes.bool,
  31. /**
  32. * Invoked to request toggling of audio only mode.
  33. */
  34. dispatch: React.PropTypes.func,
  35. /**
  36. * Invoked to obtain translated strings.
  37. */
  38. t: React.PropTypes.func
  39. }
  40. /**
  41. * Initializes a new {@code VideoStatusLabel} instance.
  42. *
  43. * @param {Object} props - The read-only React Component props with which
  44. * the new instance is to be initialized.
  45. */
  46. constructor(props) {
  47. super(props);
  48. // Bind event handler so it is only bound once for every instance.
  49. this._toggleAudioOnly = this._toggleAudioOnly.bind(this);
  50. }
  51. /**
  52. * Implements React's {@link Component#render()}.
  53. *
  54. * @inheritdoc
  55. * @returns {ReactElement}
  56. */
  57. render() {
  58. const { _audioOnly, _conferenceStarted, _largeVideoHD, t } = this.props;
  59. // FIXME The _conferenceStarted check is used to be defensive against
  60. // toggling audio only mode while there is no conference and hides the
  61. // need for error handling around audio only mode toggling.
  62. if (!_conferenceStarted) {
  63. return null;
  64. }
  65. let displayedLabel;
  66. if (_audioOnly) {
  67. displayedLabel = <i className = 'icon-visibility-off' />;
  68. } else {
  69. displayedLabel = _largeVideoHD
  70. ? t('videoStatus.hd') : t('videoStatus.sd');
  71. }
  72. return (
  73. <div
  74. className = 'video-state-indicator moveToCorner'
  75. id = 'videoResolutionLabel' >
  76. { displayedLabel }
  77. { this._renderVideonMenu() }
  78. </div>
  79. );
  80. }
  81. /**
  82. * Renders a dropdown menu for changing video modes.
  83. *
  84. * @private
  85. * @returns {ReactElement}
  86. */
  87. _renderVideonMenu() {
  88. const { _audioOnly, t } = this.props;
  89. const audioOnlyAttributes = _audioOnly ? { className: 'active' }
  90. : { onClick: this._toggleAudioOnly };
  91. const videoAttributes = _audioOnly ? { onClick: this._toggleAudioOnly }
  92. : { className: 'active' };
  93. return (
  94. <div className = 'video-state-indicator-menu'>
  95. <div className = 'video-state-indicator-menu-options'>
  96. <div { ...audioOnlyAttributes }>
  97. <i className = 'icon-visibility' />
  98. { t('audioOnly.audioOnly') }
  99. </div>
  100. <div { ...videoAttributes }>
  101. <i className = 'icon-camera' />
  102. { this.props._largeVideoHD
  103. ? t('videoStatus.hdVideo')
  104. : t('videoStatus.sdVideo') }
  105. </div>
  106. </div>
  107. </div>
  108. );
  109. }
  110. /**
  111. * Dispatches an action to toggle the state of audio only mode.
  112. *
  113. * @private
  114. * @returns {void}
  115. */
  116. _toggleAudioOnly() {
  117. this.props.dispatch(toggleAudioOnly());
  118. }
  119. }
  120. /**
  121. * Maps (parts of) the Redux state to the associated {@code VideoStatusLabel}'s
  122. * props.
  123. *
  124. * @param {Object} state - The Redux state.
  125. * @private
  126. * @returns {{
  127. * _audioOnly: boolean,
  128. * _conferenceStarted: boolean,
  129. * _largeVideoHD: (boolean|undefined)
  130. * }}
  131. */
  132. function _mapStateToProps(state) {
  133. const {
  134. audioOnly,
  135. conference,
  136. isLargeVideoHD
  137. } = state['features/base/conference'];
  138. return {
  139. _audioOnly: audioOnly,
  140. _conferenceStarted: Boolean(conference),
  141. _largeVideoHD: isLargeVideoHD
  142. };
  143. }
  144. export default translate(connect(_mapStateToProps)(VideoStatusLabel));