2020-04-16 11:26:44 +00:00
|
|
|
/* @flow */
|
|
|
|
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
|
|
|
import { createE2EEEvent, sendAnalytics } from '../../analytics';
|
2020-06-25 13:44:17 +00:00
|
|
|
import { translate } from '../../base/i18n';
|
2020-04-20 15:04:11 +00:00
|
|
|
import { getParticipants } from '../../base/participants';
|
2020-05-07 09:54:02 +00:00
|
|
|
import { Switch } from '../../base/react';
|
2020-04-16 11:26:44 +00:00
|
|
|
import { connect } from '../../base/redux';
|
2020-05-07 09:54:02 +00:00
|
|
|
import { toggleE2EE } from '../actions';
|
2020-04-16 11:26:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
2020-04-20 15:04:11 +00:00
|
|
|
/**
|
2020-05-07 09:54:02 +00:00
|
|
|
* Whether E2EE is currently enabled or not.
|
2020-04-20 15:04:11 +00:00
|
|
|
*/
|
2020-05-07 09:54:02 +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
|
|
|
*/
|
2020-05-07 09:54:02 +00:00
|
|
|
_everyoneSupportsE2EE: boolean,
|
2020-04-16 11:26:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The redux {@code dispatch} function.
|
|
|
|
*/
|
|
|
|
dispatch: Dispatch<any>,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
|
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
|
|
|
*/
|
2020-05-07 09:54:02 +00:00
|
|
|
enabled: boolean,
|
2020-06-17 10:53:46 +00:00
|
|
|
|
2020-06-25 13:44:17 +00:00
|
|
|
/**
|
|
|
|
* True if the section description should be expanded, false otherwise.
|
|
|
|
*/
|
2020-05-07 09:54:02 +00:00
|
|
|
expand: boolean
|
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.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
2020-06-17 10:53:46 +00:00
|
|
|
class E2EESection extends Component<Props, State> {
|
2020-05-07 09:54:02 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#getDerivedStateFromProps()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
static getDerivedStateFromProps(props: Props, state: Object) {
|
|
|
|
if (props._enabled !== state.enabled) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
enabled: props._enabled
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2020-05-07 09:54:02 +00:00
|
|
|
enabled: false,
|
|
|
|
expand: false
|
2020-04-16 11:26:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once for every instance.
|
2020-06-25 13:44:17 +00:00
|
|
|
this._onExpand = this._onExpand.bind(this);
|
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() {
|
2020-04-20 15:04:11 +00:00
|
|
|
const { _everyoneSupportsE2EE, t } = this.props;
|
2020-05-07 09:54:02 +00:00
|
|
|
const { enabled, expand } = this.state;
|
2020-06-25 13:44:17 +00:00
|
|
|
const description = t('dialog.e2eeDescription');
|
2020-04-16 11:26:44 +00:00
|
|
|
|
|
|
|
return (
|
2020-06-17 10:53:46 +00:00
|
|
|
<div id = 'e2ee-section'>
|
|
|
|
<p className = 'description'>
|
2020-06-25 13:44:17 +00:00
|
|
|
{ expand && description }
|
|
|
|
{ !expand && description.substring(0, 100) }
|
|
|
|
{ !expand && <span
|
|
|
|
className = 'read-more'
|
|
|
|
onClick = { this._onExpand }>
|
|
|
|
... { t('dialog.readMore') }
|
|
|
|
</span> }
|
2020-06-17 10:53:46 +00:00
|
|
|
</p>
|
2020-04-20 15:04:11 +00:00
|
|
|
{
|
|
|
|
!_everyoneSupportsE2EE
|
2020-06-17 10:53:46 +00:00
|
|
|
&& <span className = 'warning'>
|
|
|
|
{ t('dialog.e2eeWarning') }
|
|
|
|
</span>
|
2020-04-20 15:04:11 +00:00
|
|
|
}
|
2020-05-07 09:54:02 +00:00
|
|
|
<div className = 'control-row'>
|
2020-06-17 10:53:46 +00:00
|
|
|
<label>
|
2020-05-07 09:54:02 +00:00
|
|
|
{ t('dialog.e2eeLabel') }
|
2020-06-17 10:53:46 +00:00
|
|
|
</label>
|
2020-05-07 09:54:02 +00:00
|
|
|
<Switch
|
|
|
|
onValueChange = { this._onToggle }
|
|
|
|
value = { enabled } />
|
2020-06-17 10:53:46 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2020-04-16 11:26:44 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 13:44:17 +00:00
|
|
|
_onExpand: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to be invoked when the description is expanded.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onExpand() {
|
|
|
|
this.setState({
|
|
|
|
expand: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-07 09:54:02 +00:00
|
|
|
_onToggle: () => void;
|
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() {
|
|
|
|
const newValue = !this.state.enabled;
|
2020-04-16 11:26:44 +00:00
|
|
|
|
2020-06-17 10:53:46 +00:00
|
|
|
this.setState({
|
2020-05-07 09:54:02 +00:00
|
|
|
enabled: 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
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
|
|
|
function mapStateToProps(state) {
|
2020-05-07 09:54:02 +00:00
|
|
|
const { enabled } = state['features/e2ee'];
|
2020-04-20 15:04:11 +00:00
|
|
|
const participants = getParticipants(state).filter(p => !p.local);
|
2020-04-16 11:26:44 +00:00
|
|
|
|
|
|
|
return {
|
2020-05-07 09:54:02 +00:00
|
|
|
_enabled: enabled,
|
|
|
|
_everyoneSupportsE2EE: participants.every(p => Boolean(p.e2eeSupported))
|
2020-04-16 11:26:44 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-17 10:53:46 +00:00
|
|
|
export default translate(connect(mapStateToProps)(E2EESection));
|