Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

VideoQualitySlider.web.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. // @flow
  2. import { withStyles } from '@material-ui/core/styles';
  3. import clsx from 'clsx';
  4. import React, { Component } from 'react';
  5. import type { Dispatch } from 'redux';
  6. import { createToolbarEvent, sendAnalytics } from '../../analytics';
  7. import { setAudioOnly } from '../../base/audio-only';
  8. import { translate } from '../../base/i18n';
  9. import { setLastN, getLastNForQualityLevel } from '../../base/lastn';
  10. import { connect } from '../../base/redux';
  11. import { withPixelLineHeight } from '../../base/styles/functions.web';
  12. import { setPreferredVideoQuality } from '../actions';
  13. import { DEFAULT_LAST_N, VIDEO_QUALITY_LEVELS } from '../constants';
  14. import logger from '../logger';
  15. import Slider from './Slider';
  16. const {
  17. ULTRA,
  18. HIGH,
  19. STANDARD,
  20. LOW
  21. } = VIDEO_QUALITY_LEVELS;
  22. /**
  23. * Creates an analytics event for a press of one of the buttons in the video
  24. * quality dialog.
  25. *
  26. * @param {string} quality - The quality which was selected.
  27. * @returns {Object} The event in a format suitable for sending via
  28. * sendAnalytics.
  29. */
  30. const createEvent = function(quality) {
  31. return createToolbarEvent(
  32. 'video.quality',
  33. {
  34. quality
  35. });
  36. };
  37. /**
  38. * The type of the React {@code Component} props of {@link VideoQualitySlider}.
  39. */
  40. type Props = {
  41. /**
  42. * Whether or not the conference is in audio only mode.
  43. */
  44. _audioOnly: Boolean,
  45. /**
  46. * The channelLastN value configured for the conference.
  47. */
  48. _channelLastN: Number,
  49. /**
  50. * Whether or not the conference is in peer to peer mode.
  51. */
  52. _p2p: Boolean,
  53. /**
  54. * The currently configured maximum quality resolution to be sent and
  55. * received from the remote participants.
  56. */
  57. _sendrecvVideoQuality: Number,
  58. /**
  59. * An object containing the CSS classes.
  60. */
  61. classes: Object,
  62. /**
  63. * Invoked to request toggling of audio only mode.
  64. */
  65. dispatch: Dispatch<any>,
  66. /**
  67. * Invoked to obtain translated strings.
  68. */
  69. t: Function
  70. };
  71. /**
  72. * Creates the styles for the component.
  73. *
  74. * @param {Object} theme - The current UI theme.
  75. *
  76. * @returns {Object}
  77. */
  78. const styles = theme => {
  79. return {
  80. dialog: {
  81. color: theme.palette.text01
  82. },
  83. dialogDetails: {
  84. ...withPixelLineHeight(theme.typography.bodyShortRegularLarge),
  85. marginBottom: 16
  86. },
  87. dialogContents: {
  88. background: theme.palette.ui01,
  89. padding: '16px 16px 48px 16px'
  90. },
  91. sliderDescription: {
  92. ...withPixelLineHeight(theme.typography.heading6),
  93. display: 'flex',
  94. justifyContent: 'space-between',
  95. marginBottom: 40
  96. }
  97. };
  98. };
  99. /**
  100. * Implements a React {@link Component} which displays a slider for selecting a
  101. * new receive video quality.
  102. *
  103. * @extends Component
  104. */
  105. class VideoQualitySlider extends Component<Props> {
  106. _sliderOptions: Array<Object>;
  107. /**
  108. * Initializes a new {@code VideoQualitySlider} instance.
  109. *
  110. * @param {Object} props - The read-only React Component props with which
  111. * the new instance is to be initialized.
  112. */
  113. constructor(props) {
  114. super(props);
  115. // Bind event handlers so they are only bound once for every instance.
  116. this._enableAudioOnly = this._enableAudioOnly.bind(this);
  117. this._enableHighDefinition = this._enableHighDefinition.bind(this);
  118. this._enableLowDefinition = this._enableLowDefinition.bind(this);
  119. this._enableStandardDefinition
  120. = this._enableStandardDefinition.bind(this);
  121. this._enableUltraHighDefinition = this._enableUltraHighDefinition.bind(this);
  122. this._onSliderChange = this._onSliderChange.bind(this);
  123. /**
  124. * An array of configuration options for displaying a choice in the
  125. * input. The onSelect callback will be invoked when the option is
  126. * selected and videoQuality helps determine which choice matches with
  127. * the currently active quality level.
  128. *
  129. * @private
  130. * @type {Object[]}
  131. */
  132. this._sliderOptions = [
  133. {
  134. audioOnly: true,
  135. onSelect: this._enableAudioOnly,
  136. textKey: 'audioOnly.audioOnly'
  137. },
  138. {
  139. onSelect: this._enableLowDefinition,
  140. textKey: 'videoStatus.lowDefinition',
  141. videoQuality: LOW
  142. },
  143. {
  144. onSelect: this._enableStandardDefinition,
  145. textKey: 'videoStatus.standardDefinition',
  146. videoQuality: STANDARD
  147. },
  148. {
  149. onSelect: this._enableUltraHighDefinition,
  150. textKey: 'videoStatus.highDefinition',
  151. videoQuality: ULTRA
  152. }
  153. ];
  154. }
  155. /**
  156. * Implements React's {@link Component#render()}.
  157. *
  158. * @inheritdoc
  159. * @returns {ReactElement}
  160. */
  161. render() {
  162. const { classes, t } = this.props;
  163. const activeSliderOption = this._mapCurrentQualityToSliderValue();
  164. return (
  165. <div className = { clsx('video-quality-dialog', classes.dialog) }>
  166. <div className = { classes.dialogDetails }>{t('videoStatus.adjustFor')}</div>
  167. <div className = { classes.dialogContents }>
  168. <div className = { classes.sliderDescription }>
  169. <span>{t('videoStatus.bestPerformance')}</span>
  170. <span>{t('videoStatus.highestQuality')}</span>
  171. </div>
  172. <Slider
  173. ariaLabel = { t('videoStatus.callQuality') }
  174. max = { this._sliderOptions.length - 1 }
  175. min = { 0 }
  176. onChange = { this._onSliderChange }
  177. step = { 1 }
  178. value = { activeSliderOption } />
  179. </div>
  180. </div>
  181. );
  182. }
  183. _enableAudioOnly: () => void;
  184. /**
  185. * Dispatches an action to enable audio only mode.
  186. *
  187. * @private
  188. * @returns {void}
  189. */
  190. _enableAudioOnly() {
  191. sendAnalytics(createEvent('audio.only'));
  192. logger.log('Video quality: audio only enabled');
  193. this.props.dispatch(setAudioOnly(true));
  194. }
  195. _enableHighDefinition: () => void;
  196. /**
  197. * Handles the action of the high definition video being selected.
  198. * Dispatches an action to receive high quality video from remote
  199. * participants.
  200. *
  201. * @private
  202. * @returns {void}
  203. */
  204. _enableHighDefinition() {
  205. sendAnalytics(createEvent('high'));
  206. logger.log('Video quality: high enabled');
  207. this._setPreferredVideoQuality(HIGH);
  208. }
  209. _enableLowDefinition: () => void;
  210. /**
  211. * Dispatches an action to receive low quality video from remote
  212. * participants.
  213. *
  214. * @private
  215. * @returns {void}
  216. */
  217. _enableLowDefinition() {
  218. sendAnalytics(createEvent('low'));
  219. logger.log('Video quality: low enabled');
  220. this._setPreferredVideoQuality(LOW);
  221. }
  222. _enableStandardDefinition: () => void;
  223. /**
  224. * Dispatches an action to receive standard quality video from remote
  225. * participants.
  226. *
  227. * @private
  228. * @returns {void}
  229. */
  230. _enableStandardDefinition() {
  231. sendAnalytics(createEvent('standard'));
  232. logger.log('Video quality: standard enabled');
  233. this._setPreferredVideoQuality(STANDARD);
  234. }
  235. _enableUltraHighDefinition: () => void;
  236. /**
  237. * Dispatches an action to receive ultra HD quality video from remote
  238. * participants.
  239. *
  240. * @private
  241. * @returns {void}
  242. */
  243. _enableUltraHighDefinition() {
  244. sendAnalytics(createEvent('ultra high'));
  245. logger.log('Video quality: ultra high enabled');
  246. this._setPreferredVideoQuality(ULTRA);
  247. }
  248. /**
  249. * Matches the current video quality state with corresponding index of the
  250. * component's slider options.
  251. *
  252. * @private
  253. * @returns {void}
  254. */
  255. _mapCurrentQualityToSliderValue() {
  256. const { _audioOnly, _sendrecvVideoQuality } = this.props;
  257. const { _sliderOptions } = this;
  258. if (_audioOnly) {
  259. const audioOnlyOption = _sliderOptions.find(
  260. ({ audioOnly }) => audioOnly);
  261. return _sliderOptions.indexOf(audioOnlyOption);
  262. }
  263. for (let i = 0; i < _sliderOptions.length; i++) {
  264. if (_sliderOptions[i].videoQuality >= _sendrecvVideoQuality) {
  265. return i;
  266. }
  267. }
  268. return -1;
  269. }
  270. _onSliderChange: () => void;
  271. /**
  272. * Invokes a callback when the selected video quality changes.
  273. *
  274. * @param {Object} event - The slider's change event.
  275. * @private
  276. * @returns {void}
  277. */
  278. _onSliderChange(event) {
  279. const { _audioOnly, _sendrecvVideoQuality } = this.props;
  280. const {
  281. audioOnly,
  282. onSelect,
  283. videoQuality
  284. } = this._sliderOptions[event.target.value];
  285. // Take no action if the newly chosen option does not change audio only
  286. // or video quality state.
  287. if ((_audioOnly && audioOnly)
  288. || (!_audioOnly && videoQuality === _sendrecvVideoQuality)) {
  289. return;
  290. }
  291. onSelect();
  292. }
  293. /**
  294. * Helper for changing the preferred maximum video quality to receive and
  295. * disable audio only.
  296. *
  297. * @param {number} qualityLevel - The new maximum video quality. Should be
  298. * a value enumerated in {@code VIDEO_QUALITY_LEVELS}.
  299. * @private
  300. * @returns {void}
  301. */
  302. _setPreferredVideoQuality(qualityLevel) {
  303. this.props.dispatch(setPreferredVideoQuality(qualityLevel));
  304. if (this.props._audioOnly) {
  305. this.props.dispatch(setAudioOnly(false));
  306. }
  307. // Determine the lastN value based on the quality setting.
  308. let { _channelLastN = DEFAULT_LAST_N } = this.props;
  309. _channelLastN = _channelLastN === -1 ? DEFAULT_LAST_N : _channelLastN;
  310. const lastN = getLastNForQualityLevel(qualityLevel, _channelLastN);
  311. // Set the lastN for the conference.
  312. this.props.dispatch(setLastN(lastN));
  313. }
  314. }
  315. /**
  316. * Maps (parts of) the Redux state to the associated props for the
  317. * {@code VideoQualitySlider} component.
  318. *
  319. * @param {Object} state - The Redux state.
  320. * @private
  321. * @returns {Props}
  322. */
  323. function _mapStateToProps(state) {
  324. const { enabled: audioOnly } = state['features/base/audio-only'];
  325. const { p2p } = state['features/base/conference'];
  326. const { preferredVideoQuality } = state['features/video-quality'];
  327. const { channelLastN } = state['features/base/config'];
  328. return {
  329. _audioOnly: audioOnly,
  330. _channelLastN: channelLastN,
  331. _p2p: p2p,
  332. _sendrecvVideoQuality: preferredVideoQuality
  333. };
  334. }
  335. export default translate(connect(_mapStateToProps)(withStyles(styles)(VideoQualitySlider)));