2019-03-19 15:42:25 +00:00
|
|
|
// @flow
|
2018-10-30 05:02:23 +00:00
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
import React, { Component } from 'react';
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2019-07-31 12:47:52 +00:00
|
|
|
import { createToolbarEvent, sendAnalytics } from '../../analytics';
|
|
|
|
import { setAudioOnly } from '../../base/audio-only';
|
2018-03-07 00:28:19 +00:00
|
|
|
import { translate } from '../../base/i18n';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../base/redux';
|
2020-09-01 19:19:04 +00:00
|
|
|
import { setPreferredVideoQuality } from '../actions';
|
|
|
|
import { VIDEO_QUALITY_LEVELS } from '../constants';
|
2019-08-21 14:50:00 +00:00
|
|
|
import logger from '../logger';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
|
|
|
const {
|
2020-10-06 20:42:38 +00:00
|
|
|
ULTRA,
|
2018-03-07 00:28:19 +00:00
|
|
|
HIGH,
|
|
|
|
STANDARD,
|
|
|
|
LOW
|
|
|
|
} = VIDEO_QUALITY_LEVELS;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an analytics event for a press of one of the buttons in the video
|
|
|
|
* quality dialog.
|
|
|
|
*
|
|
|
|
* @param {string} quality - The quality which was selected.
|
|
|
|
* @returns {Object} The event in a format suitable for sending via
|
|
|
|
* sendAnalytics.
|
|
|
|
*/
|
|
|
|
const createEvent = function(quality) {
|
|
|
|
return createToolbarEvent(
|
|
|
|
'video.quality',
|
|
|
|
{
|
|
|
|
quality
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The type of the React {@code Component} props of {@link VideoQualitySlider}.
|
2018-03-07 00:28:19 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
type Props = {
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* Whether or not the conference is in audio only mode.
|
2018-03-07 00:28:19 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
_audioOnly: Boolean,
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the conference is in peer to peer mode.
|
|
|
|
*/
|
|
|
|
_p2p: Boolean,
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
2020-04-28 02:51:40 +00:00
|
|
|
* The currently configured maximum quality resolution to be sent and
|
|
|
|
* received from the remote participants.
|
2018-10-30 05:02:23 +00:00
|
|
|
*/
|
2020-04-28 02:51:40 +00:00
|
|
|
_sendrecvVideoQuality: Number,
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* Invoked to request toggling of audio only mode.
|
|
|
|
*/
|
2019-03-19 15:42:25 +00:00
|
|
|
dispatch: Dispatch<any>,
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a React {@link Component} which displays a slider for selecting a
|
|
|
|
* new receive video quality.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
|
|
|
class VideoQualitySlider extends Component<Props> {
|
|
|
|
_sliderOptions: Array<Object>;
|
2018-03-07 00:28:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new {@code VideoQualitySlider} instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only React Component props with which
|
|
|
|
* the new instance is to be initialized.
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once for every instance.
|
|
|
|
this._enableAudioOnly = this._enableAudioOnly.bind(this);
|
|
|
|
this._enableHighDefinition = this._enableHighDefinition.bind(this);
|
|
|
|
this._enableLowDefinition = this._enableLowDefinition.bind(this);
|
|
|
|
this._enableStandardDefinition
|
|
|
|
= this._enableStandardDefinition.bind(this);
|
2020-10-06 20:42:38 +00:00
|
|
|
this._enableUltraHighDefinition = this._enableUltraHighDefinition.bind(this);
|
2018-03-07 00:28:19 +00:00
|
|
|
this._onSliderChange = this._onSliderChange.bind(this);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of configuration options for displaying a choice in the
|
|
|
|
* input. The onSelect callback will be invoked when the option is
|
|
|
|
* selected and videoQuality helps determine which choice matches with
|
|
|
|
* the currently active quality level.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @type {Object[]}
|
|
|
|
*/
|
|
|
|
this._sliderOptions = [
|
|
|
|
{
|
|
|
|
audioOnly: true,
|
|
|
|
onSelect: this._enableAudioOnly,
|
|
|
|
textKey: 'audioOnly.audioOnly'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
onSelect: this._enableLowDefinition,
|
|
|
|
textKey: 'videoStatus.lowDefinition',
|
|
|
|
videoQuality: LOW
|
|
|
|
},
|
|
|
|
{
|
|
|
|
onSelect: this._enableStandardDefinition,
|
|
|
|
textKey: 'videoStatus.standardDefinition',
|
|
|
|
videoQuality: STANDARD
|
|
|
|
},
|
|
|
|
{
|
2020-10-06 20:42:38 +00:00
|
|
|
onSelect: this._enableUltraHighDefinition,
|
2018-03-07 00:28:19 +00:00
|
|
|
textKey: 'videoStatus.highDefinition',
|
2020-10-06 20:42:38 +00:00
|
|
|
videoQuality: ULTRA
|
2018-03-07 00:28:19 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2020-11-06 09:11:59 +00:00
|
|
|
const { t } = this.props;
|
2018-03-07 00:28:19 +00:00
|
|
|
const activeSliderOption = this._mapCurrentQualityToSliderValue();
|
|
|
|
|
|
|
|
return (
|
2020-11-06 09:11:59 +00:00
|
|
|
<div className = { 'video-quality-dialog' }>
|
2018-03-07 00:28:19 +00:00
|
|
|
<h3 className = 'video-quality-dialog-title'>
|
|
|
|
{ t('videoStatus.callQuality') }
|
|
|
|
</h3>
|
|
|
|
<div className = 'video-quality-dialog-contents'>
|
|
|
|
<div className = 'video-quality-dialog-slider-container'>
|
|
|
|
{ /* FIXME: onChange and onMouseUp are both used for
|
|
|
|
* compatibility with IE11. This workaround can be
|
|
|
|
* removed after upgrading to React 16.
|
|
|
|
*/ }
|
|
|
|
<input
|
|
|
|
className = 'video-quality-dialog-slider'
|
|
|
|
max = { this._sliderOptions.length - 1 }
|
|
|
|
min = '0'
|
|
|
|
onChange = { this._onSliderChange }
|
|
|
|
onMouseUp = { this._onSliderChange }
|
|
|
|
step = '1'
|
|
|
|
type = 'range'
|
|
|
|
value
|
|
|
|
= { activeSliderOption } />
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<div className = 'video-quality-dialog-labels'>
|
|
|
|
{ this._createLabels(activeSliderOption) }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates React Elements to display mock tick marks with associated labels.
|
|
|
|
*
|
|
|
|
* @param {number} activeLabelIndex - Which of the sliderOptions should
|
|
|
|
* display as currently active.
|
|
|
|
* @private
|
|
|
|
* @returns {ReactElement[]}
|
|
|
|
*/
|
|
|
|
_createLabels(activeLabelIndex) {
|
|
|
|
const labelsCount = this._sliderOptions.length;
|
|
|
|
const maxWidthOfLabel = `${100 / labelsCount}%`;
|
|
|
|
|
|
|
|
return this._sliderOptions.map((sliderOption, index) => {
|
|
|
|
const style = {
|
|
|
|
maxWidth: maxWidthOfLabel,
|
|
|
|
left: `${(index * 100) / (labelsCount - 1)}%`
|
|
|
|
};
|
|
|
|
|
|
|
|
const isActiveClass = activeLabelIndex === index ? 'active' : '';
|
|
|
|
const className
|
|
|
|
= `video-quality-dialog-label-container ${isActiveClass}`;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className = { className }
|
|
|
|
key = { index }
|
|
|
|
style = { style }>
|
|
|
|
<div className = 'video-quality-dialog-label'>
|
|
|
|
{ this.props.t(sliderOption.textKey) }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_enableAudioOnly: () => void;
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* Dispatches an action to enable audio only mode.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_enableAudioOnly() {
|
|
|
|
sendAnalytics(createEvent('audio.only'));
|
|
|
|
logger.log('Video quality: audio only enabled');
|
|
|
|
this.props.dispatch(setAudioOnly(true));
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_enableHighDefinition: () => void;
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* Handles the action of the high definition video being selected.
|
|
|
|
* Dispatches an action to receive high quality video from remote
|
|
|
|
* participants.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_enableHighDefinition() {
|
|
|
|
sendAnalytics(createEvent('high'));
|
|
|
|
logger.log('Video quality: high enabled');
|
2018-07-24 20:43:09 +00:00
|
|
|
this._setPreferredVideoQuality(HIGH);
|
2018-03-07 00:28:19 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_enableLowDefinition: () => void;
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* Dispatches an action to receive low quality video from remote
|
|
|
|
* participants.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_enableLowDefinition() {
|
|
|
|
sendAnalytics(createEvent('low'));
|
|
|
|
logger.log('Video quality: low enabled');
|
2018-07-24 20:43:09 +00:00
|
|
|
this._setPreferredVideoQuality(LOW);
|
2018-03-07 00:28:19 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_enableStandardDefinition: () => void;
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* Dispatches an action to receive standard quality video from remote
|
|
|
|
* participants.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_enableStandardDefinition() {
|
|
|
|
sendAnalytics(createEvent('standard'));
|
|
|
|
logger.log('Video quality: standard enabled');
|
2018-07-24 20:43:09 +00:00
|
|
|
this._setPreferredVideoQuality(STANDARD);
|
2018-03-07 00:28:19 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 20:42:38 +00:00
|
|
|
_enableUltraHighDefinition: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatches an action to receive ultra HD quality video from remote
|
|
|
|
* participants.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_enableUltraHighDefinition() {
|
|
|
|
sendAnalytics(createEvent('ultra high'));
|
|
|
|
logger.log('Video quality: ultra high enabled');
|
|
|
|
this._setPreferredVideoQuality(ULTRA);
|
|
|
|
}
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* Matches the current video quality state with corresponding index of the
|
|
|
|
* component's slider options.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_mapCurrentQualityToSliderValue() {
|
2020-04-28 02:51:40 +00:00
|
|
|
const { _audioOnly, _sendrecvVideoQuality } = this.props;
|
2018-03-07 00:28:19 +00:00
|
|
|
const { _sliderOptions } = this;
|
|
|
|
|
|
|
|
if (_audioOnly) {
|
|
|
|
const audioOnlyOption = _sliderOptions.find(
|
|
|
|
({ audioOnly }) => audioOnly);
|
|
|
|
|
|
|
|
return _sliderOptions.indexOf(audioOnlyOption);
|
|
|
|
}
|
|
|
|
|
2020-09-01 21:45:59 +00:00
|
|
|
for (let i = 0; i < _sliderOptions.length; i++) {
|
|
|
|
if (_sliderOptions[i].videoQuality >= _sendrecvVideoQuality) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2020-09-01 21:45:59 +00:00
|
|
|
return -1;
|
2018-03-07 00:28:19 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onSliderChange: () => void;
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* Invokes a callback when the selected video quality changes.
|
|
|
|
*
|
|
|
|
* @param {Object} event - The slider's change event.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onSliderChange(event) {
|
2020-04-28 02:51:40 +00:00
|
|
|
const { _audioOnly, _sendrecvVideoQuality } = this.props;
|
2018-03-07 00:28:19 +00:00
|
|
|
const {
|
|
|
|
audioOnly,
|
|
|
|
onSelect,
|
|
|
|
videoQuality
|
|
|
|
} = this._sliderOptions[event.target.value];
|
|
|
|
|
|
|
|
// Take no action if the newly chosen option does not change audio only
|
|
|
|
// or video quality state.
|
|
|
|
if ((_audioOnly && audioOnly)
|
2020-04-28 02:51:40 +00:00
|
|
|
|| (!_audioOnly && videoQuality === _sendrecvVideoQuality)) {
|
2018-03-07 00:28:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
onSelect();
|
|
|
|
}
|
2018-07-24 20:43:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for changing the preferred maximum video quality to receive and
|
|
|
|
* disable audio only.
|
|
|
|
*
|
|
|
|
* @param {number} qualityLevel - The new maximum video quality. Should be
|
|
|
|
* a value enumerated in {@code VIDEO_QUALITY_LEVELS}.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_setPreferredVideoQuality(qualityLevel) {
|
2020-04-28 02:51:40 +00:00
|
|
|
this.props.dispatch(setPreferredVideoQuality(qualityLevel));
|
2018-07-24 20:43:09 +00:00
|
|
|
|
|
|
|
if (this.props._audioOnly) {
|
|
|
|
this.props.dispatch(setAudioOnly(false));
|
|
|
|
}
|
|
|
|
}
|
2018-03-07 00:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated props for the
|
|
|
|
* {@code VideoQualitySlider} component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
2020-11-06 09:11:59 +00:00
|
|
|
* @returns {Props}
|
2018-03-07 00:28:19 +00:00
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
2019-07-31 12:47:52 +00:00
|
|
|
const { enabled: audioOnly } = state['features/base/audio-only'];
|
2020-09-01 19:19:04 +00:00
|
|
|
const { p2p } = state['features/base/conference'];
|
|
|
|
const { preferredVideoQuality } = state['features/video-quality'];
|
2018-03-07 00:28:19 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
_audioOnly: audioOnly,
|
|
|
|
_p2p: p2p,
|
2020-11-06 09:11:59 +00:00
|
|
|
_sendrecvVideoQuality: preferredVideoQuality
|
2018-03-07 00:28:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps)(VideoQualitySlider));
|