Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

VideoQualityDialog.web.js 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. import InlineMessage from '@atlaskit/inline-message';
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import { connect } from 'react-redux';
  5. import {
  6. setAudioOnly,
  7. setReceiveVideoQuality,
  8. VIDEO_QUALITY_LEVELS
  9. } from '../../base/conference';
  10. import { translate } from '../../base/i18n';
  11. const {
  12. HIGH,
  13. STANDARD,
  14. LOW
  15. } = VIDEO_QUALITY_LEVELS;
  16. /**
  17. * Implements a React {@link Component} which displays a dialog with a slider
  18. * for selecting a new receive video quality.
  19. *
  20. * @extends Component
  21. */
  22. class VideoQualityDialog extends Component {
  23. /**
  24. * {@code VideoQualityDialog}'s property types.
  25. *
  26. * @static
  27. */
  28. static propTypes = {
  29. /**
  30. * Whether or not the conference is in audio only mode.
  31. */
  32. _audioOnly: PropTypes.bool,
  33. /**
  34. * Whether or not the conference is in peer to peer mode.
  35. */
  36. _p2p: PropTypes.bool,
  37. /**
  38. * The currently configured maximum quality resolution to be received
  39. * from remote participants.
  40. */
  41. _receiveVideoQuality: PropTypes.number,
  42. /**
  43. * Invoked to request toggling of audio only mode.
  44. */
  45. dispatch: PropTypes.func,
  46. /**
  47. * Invoked to obtain translated strings.
  48. */
  49. t: PropTypes.func
  50. };
  51. /**
  52. * Initializes a new {@code VideoQualityDialog} instance.
  53. *
  54. * @param {Object} props - The read-only React Component props with which
  55. * the new instance is to be initialized.
  56. */
  57. constructor(props) {
  58. super(props);
  59. // Bind event handlers so they are only bound once for every instance.
  60. this._enableAudioOnly = this._enableAudioOnly.bind(this);
  61. this._enableHighDefinition = this._enableHighDefinition.bind(this);
  62. this._enableLowDefinition = this._enableLowDefinition.bind(this);
  63. this._enableStandardDefinition
  64. = this._enableStandardDefinition.bind(this);
  65. this._onSliderChange = this._onSliderChange.bind(this);
  66. /**
  67. * An array of configuration options for displaying a choice in the
  68. * input. The onSelect callback will be invoked when the option is
  69. * selected and videoQuality helps determine which choice matches with
  70. * the currently active quality level.
  71. *
  72. * @private
  73. * @type {Object[]}
  74. */
  75. this._sliderOptions = [
  76. {
  77. audioOnly: true,
  78. onSelect: this._enableAudioOnly,
  79. textKey: 'audioOnly.audioOnly'
  80. },
  81. {
  82. onSelect: this._enableLowDefinition,
  83. textKey: 'videoStatus.lowDefinition',
  84. videoQuality: LOW
  85. },
  86. {
  87. onSelect: this._enableStandardDefinition,
  88. textKey: 'videoStatus.standardDefinition',
  89. videoQuality: STANDARD
  90. },
  91. {
  92. onSelect: this._enableHighDefinition,
  93. textKey: 'videoStatus.highDefinition',
  94. videoQuality: HIGH
  95. }
  96. ];
  97. }
  98. /**
  99. * Implements React's {@link Component#render()}.
  100. *
  101. * @inheritdoc
  102. * @returns {ReactElement}
  103. */
  104. render() {
  105. const { _audioOnly, _p2p, t } = this.props;
  106. const activeSliderOption = this._mapCurrentQualityToSliderValue();
  107. const showP2PWarning = _p2p && !_audioOnly;
  108. return (
  109. <div className = 'video-quality-dialog'>
  110. <h3 className = 'video-quality-dialog-title'>
  111. { t('videoStatus.callQuality') }
  112. </h3>
  113. <div className = { showP2PWarning ? '' : 'hide-warning' }>
  114. { this._renderP2PMessage() }
  115. </div>
  116. <div className = 'video-quality-dialog-contents'>
  117. <div className = 'video-quality-dialog-slider-container'>
  118. { /* FIXME: onChange and onMouseUp are both used for
  119. * compatibility with IE11. This workaround can be
  120. * removed after upgrading to React 16.
  121. */ }
  122. <input
  123. className = 'video-quality-dialog-slider'
  124. max = { this._sliderOptions.length - 1 }
  125. min = '0'
  126. onChange = { this._onSliderChange }
  127. onMouseUp = { this._onSliderChange }
  128. step = '1'
  129. type = 'range'
  130. value
  131. = { activeSliderOption } />
  132. </div>
  133. <div className = 'video-quality-dialog-labels'>
  134. { this._createLabels(activeSliderOption) }
  135. </div>
  136. </div>
  137. </div>
  138. );
  139. }
  140. /**
  141. * Creates React Elements for notifying that peer to peer is enabled.
  142. *
  143. * @private
  144. * @returns {ReactElement}
  145. */
  146. _renderP2PMessage() {
  147. const { t } = this.props;
  148. return (
  149. <InlineMessage
  150. secondaryText = { t('videoStatus.recHighDefinitionOnly') }
  151. title = { t('videoStatus.p2pEnabled') }>
  152. { t('videoStatus.p2pVideoQualityDescription') }
  153. </InlineMessage>
  154. );
  155. }
  156. /**
  157. * Creates React Elements to display mock tick marks with associated labels.
  158. *
  159. * @param {number} activeLabelIndex - Which of the sliderOptions should
  160. * display as currently active.
  161. * @private
  162. * @returns {ReactElement[]}
  163. */
  164. _createLabels(activeLabelIndex) {
  165. const labelsCount = this._sliderOptions.length;
  166. const maxWidthOfLabel = `${100 / labelsCount}%`;
  167. return this._sliderOptions.map((sliderOption, index) => {
  168. const style = {
  169. maxWidth: maxWidthOfLabel,
  170. left: `${(index * 100) / (labelsCount - 1)}%`
  171. };
  172. const isActiveClass = activeLabelIndex === index ? 'active' : '';
  173. const className
  174. = `video-quality-dialog-label-container ${isActiveClass}`;
  175. return (
  176. <div
  177. className = { className }
  178. key = { index }
  179. style = { style }>
  180. <div className = 'video-quality-dialog-label'>
  181. { this.props.t(sliderOption.textKey) }
  182. </div>
  183. </div>
  184. );
  185. });
  186. }
  187. /**
  188. * Dispatches an action to enable audio only mode.
  189. *
  190. * @private
  191. * @returns {void}
  192. */
  193. _enableAudioOnly() {
  194. this.props.dispatch(setAudioOnly(true));
  195. }
  196. /**
  197. * Dispatches an action to receive high quality video from remote
  198. * participants.
  199. *
  200. * @private
  201. * @returns {void}
  202. */
  203. _enableHighDefinition() {
  204. this.props.dispatch(setReceiveVideoQuality(HIGH));
  205. }
  206. /**
  207. * Dispatches an action to receive low quality video from remote
  208. * participants.
  209. *
  210. * @private
  211. * @returns {void}
  212. */
  213. _enableLowDefinition() {
  214. this.props.dispatch(setReceiveVideoQuality(LOW));
  215. }
  216. /**
  217. * Dispatches an action to receive standard quality video from remote
  218. * participants.
  219. *
  220. * @private
  221. * @returns {void}
  222. */
  223. _enableStandardDefinition() {
  224. this.props.dispatch(setReceiveVideoQuality(STANDARD));
  225. }
  226. /**
  227. * Matches the current video quality state with corresponding index of the
  228. * component's slider options.
  229. *
  230. * @private
  231. * @returns {void}
  232. */
  233. _mapCurrentQualityToSliderValue() {
  234. const { _audioOnly, _receiveVideoQuality } = this.props;
  235. const { _sliderOptions } = this;
  236. if (_audioOnly) {
  237. const audioOnlyOption = _sliderOptions.find(
  238. ({ audioOnly }) => audioOnly);
  239. return _sliderOptions.indexOf(audioOnlyOption);
  240. }
  241. const matchingOption = _sliderOptions.find(
  242. ({ videoQuality }) => videoQuality === _receiveVideoQuality);
  243. return _sliderOptions.indexOf(matchingOption);
  244. }
  245. /**
  246. * Invokes a callback when the selected video quality changes.
  247. *
  248. * @param {Object} event - The slider's change event.
  249. * @private
  250. * @returns {void}
  251. */
  252. _onSliderChange(event) {
  253. const { _audioOnly, _receiveVideoQuality } = this.props;
  254. const {
  255. audioOnly,
  256. onSelect,
  257. videoQuality
  258. } = this._sliderOptions[event.target.value];
  259. // Take no action if the newly chosen option does not change audio only
  260. // or video quality state.
  261. if ((_audioOnly && audioOnly)
  262. || (!_audioOnly && videoQuality === _receiveVideoQuality)) {
  263. return;
  264. }
  265. onSelect();
  266. }
  267. }
  268. /**
  269. * Maps (parts of) the Redux state to the associated props for the
  270. * {@code VideoQualityDialog} component.
  271. *
  272. * @param {Object} state - The Redux state.
  273. * @private
  274. * @returns {{
  275. * _audioOnly: boolean,
  276. * _p2p: boolean,
  277. * _receiveVideoQuality: boolean
  278. * }}
  279. */
  280. function _mapStateToProps(state) {
  281. const {
  282. audioOnly,
  283. p2p,
  284. receiveVideoQuality
  285. } = state['features/base/conference'];
  286. return {
  287. _audioOnly: audioOnly,
  288. _p2p: p2p,
  289. _receiveVideoQuality: receiveVideoQuality
  290. };
  291. }
  292. export default translate(connect(_mapStateToProps)(VideoQualityDialog));