jiti-meet/react/features/overlay/components/OverlayContainer.js

289 lines
8.0 KiB
JavaScript
Raw Normal View History

import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
2017-10-05 22:54:13 +00:00
import { CallOverlay } from '../../base/jwt';
import PageReloadFilmstripOnlyOverlay from './PageReloadFilmstripOnlyOverlay';
import PageReloadOverlay from './PageReloadOverlay';
import SuspendedFilmstripOnlyOverlay from './SuspendedFilmstripOnlyOverlay';
import SuspendedOverlay from './SuspendedOverlay';
import UserMediaPermissionsFilmstripOnlyOverlay
from './UserMediaPermissionsFilmstripOnlyOverlay';
import UserMediaPermissionsOverlay from './UserMediaPermissionsOverlay';
declare var interfaceConfig: Object;
/**
* Implements a React Component that will display the correct overlay when
* needed.
*/
class OverlayContainer extends Component {
/**
* OverlayContainer component's property types.
*
* @static
*/
static propTypes = {
/**
* The browser which is used currently.
2017-02-19 00:42:11 +00:00
*
* NOTE: Used by UserMediaPermissionsOverlay only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {string}
*/
_browser: PropTypes.string,
/**
* The indicator which determines whether the {@link CallOverlay} is
* displayed/visible.
*
* @private
* @type {boolean}
*/
_callOverlayVisible: PropTypes.bool,
/**
2017-02-19 00:42:11 +00:00
* The indicator which determines whether the status of the
* JitsiConnection object has been "established" or not.
2017-02-19 00:42:11 +00:00
*
* NOTE: Used by PageReloadOverlay only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {boolean}
*/
_connectionEstablished: PropTypes.bool,
/**
* The indicator which determines whether a critical error for reload
* has been received.
2017-02-19 00:42:11 +00:00
*
* NOTE: Used by PageReloadOverlay only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {boolean}
*/
_haveToReload: PropTypes.bool,
/**
2017-02-22 18:57:07 +00:00
* The indicator which determines whether the GUM permissions prompt is
* displayed or not.
2017-02-19 00:42:11 +00:00
*
2017-02-22 18:57:07 +00:00
* NOTE: Used by UserMediaPermissionsOverlay only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {boolean}
*/
_isMediaPermissionPromptVisible: PropTypes.bool,
/**
2017-02-22 18:57:07 +00:00
* The indicator which determines whether the reload was caused by
* network failure.
2017-02-19 00:42:11 +00:00
*
2017-02-22 18:57:07 +00:00
* NOTE: Used by PageReloadOverlay only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {boolean}
*/
_isNetworkFailure: PropTypes.bool,
/**
* The reason for the error that will cause the reload.
2017-02-19 00:42:11 +00:00
*
* NOTE: Used by PageReloadOverlay only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {string}
*/
_reason: PropTypes.string,
/**
2017-02-19 00:42:11 +00:00
* The indicator which determines whether the GUM permissions prompt is
* displayed or not.
*
* NOTE: Used by SuspendedOverlay only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {string}
*/
_suspendDetected: PropTypes.bool
};
/**
* Initializes a new ReloadTimer instance.
*
* @param {Object} props - The read-only properties with which the new
* instance is to be initialized.
* @public
*/
constructor(props) {
super(props);
this.state = {
/**
* The indicator which determines whether filmstrip-only mode is
* enabled.
*
* @type {boolean}
*/
filmstripOnly:
typeof interfaceConfig === 'object'
&& interfaceConfig.filmStripOnly
};
}
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
* @returns {ReactElement|null}
* @public
*/
render() {
const { filmstripOnly } = this.state;
let overlayComponent, props;
if (this.props._connectionEstablished && this.props._haveToReload) {
overlayComponent
= filmstripOnly
? PageReloadFilmstripOnlyOverlay
: PageReloadOverlay;
props = {
isNetworkFailure: this.props._isNetworkFailure,
reason: this.props._reason
};
} else if (this.props._suspendDetected) {
overlayComponent
= filmstripOnly
? SuspendedFilmstripOnlyOverlay
: SuspendedOverlay;
} else if (this.props._isMediaPermissionPromptVisible) {
overlayComponent
= filmstripOnly
? UserMediaPermissionsFilmstripOnlyOverlay
: UserMediaPermissionsOverlay;
props = {
browser: this.props._browser
};
} else if (this.props._callOverlayVisible) {
overlayComponent = CallOverlay;
}
return (
overlayComponent
? React.createElement(overlayComponent, props)
: null);
}
}
/**
* Maps (parts of) the redux state to the associated OverlayContainer's props.
*
* @param {Object} state - The redux state.
* @returns {{
2017-02-19 00:42:11 +00:00
* _browser: string,
* _callOverlayVisible: boolean,
* _connectionEstablished: boolean,
* _haveToReload: boolean,
* _isNetworkFailure: boolean,
* _isMediaPermissionPromptVisible: boolean,
2017-02-19 00:42:11 +00:00
* _reason: string,
* _suspendDetected: boolean
* }}
* @private
*/
function _mapStateToProps(state) {
2017-02-19 00:42:11 +00:00
const stateFeaturesOverlay = state['features/overlay'];
return {
/**
* The browser which is used currently.
2017-02-19 00:42:11 +00:00
*
* NOTE: Used by {@link UserMediaPermissionsOverlay} only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {string}
*/
2017-02-19 00:42:11 +00:00
_browser: stateFeaturesOverlay.browser,
/**
* The indicator which determines whether the {@link CallOverlay} is
* displayed/visible.
*
* @private
* @type {boolean}
*/
2017-10-05 22:54:13 +00:00
_callOverlayVisible:
Boolean(state['features/base/jwt'].callOverlayVisible),
/**
2017-02-19 00:42:11 +00:00
* The indicator which determines whether the status of the
* JitsiConnection object has been "established" or not.
2017-02-19 00:42:11 +00:00
*
* NOTE: Used by {@link PageReloadOverlay} only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {boolean}
*/
2017-02-19 00:42:11 +00:00
_connectionEstablished: stateFeaturesOverlay.connectionEstablished,
/**
* The indicator which determines whether a critical error for reload
* has been received.
2017-02-19 00:42:11 +00:00
*
* NOTE: Used by {@link PageReloadOverlay} only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {boolean}
*/
2017-02-19 00:42:11 +00:00
_haveToReload: stateFeaturesOverlay.haveToReload,
/**
2017-02-22 18:57:07 +00:00
* The indicator which determines whether the GUM permissions prompt is
* displayed or not.
2017-02-19 00:42:11 +00:00
*
* NOTE: Used by {@link UserMediaPermissionsOverlay} only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {boolean}
*/
2017-02-22 18:57:07 +00:00
_isMediaPermissionPromptVisible:
stateFeaturesOverlay.isMediaPermissionPromptVisible,
/**
2017-02-22 18:57:07 +00:00
* The indicator which determines whether the reload was caused by
* network failure.
2017-02-19 00:42:11 +00:00
*
* NOTE: Used by {@link PageReloadOverlay} only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {boolean}
*/
2017-02-22 18:57:07 +00:00
_isNetworkFailure: stateFeaturesOverlay.isNetworkFailure,
/**
* The reason for the error that will cause the reload.
2017-02-19 00:42:11 +00:00
*
* NOTE: Used by {@link PageReloadOverlay} only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {string}
*/
2017-02-19 00:42:11 +00:00
_reason: stateFeaturesOverlay.reason,
/**
2017-02-19 00:42:11 +00:00
* The indicator which determines whether the GUM permissions prompt is
* displayed or not.
*
* NOTE: Used by {@link SuspendedOverlay} only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {string}
*/
2017-02-19 00:42:11 +00:00
_suspendDetected: stateFeaturesOverlay.suspendDetected
};
}
export default connect(_mapStateToProps)(OverlayContainer);