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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 the filmstrip is displayed with remote videos.
  29. */
  30. _filmstripVisible: React.PropTypes.bool,
  31. /**
  32. * Whether or not a high-definition large video is displayed.
  33. */
  34. _largeVideoHD: React.PropTypes.bool,
  35. /**
  36. * Invoked to request toggling of audio only mode.
  37. */
  38. dispatch: React.PropTypes.func,
  39. /**
  40. * Invoked to obtain translated strings.
  41. */
  42. t: React.PropTypes.func
  43. }
  44. /**
  45. * Initializes a new {@code VideoStatusLabel} instance.
  46. *
  47. * @param {Object} props - The read-only React Component props with which
  48. * the new instance is to be initialized.
  49. */
  50. constructor(props) {
  51. super(props);
  52. // Bind event handler so it is only bound once for every instance.
  53. this._toggleAudioOnly = this._toggleAudioOnly.bind(this);
  54. }
  55. /**
  56. * Implements React's {@link Component#render()}.
  57. *
  58. * @inheritdoc
  59. * @returns {ReactElement}
  60. */
  61. render() {
  62. const {
  63. _audioOnly,
  64. _conferenceStarted,
  65. _filmstripVisible,
  66. _largeVideoHD,
  67. t
  68. } = this.props;
  69. // FIXME The _conferenceStarted check is used to be defensive against
  70. // toggling audio only mode while there is no conference and hides the
  71. // need for error handling around audio only mode toggling.
  72. if (!_conferenceStarted) {
  73. return null;
  74. }
  75. let displayedLabel;
  76. if (_audioOnly) {
  77. displayedLabel = <i className = 'icon-visibility-off' />;
  78. } else {
  79. displayedLabel = _largeVideoHD
  80. ? t('videoStatus.hd') : t('videoStatus.sd');
  81. }
  82. const filmstripClassName
  83. = _filmstripVisible ? 'with-filmstrip' : 'without-filmstrip';
  84. const classNames
  85. = `video-state-indicator moveToCorner ${filmstripClassName}`;
  86. return (
  87. <div
  88. className = { classNames }
  89. id = 'videoResolutionLabel' >
  90. { displayedLabel }
  91. { this._renderVideonMenu() }
  92. </div>
  93. );
  94. }
  95. /**
  96. * Renders a dropdown menu for changing video modes.
  97. *
  98. * @private
  99. * @returns {ReactElement}
  100. */
  101. _renderVideonMenu() {
  102. const { _audioOnly, t } = this.props;
  103. const audioOnlyAttributes = _audioOnly ? { className: 'active' }
  104. : { onClick: this._toggleAudioOnly };
  105. const videoAttributes = _audioOnly ? { onClick: this._toggleAudioOnly }
  106. : { className: 'active' };
  107. return (
  108. <div className = 'video-state-indicator-menu'>
  109. <div className = 'video-state-indicator-menu-options'>
  110. <div { ...audioOnlyAttributes }>
  111. <i className = 'icon-visibility' />
  112. { t('audioOnly.audioOnly') }
  113. </div>
  114. <div { ...videoAttributes }>
  115. <i className = 'icon-camera' />
  116. { this.props._largeVideoHD
  117. ? t('videoStatus.hdVideo')
  118. : t('videoStatus.sdVideo') }
  119. </div>
  120. </div>
  121. </div>
  122. );
  123. }
  124. /**
  125. * Dispatches an action to toggle the state of audio only mode.
  126. *
  127. * @private
  128. * @returns {void}
  129. */
  130. _toggleAudioOnly() {
  131. this.props.dispatch(toggleAudioOnly());
  132. }
  133. }
  134. /**
  135. * Maps (parts of) the Redux state to the associated {@code VideoStatusLabel}'s
  136. * props.
  137. *
  138. * @param {Object} state - The Redux state.
  139. * @private
  140. * @returns {{
  141. * _audioOnly: boolean,
  142. * _conferenceStarted: boolean,
  143. * _largeVideoHD: (boolean|undefined)
  144. * }}
  145. */
  146. function _mapStateToProps(state) {
  147. const {
  148. audioOnly,
  149. conference,
  150. isLargeVideoHD
  151. } = state['features/base/conference'];
  152. const {
  153. remoteVideosCount,
  154. remoteVideosVisible,
  155. visible
  156. } = state['features/filmstrip'];
  157. return {
  158. _audioOnly: audioOnly,
  159. _conferenceStarted: Boolean(conference),
  160. _filmstripVisible:
  161. Boolean(remoteVideosCount && remoteVideosVisible && visible),
  162. _largeVideoHD: isLargeVideoHD
  163. };
  164. }
  165. export default translate(connect(_mapStateToProps)(VideoStatusLabel));