2020-04-16 11:26:44 +00:00
|
|
|
import React, { Component } from 'react';
|
2022-08-08 09:36:06 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2020-04-16 11:26:44 +00:00
|
|
|
|
2022-09-07 08:20:05 +00:00
|
|
|
import { createE2EEEvent } from '../../analytics/AnalyticsEvents';
|
|
|
|
import { sendAnalytics } from '../../analytics/functions';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState, IStore } from '../../app/types';
|
2022-08-08 09:36:06 +00:00
|
|
|
import { translate } from '../../base/i18n/functions';
|
2022-08-02 10:31:11 +00:00
|
|
|
import { connect } from '../../base/redux/functions';
|
|
|
|
import Switch from '../../base/ui/components/web/Switch';
|
2020-05-07 09:54:02 +00:00
|
|
|
import { toggleE2EE } from '../actions';
|
2021-09-21 11:00:23 +00:00
|
|
|
import { MAX_MODE } from '../constants';
|
2021-08-18 13:21:23 +00:00
|
|
|
import { doesEveryoneSupportE2EE } from '../functions';
|
2020-04-16 11:26:44 +00:00
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
interface IProps extends WithTranslation {
|
2020-04-16 11:26:44 +00:00
|
|
|
|
2021-09-21 11:00:23 +00:00
|
|
|
/**
|
|
|
|
* The resource for the description, computed based on the maxMode and whether the switch is toggled or not.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_descriptionResource: string;
|
2021-09-21 11:00:23 +00:00
|
|
|
|
2021-09-08 08:58:25 +00:00
|
|
|
/**
|
2021-09-09 08:10:09 +00:00
|
|
|
* Custom e2ee labels.
|
2021-09-08 08:58:25 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_e2eeLabels: any;
|
2021-09-08 08:58:25 +00:00
|
|
|
|
2020-04-20 15:04:11 +00:00
|
|
|
/**
|
2021-09-21 11:00:23 +00:00
|
|
|
* Whether the switch is currently enabled or not.
|
2020-04-20 15:04:11 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_enabled: boolean;
|
2020-04-20 15:04:11 +00:00
|
|
|
|
2020-04-16 11:26:44 +00:00
|
|
|
/**
|
2020-05-07 09:54:02 +00:00
|
|
|
* Indicates whether all participants in the conference currently support E2EE.
|
2020-04-16 11:26:44 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_everyoneSupportE2EE: boolean;
|
2020-04-16 11:26:44 +00:00
|
|
|
|
2021-09-21 11:00:23 +00:00
|
|
|
/**
|
|
|
|
* Whether E2EE is currently enabled or not.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
_toggled: boolean;
|
2021-09-21 11:00:23 +00:00
|
|
|
|
2020-04-16 11:26:44 +00:00
|
|
|
/**
|
|
|
|
* The redux {@code dispatch} function.
|
|
|
|
*/
|
2022-10-11 10:47:54 +00:00
|
|
|
dispatch: IStore['dispatch'];
|
2022-08-08 09:36:06 +00:00
|
|
|
}
|
2020-04-16 11:26:44 +00:00
|
|
|
|
2022-11-03 08:35:51 +00:00
|
|
|
interface IState {
|
2020-04-16 11:26:44 +00:00
|
|
|
|
2020-06-17 10:53:46 +00:00
|
|
|
/**
|
2020-05-07 09:54:02 +00:00
|
|
|
* True if the switch is toggled on.
|
2020-06-17 10:53:46 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
toggled: boolean;
|
2022-11-03 08:35:51 +00:00
|
|
|
}
|
2020-04-16 11:26:44 +00:00
|
|
|
|
|
|
|
/**
|
2020-06-17 10:53:46 +00:00
|
|
|
* Implements a React {@code Component} for displaying a security dialog section with a field
|
2020-04-16 11:26:44 +00:00
|
|
|
* for setting the E2EE key.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments Component
|
2020-04-16 11:26:44 +00:00
|
|
|
*/
|
2022-11-03 08:35:51 +00:00
|
|
|
class E2EESection extends Component<IProps, IState> {
|
2020-05-07 09:54:02 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#getDerivedStateFromProps()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-11-03 08:35:51 +00:00
|
|
|
static getDerivedStateFromProps(props: IProps, state: IState) {
|
2021-09-21 11:00:23 +00:00
|
|
|
if (props._toggled !== state.toggled) {
|
2020-05-07 09:54:02 +00:00
|
|
|
|
|
|
|
return {
|
2021-09-21 11:00:23 +00:00
|
|
|
toggled: props._toggled
|
2020-05-07 09:54:02 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2020-06-17 10:53:46 +00:00
|
|
|
|
2020-04-16 11:26:44 +00:00
|
|
|
/**
|
2020-05-07 09:54:02 +00:00
|
|
|
* Instantiates a new component.
|
2020-04-16 11:26:44 +00:00
|
|
|
*
|
2020-05-07 09:54:02 +00:00
|
|
|
* @inheritdoc
|
2020-04-16 11:26:44 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
constructor(props: IProps) {
|
2020-04-16 11:26:44 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2021-09-21 11:00:23 +00:00
|
|
|
toggled: false
|
2020-04-16 11:26:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once for every instance.
|
2020-05-07 09:54:02 +00:00
|
|
|
this._onToggle = this._onToggle.bind(this);
|
2020-04-16 11:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2021-09-21 11:00:23 +00:00
|
|
|
const { _descriptionResource, _enabled, _e2eeLabels, _everyoneSupportE2EE, t } = this.props;
|
|
|
|
const { toggled } = this.state;
|
|
|
|
const description = _e2eeLabels?.description || t(_descriptionResource);
|
2021-09-09 08:10:09 +00:00
|
|
|
const label = _e2eeLabels?.label || t('dialog.e2eeLabel');
|
|
|
|
const warning = _e2eeLabels?.warning || t('dialog.e2eeWarning');
|
2020-04-16 11:26:44 +00:00
|
|
|
|
|
|
|
return (
|
2020-06-17 10:53:46 +00:00
|
|
|
<div id = 'e2ee-section'>
|
2021-06-10 12:48:44 +00:00
|
|
|
<p
|
|
|
|
aria-live = 'polite'
|
|
|
|
className = 'description'
|
|
|
|
id = 'e2ee-section-description'>
|
2021-08-18 13:02:25 +00:00
|
|
|
{ description }
|
|
|
|
{ !_everyoneSupportE2EE && <br /> }
|
2021-09-08 08:58:25 +00:00
|
|
|
{ !_everyoneSupportE2EE && warning }
|
2020-06-17 10:53:46 +00:00
|
|
|
</p>
|
2020-05-07 09:54:02 +00:00
|
|
|
<div className = 'control-row'>
|
2021-01-14 16:12:08 +00:00
|
|
|
<label htmlFor = 'e2ee-section-switch'>
|
2021-09-08 08:58:25 +00:00
|
|
|
{ label }
|
2020-06-17 10:53:46 +00:00
|
|
|
</label>
|
2020-05-07 09:54:02 +00:00
|
|
|
<Switch
|
2022-08-02 10:31:11 +00:00
|
|
|
checked = { toggled }
|
2021-09-21 11:00:23 +00:00
|
|
|
disabled = { !_enabled }
|
2021-01-14 16:12:08 +00:00
|
|
|
id = 'e2ee-section-switch'
|
2022-08-02 10:31:11 +00:00
|
|
|
onChange = { this._onToggle } />
|
2020-06-17 10:53:46 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2020-04-16 11:26:44 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 12:12:23 +00:00
|
|
|
/**
|
2020-05-07 09:54:02 +00:00
|
|
|
* Callback to be invoked when the user toggles E2EE on or off.
|
2020-04-16 11:26:44 +00:00
|
|
|
*
|
|
|
|
* @private
|
2020-06-17 10:53:46 +00:00
|
|
|
* @returns {void}
|
2020-04-16 11:26:44 +00:00
|
|
|
*/
|
2020-05-07 09:54:02 +00:00
|
|
|
_onToggle() {
|
2021-09-21 11:00:23 +00:00
|
|
|
const newValue = !this.state.toggled;
|
2020-04-16 11:26:44 +00:00
|
|
|
|
2020-06-17 10:53:46 +00:00
|
|
|
this.setState({
|
2021-09-21 11:00:23 +00:00
|
|
|
toggled: newValue
|
2020-06-17 10:53:46 +00:00
|
|
|
});
|
|
|
|
|
2020-05-07 09:54:02 +00:00
|
|
|
sendAnalytics(createE2EEEvent(`enabled.${String(newValue)}`));
|
|
|
|
this.props.dispatch(toggleE2EE(newValue));
|
2020-04-16 11:26:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated props for this component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
2022-10-20 09:11:27 +00:00
|
|
|
* @returns {IProps}
|
2020-04-16 11:26:44 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
function mapStateToProps(state: IReduxState) {
|
2021-09-21 11:00:23 +00:00
|
|
|
const { enabled: e2eeEnabled, maxMode } = state['features/e2ee'];
|
2021-09-09 08:10:09 +00:00
|
|
|
const { e2eeLabels } = state['features/base/config'];
|
2020-04-16 11:26:44 +00:00
|
|
|
|
2022-09-08 09:52:36 +00:00
|
|
|
let descriptionResource: string | undefined = '';
|
2021-09-21 11:00:23 +00:00
|
|
|
|
|
|
|
if (e2eeLabels) {
|
|
|
|
// When e2eeLabels are present, the descriptionResouse is ignored.
|
|
|
|
descriptionResource = undefined;
|
|
|
|
} else if (maxMode === MAX_MODE.THRESHOLD_EXCEEDED) {
|
|
|
|
descriptionResource = 'dialog.e2eeDisabledDueToMaxModeDescription';
|
|
|
|
} else if (maxMode === MAX_MODE.ENABLED) {
|
|
|
|
descriptionResource = e2eeEnabled
|
|
|
|
? 'dialog.e2eeWillDisableDueToMaxModeDescription' : 'dialog.e2eeDisabledDueToMaxModeDescription';
|
|
|
|
} else {
|
|
|
|
descriptionResource = 'dialog.e2eeDescription';
|
|
|
|
}
|
|
|
|
|
2020-04-16 11:26:44 +00:00
|
|
|
return {
|
2021-09-21 11:00:23 +00:00
|
|
|
_descriptionResource: descriptionResource,
|
2021-09-09 08:10:09 +00:00
|
|
|
_e2eeLabels: e2eeLabels,
|
2021-09-21 11:00:23 +00:00
|
|
|
_enabled: maxMode === MAX_MODE.DISABLED || e2eeEnabled,
|
|
|
|
_toggled: e2eeEnabled,
|
2021-08-18 13:21:23 +00:00
|
|
|
_everyoneSupportE2EE: doesEveryoneSupportE2EE(state)
|
2020-04-16 11:26:44 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-17 10:53:46 +00:00
|
|
|
export default translate(connect(mapStateToProps)(E2EESection));
|