jiti-meet/react/features/conference/components/Conference.native.js

408 lines
12 KiB
JavaScript
Raw Normal View History

// @flow
import React, { Component } from 'react';
// eslint-disable-next-line react-native/split-platform-components
import { BackAndroid, BackHandler, View } from 'react-native';
import { connect as reactReduxConnect } from 'react-redux';
import { appNavigate } from '../../app';
2016-12-12 00:29:13 +00:00
import { connect, disconnect } from '../../base/connection';
2017-03-07 03:34:51 +00:00
import { DialogContainer } from '../../base/dialog';
2017-12-13 03:58:33 +00:00
import { CalleeInfoContainer } from '../../base/jwt';
import { Container, LoadingIndicator, TintedView } from '../../base/react';
import { createDesiredLocalTracks } from '../../base/tracks';
import { Filmstrip } from '../../filmstrip';
2017-01-17 14:44:50 +00:00
import { LargeVideo } from '../../large-video';
2017-04-01 05:52:40 +00:00
import { setToolboxVisible, Toolbox } from '../../toolbox';
import styles from './styles';
/**
2017-04-01 05:52:40 +00:00
* The timeout in milliseconds after which the Toolbox will be hidden.
2017-02-02 16:49:14 +00:00
*
* @private
* @type {number}
*/
2017-04-01 05:52:40 +00:00
const _TOOLBOX_TIMEOUT_MS = 5000;
/**
* The type of the React {@code Component} props of {@link Conference}.
*/
type Props = {
2017-11-13 15:54:04 +00:00
/**
2017-11-13 15:54:04 +00:00
* The indicator which determines that we are still connecting to the
* conference which includes establishing the XMPP connection and then
* joining the room. If truthy, then an activity/loading indicator will
* be rendered.
*
2017-11-13 15:54:04 +00:00
* @private
*/
2017-11-13 15:54:04 +00:00
_connecting: boolean,
2017-11-13 15:54:04 +00:00
/**
* The handler which dispatches the (redux) action connect.
*
* @private
*/
_onConnect: Function,
2017-02-16 23:02:40 +00:00
2017-11-13 15:54:04 +00:00
/**
* The handler which dispatches the (redux) action disconnect.
*
* @private
*/
_onDisconnect: Function,
2017-02-16 23:02:40 +00:00
2017-11-13 15:54:04 +00:00
/**
* Handles a hardware button press for back navigation. Leaves the
* associated {@code Conference}.
*
* @private
* @returns {boolean} As the associated conference is unconditionally
* left and exiting the app while it renders a {@code Conference} is
* undesired, {@code true} is always returned.
*/
_onHardwareBackPress: Function,
2017-11-13 15:54:04 +00:00
/**
* The handler which dispatches the (redux) action setToolboxVisible to
* show/hide the Toolbox.
*
* @private
*/
_setToolboxVisible: Function,
2017-02-16 23:02:40 +00:00
2017-11-13 15:54:04 +00:00
/**
* The indicator which determines whether the Toolbox is visible.
*
* @private
*/
_toolboxVisible: boolean
};
2017-11-13 15:54:04 +00:00
/**
* The conference page of the mobile (i.e. React Native) application.
*/
class Conference extends Component<Props> {
_backHandler: ?BackHandler;
_toolboxTimeout: ?number;
/**
* Initializes a new Conference instance.
*
* @param {Object} props - The read-only properties with which the new
* instance is to be initialized.
*/
constructor(props) {
super(props);
/**
* The numerical ID of the timeout in milliseconds after which the
2017-04-01 05:52:40 +00:00
* Toolbox will be hidden. To be used with
* {@link WindowTimers#clearTimeout()}.
*
* @private
*/
2017-04-01 05:52:40 +00:00
this._toolboxTimeout = undefined;
// Bind event handlers so they are only bound once per instance.
this._onClick = this._onClick.bind(this);
this._onHardwareBackPress = this._onHardwareBackPress.bind(this);
}
/**
* Implements {@link Component#componentDidMount()}. Invoked immediately
* after this component is mounted.
*
2017-01-03 21:09:52 +00:00
* @inheritdoc
2017-11-03 20:14:38 +00:00
* @returns {void}
*/
componentDidMount() {
// Set handling any hardware button presses for back navigation up.
const backHandler = BackHandler || BackAndroid;
if (backHandler) {
this._backHandler = backHandler;
backHandler.addEventListener(
'hardwareBackPress',
this._onHardwareBackPress);
}
2017-04-01 05:52:40 +00:00
this._setToolboxTimeout(this.props._toolboxVisible);
}
/**
* Implements {@link Component#componentWillMount()}. Invoked immediately
* before mounting occurs. Connects the conference described by the redux
* store/state.
*
* @inheritdoc
* @returns {void}
*/
componentWillMount() {
2017-02-16 23:02:40 +00:00
this.props._onConnect();
}
/**
* Implements {@link Component#componentWillUnmount()}. Invoked immediately
* before this component is unmounted and destroyed. Disconnects the
* conference described by the redux store/state.
*
* @inheritdoc
* @returns {void}
*/
componentWillUnmount() {
// Tear handling any hardware button presses for back navigation down.
const backHandler = this._backHandler;
if (backHandler) {
this._backHandler = undefined;
backHandler.removeEventListener(
'hardwareBackPress',
this._onHardwareBackPress);
}
2017-04-01 05:52:40 +00:00
this._clearToolboxTimeout();
2017-02-16 23:02:40 +00:00
this.props._onDisconnect();
}
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
* @returns {ReactElement}
*/
render() {
return (
<Container
accessibilityLabel = 'Conference'
accessible = { false }
onClick = { this._onClick }
style = { styles.conference }
touchFeedback = { false }>
{/*
* The LargeVideo is the lowermost stacking layer.
*/}
<LargeVideo />
2016-12-12 01:02:50 +00:00
{/*
* If there is a ringing call, show the callee's info.
2017-12-13 03:58:33 +00:00
*/}
<CalleeInfoContainer />
{/*
* The activity/loading indicator goes above everything, except
* the toolbox/toolbars and the dialogs.
*/
this.props._connecting
&& <TintedView>
<LoadingIndicator />
</TintedView>
}
<View style = { styles.toolboxAndFilmstripContainer } >
{/*
2017-11-07 14:28:08 +00:00
* The Toolbox is in a stacking layer bellow the Filmstrip.
*/}
<Toolbox />
{/*
2017-11-07 14:28:08 +00:00
* The Filmstrip is in a stacking layer above the
* LargeVideo. The LargeVideo and the Filmstrip form what
* the Web/React app calls "videospace". Presumably, the
* name and grouping stem from the fact that these two
* React Components depict the videos of the conference's
* participants.
*/}
<Filmstrip />
</View>
{/*
* The dialogs are in the topmost stacking layers.
*/}
2017-02-16 23:02:40 +00:00
<DialogContainer />
</Container>
);
}
/**
2017-04-01 05:52:40 +00:00
* Clears {@link #_toolboxTimeout} if any.
*
* @private
* @returns {void}
*/
2017-04-01 05:52:40 +00:00
_clearToolboxTimeout() {
if (this._toolboxTimeout) {
clearTimeout(this._toolboxTimeout);
this._toolboxTimeout = undefined;
}
}
_onClick: () => void;
/**
2017-04-01 05:52:40 +00:00
* Changes the value of the toolboxVisible state, thus allowing us to switch
* between Toolbox and Filmstrip and change their visibility.
*
* @private
* @returns {void}
*/
_onClick() {
2017-04-01 05:52:40 +00:00
const toolboxVisible = !this.props._toolboxVisible;
2017-04-01 05:52:40 +00:00
this.props._setToolboxVisible(toolboxVisible);
2017-11-07 23:25:42 +00:00
// XXX If the user taps to toggle the visibility of the Toolbox, then no
// automatic toggling of the visibility should happen.
this._clearToolboxTimeout();
}
2016-12-12 01:02:50 +00:00
_onHardwareBackPress: () => boolean;
/**
* Handles a hardware button press for back navigation.
*
* @returns {boolean} If the hardware button press for back navigation was
* handled by this {@code Conference}, then {@code true}; otherwise,
* {@code false}.
*/
_onHardwareBackPress() {
return this._backHandler && this.props._onHardwareBackPress();
}
/**
2017-04-01 05:52:40 +00:00
* Triggers the default Toolbox timeout.
*
2017-04-01 05:52:40 +00:00
* @param {boolean} toolboxVisible - Indicates whether the Toolbox is
* currently visible.
* @private
* @returns {void}
*/
2017-04-01 05:52:40 +00:00
_setToolboxTimeout(toolboxVisible) {
this._clearToolboxTimeout();
if (toolboxVisible) {
this._toolboxTimeout
= setTimeout(this._onClick, _TOOLBOX_TIMEOUT_MS);
}
}
2016-12-12 01:02:50 +00:00
}
2017-02-16 23:02:40 +00:00
/**
* Maps dispatching of some action to React component props.
*
* @param {Function} dispatch - Redux action dispatcher.
* @private
* @returns {{
* _onConnect: Function,
* _onDisconnect: Function,
2017-04-01 05:52:40 +00:00
* _setToolboxVisible: Function
2017-02-16 23:02:40 +00:00
* }}
*/
function _mapDispatchToProps(dispatch) {
return {
/**
* Dispatches actions to create the desired local tracks and for
* connecting to the conference.
2017-02-16 23:02:40 +00:00
*
* @returns {void}
2017-02-16 23:02:40 +00:00
* @private
*/
_onConnect() {
dispatch(createDesiredLocalTracks());
dispatch(connect());
2017-02-16 23:02:40 +00:00
},
/**
* Dispatches an action disconnecting from the conference.
*
* @returns {void}
2017-02-16 23:02:40 +00:00
* @private
*/
_onDisconnect() {
dispatch(disconnect());
2017-02-16 23:02:40 +00:00
},
/**
* Handles a hardware button press for back navigation. Leaves the
* associated {@code Conference}.
*
* @returns {boolean} As the associated conference is unconditionally
* left and exiting the app while it renders a {@code Conference} is
* undesired, {@code true} is always returned.
*/
_onHardwareBackPress() {
dispatch(appNavigate(undefined));
return true;
},
/**
* Dispatches an action changing the visibility of the Toolbox.
2017-02-16 23:02:40 +00:00
*
2017-04-01 05:52:40 +00:00
* @param {boolean} visible - True to show the Toolbox or false to hide
* it.
* @returns {void}
2017-02-16 23:02:40 +00:00
* @private
*/
_setToolboxVisible(visible) {
dispatch(setToolboxVisible(visible));
2017-02-16 23:02:40 +00:00
}
};
}
/**
* Maps (parts of) the redux state to the associated {@code Conference}'s props.
2017-02-16 23:02:40 +00:00
*
* @param {Object} state - The redux state.
2017-02-16 23:02:40 +00:00
* @private
* @returns {{
* _connecting: boolean,
2017-04-01 05:52:40 +00:00
* _toolboxVisible: boolean
2017-02-16 23:02:40 +00:00
* }}
*/
function _mapStateToProps(state) {
const { connecting, connection } = state['features/base/connection'];
const { conference, joining, leaving } = state['features/base/conference'];
// XXX There is a window of time between the successful establishment of the
// XMPP connection and the subsequent commencement of joining the MUC during
// which the app does not appear to be doing anything according to the redux
// state. In order to not toggle the _connecting props during the window of
// time in question, define _connecting as follows:
// - the XMPP connection is connecting, or
// - the XMPP connection is connected and the conference is joining, or
// - the XMPP connection is connected and we have no conference yet, nor we
// are leaving one.
const connecting_
= connecting || (connection && (joining || (!conference && !leaving)));
2017-02-16 23:02:40 +00:00
return {
/**
* The indicator which determines that we are still connecting to the
* conference which includes establishing the XMPP connection and then
* joining the room. If truthy, then an activity/loading indicator will
* be rendered.
*
* @private
* @type {boolean}
*/
_connecting: Boolean(connecting_),
2017-02-16 23:02:40 +00:00
/**
2017-04-01 05:52:40 +00:00
* The indicator which determines whether the Toolbox is visible.
2017-02-16 23:02:40 +00:00
*
* @private
* @type {boolean}
*/
2017-04-01 05:52:40 +00:00
_toolboxVisible: state['features/toolbox'].visible
2017-02-16 23:02:40 +00:00
};
}
// $FlowFixMe
2017-02-16 23:02:40 +00:00
export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
2017-06-15 00:40:51 +00:00
Conference);