2018-06-14 11:14:17 +00:00
|
|
|
// @flow
|
2018-08-31 20:06:48 +00:00
|
|
|
|
2018-06-14 11:14:17 +00:00
|
|
|
import React from 'react';
|
2018-09-11 10:16:01 +00:00
|
|
|
import { TouchableOpacity, View } from 'react-native';
|
2018-06-14 11:14:17 +00:00
|
|
|
|
2019-02-05 10:10:15 +00:00
|
|
|
import { JitsiRecordingConstants } from '../../../base/lib-jitsi-meet';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../../base/redux';
|
2018-06-14 11:14:17 +00:00
|
|
|
import {
|
|
|
|
isNarrowAspectRatio,
|
|
|
|
makeAspectRatioAware
|
2019-02-05 10:10:15 +00:00
|
|
|
} from '../../../base/responsive-ui';
|
|
|
|
import {
|
|
|
|
RecordingExpandedLabel
|
|
|
|
} from '../../../recording';
|
2019-01-30 15:43:57 +00:00
|
|
|
import { isToolboxVisible } from '../../../toolbox';
|
2019-02-05 10:10:15 +00:00
|
|
|
import { TranscribingExpandedLabel } from '../../../transcribing';
|
2019-01-30 15:43:57 +00:00
|
|
|
import { shouldDisplayTileView } from '../../../video-layout';
|
2019-02-05 10:10:15 +00:00
|
|
|
import { VideoQualityExpandedLabel } from '../../../video-quality';
|
2018-06-14 11:14:17 +00:00
|
|
|
|
2018-08-31 20:12:09 +00:00
|
|
|
import AbstractLabels, {
|
|
|
|
_abstractMapStateToProps,
|
|
|
|
type Props as AbstractLabelsProps
|
2019-02-05 10:10:15 +00:00
|
|
|
} from '../AbstractLabels';
|
2019-03-20 20:09:23 +00:00
|
|
|
import { shouldDisplayNotifications } from '../../functions';
|
2018-06-14 11:14:17 +00:00
|
|
|
import styles from './styles';
|
|
|
|
|
2018-08-31 20:12:09 +00:00
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link Labels}.
|
|
|
|
*/
|
|
|
|
type Props = AbstractLabelsProps & {
|
|
|
|
|
2018-09-11 10:16:01 +00:00
|
|
|
/**
|
|
|
|
* Function to translate i18n labels.
|
|
|
|
*/
|
|
|
|
t: Function,
|
|
|
|
|
2018-08-31 20:12:09 +00:00
|
|
|
/**
|
|
|
|
* The indicator which determines whether the UI is reduced (to accommodate
|
|
|
|
* smaller display areas).
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
2019-01-30 15:43:57 +00:00
|
|
|
_reducedUI: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if the labels should be visible, false otherwise.
|
|
|
|
*/
|
|
|
|
_visible: boolean
|
2018-08-31 20:12:09 +00:00
|
|
|
};
|
|
|
|
|
2018-09-11 10:16:01 +00:00
|
|
|
type State = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Layout object of the outermost container. For stucture please see:
|
|
|
|
* https://facebook.github.io/react-native/docs/view#onlayout
|
|
|
|
*/
|
|
|
|
containerLayout: ?Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Layout objects of the individual labels. This data type contains the same
|
|
|
|
* structure as the layout is defined here:
|
|
|
|
* https://facebook.github.io/react-native/docs/view#onlayout
|
|
|
|
* but keyed with the ID of the label its layout it contains. E.g.
|
|
|
|
*
|
|
|
|
* {
|
|
|
|
* transcribing: {
|
|
|
|
* { layout: { x, y, width, height } }
|
|
|
|
* },
|
|
|
|
* ...
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
labelLayouts: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Position of the label to render the {@code ExpandedLabel} to.
|
|
|
|
*/
|
|
|
|
parentPosition: ?number,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* String to show which {@code ExpandedLabel} to be shown. (Equals to the
|
|
|
|
* label IDs below.)
|
|
|
|
*/
|
|
|
|
visibleExpandedLabel: ?string
|
|
|
|
}
|
|
|
|
|
|
|
|
const LABEL_ID_QUALITY = 'quality';
|
|
|
|
const LABEL_ID_RECORDING = 'recording';
|
|
|
|
const LABEL_ID_STREAMING = 'streaming';
|
|
|
|
const LABEL_ID_TRANSCRIBING = 'transcribing';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The {@code ExpandedLabel} components to be rendered for the individual
|
|
|
|
* {@code Label}s.
|
|
|
|
*/
|
|
|
|
const EXPANDED_LABELS = {
|
|
|
|
quality: VideoQualityExpandedLabel,
|
|
|
|
recording: {
|
|
|
|
component: RecordingExpandedLabel,
|
|
|
|
props: {
|
|
|
|
mode: JitsiRecordingConstants.mode.FILE
|
|
|
|
}
|
|
|
|
},
|
|
|
|
streaming: {
|
|
|
|
component: RecordingExpandedLabel,
|
|
|
|
props: {
|
|
|
|
mode: JitsiRecordingConstants.mode.STREAM
|
|
|
|
}
|
|
|
|
},
|
|
|
|
transcribing: TranscribingExpandedLabel
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Timeout to hide the {@ExpandedLabel}.
|
|
|
|
*/
|
|
|
|
const EXPANDED_LABEL_TIMEOUT = 5000;
|
|
|
|
|
2018-06-14 11:14:17 +00:00
|
|
|
/**
|
|
|
|
* A container that renders the conference indicators, if any.
|
|
|
|
*/
|
2018-09-11 10:16:01 +00:00
|
|
|
class Labels extends AbstractLabels<Props, State> {
|
|
|
|
/**
|
|
|
|
* Timeout for the expanded labels to disappear.
|
|
|
|
*/
|
|
|
|
expandedLabelTimeout: TimeoutID;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new instance of {@code Labels}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
containerLayout: undefined,
|
|
|
|
labelLayouts: {},
|
|
|
|
parentPosition: undefined,
|
|
|
|
visibleExpandedLabel: undefined
|
|
|
|
};
|
|
|
|
|
|
|
|
this._onTopViewLayout = this._onTopViewLayout.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React {@code Component}'s componentWillUnmount.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentWillUnmount() {
|
|
|
|
clearTimeout(this.expandedLabelTimeout);
|
|
|
|
}
|
|
|
|
|
2018-06-14 11:14:17 +00:00
|
|
|
/**
|
|
|
|
* Implements React {@code Component}'s render.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
2019-01-30 15:43:57 +00:00
|
|
|
if (!this.props._visible) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-08-31 20:06:48 +00:00
|
|
|
const wide = !isNarrowAspectRatio(this);
|
2018-08-31 20:12:09 +00:00
|
|
|
const { _filmstripVisible, _reducedUI } = this.props;
|
2018-06-14 11:14:17 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<View
|
|
|
|
pointerEvents = 'box-none'
|
2018-09-11 10:16:01 +00:00
|
|
|
style = { styles.labelWrapper }>
|
|
|
|
<View
|
|
|
|
onLayout = { this._onTopViewLayout }
|
|
|
|
pointerEvents = 'box-none'
|
|
|
|
style = { [
|
|
|
|
styles.indicatorContainer,
|
|
|
|
wide && _filmstripVisible
|
|
|
|
&& styles.indicatorContainerWide
|
|
|
|
] }>
|
|
|
|
<TouchableOpacity
|
|
|
|
onLayout = { this._createOnLayout(LABEL_ID_RECORDING) }
|
|
|
|
onPress = { this._createOnPress(LABEL_ID_RECORDING) } >
|
|
|
|
{
|
|
|
|
this._renderRecordingLabel(
|
|
|
|
JitsiRecordingConstants.mode.FILE)
|
|
|
|
}
|
|
|
|
</TouchableOpacity>
|
|
|
|
<TouchableOpacity
|
|
|
|
onLayout = { this._createOnLayout(LABEL_ID_STREAMING) }
|
|
|
|
onPress = { this._createOnPress(LABEL_ID_STREAMING) } >
|
|
|
|
{
|
|
|
|
this._renderRecordingLabel(
|
|
|
|
JitsiRecordingConstants.mode.STREAM)
|
|
|
|
}
|
|
|
|
</TouchableOpacity>
|
|
|
|
<TouchableOpacity
|
|
|
|
onLayout = {
|
|
|
|
this._createOnLayout(LABEL_ID_TRANSCRIBING)
|
|
|
|
}
|
|
|
|
onPress = {
|
|
|
|
this._createOnPress(LABEL_ID_TRANSCRIBING)
|
|
|
|
} >
|
|
|
|
{
|
|
|
|
this._renderTranscribingLabel()
|
|
|
|
}
|
|
|
|
</TouchableOpacity>
|
|
|
|
{/*
|
|
|
|
* Emil, Lyubomir, Nichole, and Zoli said that the Labels
|
|
|
|
* should not be rendered in Picture-in-Picture. Saul
|
|
|
|
* argued that the recording Labels should be rendered. As
|
|
|
|
* a temporary compromise, don't render the
|
|
|
|
* VideoQualityLabel at least because it's not that
|
|
|
|
* important.
|
|
|
|
*/
|
|
|
|
_reducedUI || (
|
|
|
|
<TouchableOpacity
|
|
|
|
onLayout = {
|
|
|
|
this._createOnLayout(LABEL_ID_QUALITY) }
|
|
|
|
onPress = {
|
|
|
|
this._createOnPress(LABEL_ID_QUALITY) } >
|
|
|
|
{ this._renderVideoQualityLabel() }
|
|
|
|
</TouchableOpacity>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</View>
|
|
|
|
<View
|
|
|
|
style = { [
|
|
|
|
styles.indicatorContainer,
|
|
|
|
wide && _filmstripVisible
|
|
|
|
&& styles.indicatorContainerWide
|
|
|
|
] }>
|
|
|
|
{
|
|
|
|
this._renderExpandedLabel()
|
|
|
|
}
|
|
|
|
</View>
|
2018-06-14 11:14:17 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-11 10:16:01 +00:00
|
|
|
/**
|
|
|
|
* Creates a function to be invoked when the onLayout of the touchables are
|
|
|
|
* triggered.
|
|
|
|
*
|
|
|
|
* @param {string} label - The identifier of the label that's onLayout is
|
|
|
|
* triggered.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
_createOnLayout(label) {
|
|
|
|
return ({ nativeEvent: { layout } }) => {
|
|
|
|
const { labelLayouts } = this.state;
|
|
|
|
const updatedLayout = {};
|
|
|
|
|
|
|
|
updatedLayout[label] = layout;
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
labelLayouts: {
|
|
|
|
...labelLayouts,
|
|
|
|
...updatedLayout
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a function to be invoked when the onPress of the touchables are
|
|
|
|
* triggered.
|
|
|
|
*
|
|
|
|
* @param {string} label - The identifier of the label that's onLayout is
|
|
|
|
* triggered.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
_createOnPress(label) {
|
|
|
|
return () => {
|
|
|
|
const {
|
|
|
|
containerLayout,
|
|
|
|
labelLayouts
|
|
|
|
} = this.state;
|
|
|
|
let { visibleExpandedLabel } = this.state;
|
|
|
|
|
|
|
|
if (containerLayout) {
|
|
|
|
const labelLayout = labelLayouts[label];
|
|
|
|
|
|
|
|
// This calculation has to be changed if the labels are not
|
|
|
|
// positioned right anymore.
|
|
|
|
const right = containerLayout.width - labelLayout.x;
|
|
|
|
|
|
|
|
visibleExpandedLabel
|
|
|
|
= visibleExpandedLabel === label ? undefined : label;
|
|
|
|
|
|
|
|
clearTimeout(this.expandedLabelTimeout);
|
|
|
|
this.setState({
|
|
|
|
parentPosition: right,
|
|
|
|
visibleExpandedLabel
|
|
|
|
});
|
|
|
|
|
|
|
|
if (visibleExpandedLabel) {
|
|
|
|
this.expandedLabelTimeout = setTimeout(() => {
|
|
|
|
this.setState({
|
|
|
|
visibleExpandedLabel: undefined
|
|
|
|
});
|
|
|
|
}, EXPANDED_LABEL_TIMEOUT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
_onTopViewLayout: Object => void
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked when the View containing the {@code Label}s is laid out.
|
|
|
|
*
|
|
|
|
* @param {Object} layout - The native layout object.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onTopViewLayout({ nativeEvent: { layout } }) {
|
|
|
|
this.setState({
|
|
|
|
containerLayout: layout
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rendes the expanded (explaining) label for the label that was touched.
|
|
|
|
*
|
|
|
|
* @returns {React$Element}
|
|
|
|
*/
|
|
|
|
_renderExpandedLabel() {
|
|
|
|
const { parentPosition, visibleExpandedLabel } = this.state;
|
|
|
|
|
|
|
|
if (visibleExpandedLabel) {
|
|
|
|
const expandedLabel = EXPANDED_LABELS[visibleExpandedLabel];
|
|
|
|
|
|
|
|
if (expandedLabel) {
|
|
|
|
const component = expandedLabel.component || expandedLabel;
|
|
|
|
const expandedLabelProps = expandedLabel.props || {};
|
|
|
|
|
|
|
|
return React.createElement(component, {
|
|
|
|
...expandedLabelProps,
|
|
|
|
parentPosition
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-08-31 20:06:48 +00:00
|
|
|
_renderRecordingLabel: string => React$Element<*>;
|
2018-06-14 11:14:17 +00:00
|
|
|
|
2018-08-16 19:34:26 +00:00
|
|
|
_renderTranscribingLabel: () => React$Element<*>
|
|
|
|
|
2018-08-31 20:06:48 +00:00
|
|
|
_renderVideoQualityLabel: () => React$Element<*>;
|
2018-06-14 11:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the redux state to the associated
|
|
|
|
* {@code Labels}'s props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @private
|
|
|
|
* @returns {{
|
2018-08-31 20:12:09 +00:00
|
|
|
* _filmstripVisible: boolean,
|
2019-01-30 15:43:57 +00:00
|
|
|
* _reducedUI: boolean,
|
|
|
|
* _visible: boolean
|
2018-06-14 11:14:17 +00:00
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
|
|
|
return {
|
2018-08-31 20:12:09 +00:00
|
|
|
..._abstractMapStateToProps(state),
|
2019-01-30 15:43:57 +00:00
|
|
|
_reducedUI: state['features/base/responsive-ui'].reducedUI,
|
2019-03-20 20:09:23 +00:00
|
|
|
_visible: !isToolboxVisible(state)
|
|
|
|
&& !shouldDisplayTileView(state)
|
|
|
|
&& !shouldDisplayNotifications(state)
|
2018-06-14 11:14:17 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-31 20:06:48 +00:00
|
|
|
export default connect(_mapStateToProps)(makeAspectRatioAware(Labels));
|