123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- // @flow
-
- import React from 'react';
- import { BackHandler, NativeModules, SafeAreaView, StatusBar, View } from 'react-native';
-
- import { appNavigate } from '../../../app';
- import { PIP_ENABLED, getFeatureFlag } from '../../../base/flags';
- import { getParticipantCount } from '../../../base/participants';
- import { Container, LoadingIndicator, TintedView } from '../../../base/react';
- import { connect } from '../../../base/redux';
- import {
- isNarrowAspectRatio,
- makeAspectRatioAware
- } from '../../../base/responsive-ui';
- import { TestConnectionInfo } from '../../../base/testing';
- import { ConferenceNotification } from '../../../calendar-sync';
- import { Chat } from '../../../chat';
- import { DisplayNameLabel } from '../../../display-name';
- import {
- FILMSTRIP_SIZE,
- Filmstrip,
- isFilmstripVisible,
- TileView
- } from '../../../filmstrip';
- import { LargeVideo } from '../../../large-video';
- import { AddPeopleDialog, CalleeInfoContainer } from '../../../invite';
- import { Captions } from '../../../subtitles';
- import { setToolboxVisible, Toolbox } from '../../../toolbox';
-
- import {
- AbstractConference,
- abstractMapStateToProps
- } from '../AbstractConference';
- import Labels from './Labels';
- import NavigationBar from './NavigationBar';
- import styles from './styles';
-
- import type { AbstractProps } from '../AbstractConference';
-
- /**
- * The type of the React {@code Component} props of {@link Conference}.
- */
- type Props = AbstractProps & {
-
- /**
- * 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
- */
- _connecting: boolean,
-
- /**
- * Set to {@code true} when the filmstrip is currently visible.
- *
- * @private
- */
- _filmstripVisible: boolean,
-
- /**
- * The ID of the participant currently on stage (if any)
- */
- _largeVideoParticipantId: string,
-
- /**
- * The number of participants in the conference.
- *
- * @private
- */
- _participantCount: number,
-
- /**
- * Whether Picture-in-Picture is enabled.
- *
- * @private
- */
- _pictureInPictureEnabled: boolean,
-
- /**
- * The indicator which determines whether the UI is reduced (to accommodate
- * smaller display areas).
- *
- * @private
- */
- _reducedUI: boolean,
-
- /**
- * The handler which dispatches the (redux) action {@link setToolboxVisible}
- * to show/hide the {@link Toolbox}.
- *
- * @param {boolean} visible - {@code true} to show the {@code Toolbox} or
- * {@code false} to hide it.
- * @private
- * @returns {void}
- */
- _setToolboxVisible: Function,
-
- /**
- * The indicator which determines whether the Toolbox is visible.
- *
- * @private
- */
- _toolboxVisible: boolean,
-
- /**
- * The indicator which determines whether the Toolbox is always visible.
- *
- * @private
- */
- _toolboxAlwaysVisible: boolean,
-
- /**
- * The redux {@code dispatch} function.
- */
- dispatch: Function
- };
-
- /**
- * The conference page of the mobile (i.e. React Native) application.
- */
- class Conference extends AbstractConference<Props, *> {
- /**
- * 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);
-
- // Bind event handlers so they are only bound once per instance.
- this._onClick = this._onClick.bind(this);
- this._onHardwareBackPress = this._onHardwareBackPress.bind(this);
- this._setToolboxVisible = this._setToolboxVisible.bind(this);
- }
-
- /**
- * Implements {@link Component#componentDidMount()}. Invoked immediately
- * after this component is mounted.
- *
- * @inheritdoc
- * @returns {void}
- */
- componentDidMount() {
- BackHandler.addEventListener('hardwareBackPress', this._onHardwareBackPress);
-
- // Show the toolbox if we are the only participant; otherwise, the whole
- // UI looks too unpopulated the LargeVideo visible.
- this.props._participantCount === 1 && this._setToolboxVisible(true);
- }
-
- /**
- * Implements React's {@link Component#componentDidUpdate()}.
- *
- * @inheritdoc
- */
- componentDidUpdate(prevProps: Props) {
- const {
- _participantCount: oldParticipantCount
- } = prevProps;
- const {
- _participantCount: newParticipantCount,
- _toolboxVisible
- } = this.props;
-
- if (oldParticipantCount === 1
- && newParticipantCount > 1
- && _toolboxVisible) {
- this._setToolboxVisible(false);
- } else if (oldParticipantCount > 1
- && newParticipantCount === 1
- && !_toolboxVisible) {
- this._setToolboxVisible(true);
- }
- }
-
- /**
- * 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.
- BackHandler.removeEventListener('hardwareBackPress', this._onHardwareBackPress);
- }
-
- /**
- * Implements React's {@link Component#render()}.
- *
- * @inheritdoc
- * @returns {ReactElement}
- */
- render() {
- const {
- _connecting,
- _largeVideoParticipantId,
- _reducedUI,
- _shouldDisplayTileView
- } = this.props;
-
- return (
- <Container style = { styles.conference }>
- <StatusBar
- barStyle = 'light-content'
- hidden = { true }
- translucent = { true } />
-
- <Chat />
- <AddPeopleDialog />
-
- {/*
- * The LargeVideo is the lowermost stacking layer.
- */
- _shouldDisplayTileView
- ? <TileView onClick = { this._onClick } />
- : <LargeVideo onClick = { this._onClick } />
- }
-
- {/*
- * If there is a ringing call, show the callee's info.
- */
- _reducedUI || <CalleeInfoContainer />
- }
-
- {/*
- * The activity/loading indicator goes above everything, except
- * the toolbox/toolbars and the dialogs.
- */
- _connecting
- && <TintedView>
- <LoadingIndicator />
- </TintedView>
- }
-
- <View
- pointerEvents = 'box-none'
- style = { styles.toolboxAndFilmstripContainer }>
-
- <Labels />
-
- <Captions onPress = { this._onClick } />
-
- { _shouldDisplayTileView || <DisplayNameLabel participantId = { _largeVideoParticipantId } /> }
-
- {/*
- * The Toolbox is in a stacking layer bellow the Filmstrip.
- */}
- <Toolbox />
-
- {/*
- * 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.
- */
- _shouldDisplayTileView ? undefined : <Filmstrip />
- }
- </View>
-
- <SafeAreaView
- pointerEvents = 'box-none'
- style = { styles.navBarSafeView }>
- <NavigationBar />
- { this.renderNotificationsContainer() }
- </SafeAreaView>
-
- <TestConnectionInfo />
-
- {
- this._renderConferenceNotification()
- }
-
- </Container>
- );
- }
-
- _onClick: () => void;
-
- /**
- * Changes the value of the toolboxVisible state, thus allowing us to switch
- * between Toolbox and Filmstrip and change their visibility.
- *
- * @private
- * @returns {void}
- */
- _onClick() {
- if (this.props._toolboxAlwaysVisible) {
- return;
- }
-
- this._setToolboxVisible(!this.props._toolboxVisible);
- }
-
- _onHardwareBackPress: () => boolean;
-
- /**
- * Handles a hardware button press for back navigation. Enters Picture-in-Picture mode
- * (if supported) or leaves the associated {@code Conference} otherwise.
- *
- * @returns {boolean} Exiting the app is undesired, so {@code true} is always returned.
- */
- _onHardwareBackPress() {
- let p;
-
- if (this.props._pictureInPictureEnabled) {
- const { PictureInPicture } = NativeModules;
-
- p = PictureInPicture.enterPictureInPicture();
- } else {
- p = Promise.reject(new Error('PiP not enabled'));
- }
-
- p.catch(() => {
- this.props.dispatch(appNavigate(undefined));
- });
-
- return true;
- }
-
- /**
- * Renders the conference notification badge if the feature is enabled.
- *
- * @private
- * @returns {React$Node}
- */
- _renderConferenceNotification() {
- // XXX If the calendar feature is disabled on a platform, then we don't
- // have its components exported so an undefined check is necessary.
- return (
- !this.props._reducedUI && ConferenceNotification
- ? <ConferenceNotification />
- : undefined);
- }
-
- /**
- * Renders a container for notifications to be displayed by the
- * base/notifications feature.
- *
- * @private
- * @returns {React$Element}
- */
- renderNotificationsContainer() {
- const notificationsStyle = {};
-
- // In the landscape mode (wide) there's problem with notifications being
- // shadowed by the filmstrip rendered on the right. This makes the "x"
- // button not clickable. In order to avoid that a margin of the
- // filmstrip's size is added to the right.
- //
- // Pawel: after many attempts I failed to make notifications adjust to
- // their contents width because of column and rows being used in the
- // flex layout. The only option that seemed to limit the notification's
- // size was explicit 'width' value which is not better than the margin
- // added here.
- if (this.props._filmstripVisible && !isNarrowAspectRatio(this)) {
- notificationsStyle.marginRight = FILMSTRIP_SIZE;
- }
-
- return super.renderNotificationsContainer(
- {
- style: notificationsStyle
- }
- );
- }
-
- _setToolboxVisible: (boolean) => void;
-
- /**
- * Dispatches an action changing the visibility of the {@link Toolbox}.
- *
- * @private
- * @param {boolean} visible - Pass {@code true} to show the
- * {@code Toolbox} or {@code false} to hide it.
- * @returns {void}
- */
- _setToolboxVisible(visible) {
- this.props.dispatch(setToolboxVisible(visible));
- }
- }
-
- /**
- * Maps (parts of) the redux state to the associated {@code Conference}'s props.
- *
- * @param {Object} state - The redux state.
- * @private
- * @returns {Props}
- */
- function _mapStateToProps(state) {
- const { connecting, connection } = state['features/base/connection'];
- const {
- conference,
- joining,
- leaving
- } = state['features/base/conference'];
- const { reducedUI } = state['features/base/responsive-ui'];
- const { alwaysVisible, visible } = state['features/toolbox'];
-
- // 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)));
-
- return {
- ...abstractMapStateToProps(state),
-
- /**
- * 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_),
-
- /**
- * Is {@code true} when the filmstrip is currently visible.
- */
- _filmstripVisible: isFilmstripVisible(state),
-
- /**
- * The ID of the participant currently on stage.
- */
- _largeVideoParticipantId: state['features/large-video'].participantId,
-
- /**
- * The number of participants in the conference.
- *
- * @private
- * @type {number}
- */
- _participantCount: getParticipantCount(state),
-
- /**
- * Whether Picture-in-Picture is enabled.
- *
- * @private
- * @type {boolean}
- */
- _pictureInPictureEnabled: getFeatureFlag(state, PIP_ENABLED),
-
- /**
- * The indicator which determines whether the UI is reduced (to
- * accommodate smaller display areas).
- *
- * @private
- * @type {boolean}
- */
- _reducedUI: reducedUI,
-
- /**
- * The indicator which determines whether the Toolbox is visible.
- *
- * @private
- * @type {boolean}
- */
- _toolboxVisible: visible,
-
- /**
- * The indicator which determines whether the Toolbox is always visible.
- *
- * @private
- * @type {boolean}
- */
- _toolboxAlwaysVisible: alwaysVisible
- };
- }
-
- export default connect(_mapStateToProps)(makeAspectRatioAware(Conference));
|