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

243 lines
6.4 KiB
JavaScript
Raw Normal View History

/* global APP */
import React, { Component } from 'react';
import { connect } from 'react-redux';
import PageReloadOverlay from './PageReloadOverlay';
import SuspendedOverlay from './SuspendedOverlay';
import UserMediaPermissionsOverlay from './UserMediaPermissionsOverlay';
/**
* 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: React.PropTypes.string,
/**
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: React.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: React.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}
*/
2017-02-22 18:57:07 +00:00
_isMediaPermissionPromptVisible: React.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}
*/
2017-02-22 18:57:07 +00:00
_isNetworkFailure: React.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: React.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: React.PropTypes.bool
}
/**
* React Component method that executes once component is updated.
*
* @inheritdoc
* @returns {void}
* @protected
*/
componentDidUpdate() {
// FIXME: Temporary workaround until everything is moved to react.
APP.UI.overlayVisible
= (this.props._connectionEstablished && this.props._haveToReload)
2017-02-19 00:42:11 +00:00
|| this.props._suspendDetected
2017-02-22 18:57:07 +00:00
|| this.props._isMediaPermissionPromptVisible;
}
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
* @returns {ReactElement|null}
* @public
*/
render() {
if (this.props._connectionEstablished && this.props._haveToReload) {
return (
<PageReloadOverlay
isNetworkFailure = { this.props._isNetworkFailure }
reason = { this.props._reason } />
);
}
if (this.props._suspendDetected) {
return (
<SuspendedOverlay />
);
}
2017-02-22 18:57:07 +00:00
if (this.props._isMediaPermissionPromptVisible) {
return (
<UserMediaPermissionsOverlay
browser = { this.props._browser } />
);
}
return 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,
* _connectionEstablished: bool,
* _haveToReload: bool,
* _isNetworkFailure: bool,
2017-02-22 18:57:07 +00:00
* _isMediaPermissionPromptVisible: bool,
2017-02-19 00:42:11 +00:00
* _reason: string,
* _suspendDetected: bool
* }}
* @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 UserMediaPermissionsOverlay only.
2017-02-19 00:42:11 +00:00
*
* @private
* @type {string}
*/
2017-02-19 00:42:11 +00:00
_browser: stateFeaturesOverlay.browser,
/**
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}
*/
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 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
*
2017-02-22 18:57:07 +00:00
* NOTE: Used by 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
*
2017-02-22 18:57:07 +00:00
* NOTE: Used by 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 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 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);