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

VideoStatusLabel.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 These truthy checks should not be necessary. The
  60. // _conferenceStarted check is used to be defensive against toggling
  61. // audio only mode while there is no conference and hides the need for
  62. // error handling around audio only mode toggling. The _largeVideoHD
  63. // check is used to prevent the label from displaying while the video
  64. // resolution status is unknown but ties this component to the
  65. // LargeVideoManager.
  66. if (!_conferenceStarted || _largeVideoHD === undefined) {
  67. return null;
  68. }
  69. let displayedLabel;
  70. if (_audioOnly) {
  71. displayedLabel = <i className = 'icon-visibility-off' />;
  72. } else {
  73. displayedLabel = _largeVideoHD
  74. ? t('videoStatus.hd') : t('videoStatus.sd');
  75. }
  76. return (
  77. <div
  78. className = 'video-state-indicator moveToCorner'
  79. id = 'videoResolutionLabel' >
  80. { displayedLabel }
  81. { this._renderVideonMenu() }
  82. </div>
  83. );
  84. }
  85. /**
  86. * Renders a dropdown menu for changing video modes.
  87. *
  88. * @private
  89. * @returns {ReactElement}
  90. */
  91. _renderVideonMenu() {
  92. const { _audioOnly, t } = this.props;
  93. const audioOnlyAttributes = _audioOnly ? { className: 'active' }
  94. : { onClick: this._toggleAudioOnly };
  95. const videoAttributes = _audioOnly ? { onClick: this._toggleAudioOnly }
  96. : { className: 'active' };
  97. return (
  98. <div className = 'video-state-indicator-menu'>
  99. <div className = 'video-state-indicator-menu-options'>
  100. <div { ...audioOnlyAttributes }>
  101. <i className = 'icon-visibility' />
  102. { t('audioOnly.audioOnly') }
  103. </div>
  104. <div { ...videoAttributes }>
  105. <i className = 'icon-camera' />
  106. { this.props._largeVideoHD
  107. ? t('videoStatus.hdVideo')
  108. : t('videoStatus.sdVideo') }
  109. </div>
  110. </div>
  111. </div>
  112. );
  113. }
  114. /**
  115. * Dispatches an action to toggle the state of audio only mode.
  116. *
  117. * @private
  118. * @returns {void}
  119. */
  120. _toggleAudioOnly() {
  121. this.props.dispatch(toggleAudioOnly());
  122. }
  123. }
  124. /**
  125. * Maps (parts of) the Redux state to the associated {@code VideoStatusLabel}'s
  126. * props.
  127. *
  128. * @param {Object} state - The Redux state.
  129. * @private
  130. * @returns {{
  131. * _audioOnly: boolean,
  132. * _conferenceStarted: boolean,
  133. * _largeVideoHD: (boolean|undefined)
  134. * }}
  135. */
  136. function _mapStateToProps(state) {
  137. const {
  138. audioOnly,
  139. conference,
  140. isLargeVideoHD
  141. } = state['features/base/conference'];
  142. return {
  143. _audioOnly: audioOnly,
  144. _conferenceStarted: Boolean(conference),
  145. _largeVideoHD: isLargeVideoHD
  146. };
  147. }
  148. export default translate(connect(_mapStateToProps)(VideoStatusLabel));