2018-02-26 16:14:46 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React from 'react';
|
2020-04-06 15:21:50 +00:00
|
|
|
import { Alert, NativeModules, ScrollView, Switch, Text, TextInput } from 'react-native';
|
2018-02-26 16:14:46 +00:00
|
|
|
|
|
|
|
import { translate } from '../../../base/i18n';
|
2020-04-06 15:21:50 +00:00
|
|
|
import { JitsiModal } from '../../../base/modal';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../../base/redux';
|
2018-02-26 16:14:46 +00:00
|
|
|
|
2020-04-06 15:21:50 +00:00
|
|
|
import { SETTINGS_VIEW_ID } from '../../constants';
|
|
|
|
import { normalizeUserInputURL } from '../../functions';
|
|
|
|
|
2018-02-26 16:14:46 +00:00
|
|
|
import {
|
|
|
|
AbstractSettingsView,
|
2019-03-05 17:41:39 +00:00
|
|
|
_mapStateToProps as _abstractMapStateToProps,
|
2020-04-06 15:21:50 +00:00
|
|
|
type Props
|
2018-02-26 16:14:46 +00:00
|
|
|
} from '../AbstractSettingsView';
|
2020-04-06 15:21:50 +00:00
|
|
|
|
2018-02-26 16:14:46 +00:00
|
|
|
import FormRow from './FormRow';
|
|
|
|
import FormSectionHeader from './FormSectionHeader';
|
|
|
|
|
2019-04-02 08:03:01 +00:00
|
|
|
/**
|
|
|
|
* Application information module.
|
|
|
|
*/
|
|
|
|
const { AppInfo } = NativeModules;
|
|
|
|
|
2019-10-18 14:30:59 +00:00
|
|
|
type State = {
|
|
|
|
|
2020-03-25 10:10:13 +00:00
|
|
|
/**
|
|
|
|
* State variable for the disable call integration switch.
|
|
|
|
*/
|
|
|
|
disableCallIntegration: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* State variable for the disable p2p switch.
|
|
|
|
*/
|
|
|
|
disableP2P: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* State variable for the display name field.
|
|
|
|
*/
|
|
|
|
displayName: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* State variable for the email field.
|
|
|
|
*/
|
|
|
|
email: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* State variable for the server URL field.
|
|
|
|
*/
|
|
|
|
serverURL: string,
|
|
|
|
|
2019-10-18 14:30:59 +00:00
|
|
|
/**
|
|
|
|
* Whether to show advanced settings or not.
|
|
|
|
*/
|
2020-03-25 10:10:13 +00:00
|
|
|
showAdvanced: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* State variable for the start with audio muted switch.
|
|
|
|
*/
|
|
|
|
startWithAudioMuted: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* State variable for the start with video muted switch.
|
|
|
|
*/
|
|
|
|
startWithVideoMuted: boolean,
|
2019-10-18 14:30:59 +00:00
|
|
|
}
|
|
|
|
|
2018-02-26 16:14:46 +00:00
|
|
|
/**
|
|
|
|
* The native container rendering the app settings page.
|
|
|
|
*
|
|
|
|
* @extends AbstractSettingsView
|
|
|
|
*/
|
2019-10-18 14:30:59 +00:00
|
|
|
class SettingsView extends AbstractSettingsView<Props, State> {
|
2018-02-26 16:14:46 +00:00
|
|
|
_urlField: Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new {@code SettingsView} instance.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2020-03-25 10:10:13 +00:00
|
|
|
const {
|
|
|
|
disableCallIntegration,
|
|
|
|
disableP2P,
|
|
|
|
displayName,
|
|
|
|
email,
|
|
|
|
serverURL,
|
|
|
|
startWithAudioMuted,
|
|
|
|
startWithVideoMuted
|
|
|
|
} = props._settings || {};
|
2018-02-26 16:14:46 +00:00
|
|
|
|
2019-10-18 14:30:59 +00:00
|
|
|
this.state = {
|
2020-03-25 10:10:13 +00:00
|
|
|
disableCallIntegration,
|
|
|
|
disableP2P,
|
|
|
|
displayName,
|
|
|
|
email,
|
|
|
|
serverURL,
|
|
|
|
showAdvanced: false,
|
|
|
|
startWithAudioMuted,
|
|
|
|
startWithVideoMuted
|
2019-10-18 14:30:59 +00:00
|
|
|
};
|
|
|
|
|
2018-02-26 16:14:46 +00:00
|
|
|
// Bind event handlers so they are only bound once per instance.
|
|
|
|
this._onBlurServerURL = this._onBlurServerURL.bind(this);
|
2020-04-06 15:21:50 +00:00
|
|
|
this._onClose = this._onClose.bind(this);
|
2019-10-18 14:30:59 +00:00
|
|
|
this._onDisableCallIntegration = this._onDisableCallIntegration.bind(this);
|
|
|
|
this._onDisableP2P = this._onDisableP2P.bind(this);
|
|
|
|
this._onShowAdvanced = this._onShowAdvanced.bind(this);
|
2018-02-26 16:14:46 +00:00
|
|
|
this._setURLFieldReference = this._setURLFieldReference.bind(this);
|
|
|
|
this._showURLAlert = this._showURLAlert.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}, renders the settings page.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2020-04-06 15:21:50 +00:00
|
|
|
const { displayName, email, serverURL, startWithAudioMuted, startWithVideoMuted } = this.state;
|
|
|
|
|
2018-02-26 16:14:46 +00:00
|
|
|
return (
|
2020-04-06 15:21:50 +00:00
|
|
|
<JitsiModal
|
|
|
|
headerProps = {{
|
|
|
|
headerLabelKey: 'settingsView.header'
|
|
|
|
}}
|
|
|
|
modalId = { SETTINGS_VIEW_ID }
|
|
|
|
onClose = { this._onClose }>
|
|
|
|
<ScrollView>
|
|
|
|
<FormSectionHeader
|
|
|
|
label = 'settingsView.profileSection' />
|
|
|
|
<FormRow
|
|
|
|
fieldSeparator = { true }
|
|
|
|
label = 'settingsView.displayName'
|
|
|
|
layout = 'column'>
|
|
|
|
<TextInput
|
|
|
|
autoCorrect = { false }
|
|
|
|
onChangeText = { this._onChangeDisplayName }
|
|
|
|
placeholder = 'John Doe'
|
|
|
|
value = { displayName } />
|
|
|
|
</FormRow>
|
|
|
|
<FormRow
|
|
|
|
label = 'settingsView.email'
|
|
|
|
layout = 'column'>
|
|
|
|
<TextInput
|
|
|
|
autoCapitalize = 'none'
|
|
|
|
autoCorrect = { false }
|
|
|
|
keyboardType = { 'email-address' }
|
|
|
|
onChangeText = { this._onChangeEmail }
|
|
|
|
placeholder = 'email@example.com'
|
|
|
|
value = { email } />
|
|
|
|
</FormRow>
|
|
|
|
<FormSectionHeader
|
|
|
|
label = 'settingsView.conferenceSection' />
|
|
|
|
<FormRow
|
|
|
|
fieldSeparator = { true }
|
|
|
|
label = 'settingsView.serverURL'
|
|
|
|
layout = 'column'>
|
|
|
|
<TextInput
|
|
|
|
autoCapitalize = 'none'
|
|
|
|
autoCorrect = { false }
|
|
|
|
onBlur = { this._onBlurServerURL }
|
|
|
|
onChangeText = { this._onChangeServerURL }
|
|
|
|
placeholder = { this.props._serverURL }
|
|
|
|
value = { serverURL } />
|
|
|
|
</FormRow>
|
|
|
|
<FormRow
|
|
|
|
fieldSeparator = { true }
|
|
|
|
label = 'settingsView.startWithAudioMuted'>
|
|
|
|
<Switch
|
|
|
|
onValueChange = { this._onStartAudioMutedChange }
|
|
|
|
value = { startWithAudioMuted } />
|
|
|
|
</FormRow>
|
|
|
|
<FormRow label = 'settingsView.startWithVideoMuted'>
|
|
|
|
<Switch
|
|
|
|
onValueChange = { this._onStartVideoMutedChange }
|
|
|
|
value = { startWithVideoMuted } />
|
|
|
|
</FormRow>
|
|
|
|
<FormSectionHeader
|
|
|
|
label = 'settingsView.buildInfoSection' />
|
|
|
|
<FormRow
|
|
|
|
label = 'settingsView.version'>
|
|
|
|
<Text>
|
|
|
|
{ `${AppInfo.version} build ${AppInfo.buildNumber}` }
|
|
|
|
</Text>
|
|
|
|
</FormRow>
|
|
|
|
<FormSectionHeader
|
|
|
|
label = 'settingsView.advanced' />
|
|
|
|
{ this._renderAdvancedSettings() }
|
|
|
|
</ScrollView>
|
|
|
|
</JitsiModal>
|
2018-02-26 16:14:46 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onBlurServerURL: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler the server URL lose focus event. Here we validate the server URL
|
|
|
|
* and update it to the normalized version, or show an error if incorrect.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onBlurServerURL() {
|
|
|
|
this._processServerURL(false /* hideOnSuccess */);
|
|
|
|
}
|
|
|
|
|
2020-03-25 10:10:13 +00:00
|
|
|
/**
|
|
|
|
* Callback to update the display name.
|
|
|
|
*
|
|
|
|
* @param {string} displayName - The new value to set.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onChangeDisplayName(displayName) {
|
|
|
|
super._onChangeDisplayName(displayName);
|
|
|
|
this.setState({
|
|
|
|
displayName
|
|
|
|
});
|
|
|
|
}
|
2018-02-26 16:14:46 +00:00
|
|
|
|
2020-03-25 10:10:13 +00:00
|
|
|
/**
|
|
|
|
* Callback to update the email.
|
|
|
|
*
|
|
|
|
* @param {string} email - The new value to set.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onChangeEmail(email) {
|
|
|
|
super._onChangeEmail(email);
|
|
|
|
this.setState({
|
|
|
|
email
|
|
|
|
});
|
|
|
|
}
|
2018-02-26 16:14:46 +00:00
|
|
|
|
2020-03-25 10:10:13 +00:00
|
|
|
/**
|
|
|
|
* Callback to update the server URL.
|
|
|
|
*
|
|
|
|
* @param {string} serverURL - The new value to set.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onChangeServerURL(serverURL) {
|
|
|
|
super._onChangeServerURL(serverURL);
|
|
|
|
this.setState({
|
|
|
|
serverURL
|
|
|
|
});
|
|
|
|
}
|
2018-02-26 16:14:46 +00:00
|
|
|
|
2019-10-18 14:30:59 +00:00
|
|
|
_onDisableCallIntegration: (boolean) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the disable call integration change event.
|
|
|
|
*
|
2020-03-25 10:10:13 +00:00
|
|
|
* @param {boolean} disableCallIntegration - The new value
|
2019-10-18 14:30:59 +00:00
|
|
|
* option.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2020-03-25 10:10:13 +00:00
|
|
|
_onDisableCallIntegration(disableCallIntegration) {
|
2019-10-18 14:30:59 +00:00
|
|
|
this._updateSettings({
|
2020-03-25 10:10:13 +00:00
|
|
|
disableCallIntegration
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
disableCallIntegration
|
2019-10-18 14:30:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_onDisableP2P: (boolean) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the disable P2P change event.
|
|
|
|
*
|
2020-03-25 10:10:13 +00:00
|
|
|
* @param {boolean} disableP2P - The new value
|
2019-10-18 14:30:59 +00:00
|
|
|
* option.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2020-03-25 10:10:13 +00:00
|
|
|
_onDisableP2P(disableP2P) {
|
2019-10-18 14:30:59 +00:00
|
|
|
this._updateSettings({
|
2020-03-25 10:10:13 +00:00
|
|
|
disableP2P
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
disableP2P
|
2019-10-18 14:30:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-06 15:21:50 +00:00
|
|
|
_onClose: () => void;
|
2018-02-26 16:14:46 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-06 15:21:50 +00:00
|
|
|
* Callback to be invoked on closing the modal. Also invokes normalizeUserInputURL to validate
|
2018-02-26 16:14:46 +00:00
|
|
|
* the URL entered by the user.
|
|
|
|
*
|
2020-04-06 15:21:50 +00:00
|
|
|
* @returns {boolean} - True if the modal can be closed.
|
2018-02-26 16:14:46 +00:00
|
|
|
*/
|
2020-04-06 15:21:50 +00:00
|
|
|
_onClose() {
|
2019-10-18 14:30:59 +00:00
|
|
|
this.setState({ showAdvanced: false });
|
2020-04-06 15:21:50 +00:00
|
|
|
|
|
|
|
return this._processServerURL(true /* hideOnSuccess */);
|
2018-02-26 16:14:46 +00:00
|
|
|
}
|
|
|
|
|
2019-10-18 14:30:59 +00:00
|
|
|
_onShowAdvanced: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the advanced settings button.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onShowAdvanced() {
|
|
|
|
this.setState({ showAdvanced: !this.state.showAdvanced });
|
|
|
|
}
|
|
|
|
|
2020-03-25 10:10:13 +00:00
|
|
|
/**
|
|
|
|
* Callback to update the start with audio muted value.
|
|
|
|
*
|
|
|
|
* @param {boolean} startWithAudioMuted - The new value to set.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onStartAudioMutedChange(startWithAudioMuted) {
|
|
|
|
super._onStartAudioMutedChange(startWithAudioMuted);
|
|
|
|
this.setState({
|
|
|
|
startWithAudioMuted
|
|
|
|
});
|
|
|
|
}
|
2018-02-26 16:14:46 +00:00
|
|
|
|
2020-03-25 10:10:13 +00:00
|
|
|
/**
|
|
|
|
* Callback to update the start with video muted value.
|
|
|
|
*
|
|
|
|
* @param {boolean} startWithVideoMuted - The new value to set.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onStartVideoMutedChange(startWithVideoMuted) {
|
|
|
|
super._onStartVideoMutedChange(startWithVideoMuted);
|
|
|
|
this.setState({
|
|
|
|
startWithVideoMuted
|
|
|
|
});
|
|
|
|
}
|
2018-02-26 16:14:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes the server URL. It normalizes it and an error alert is
|
|
|
|
* displayed in case it's incorrect.
|
|
|
|
*
|
|
|
|
* @param {boolean} hideOnSuccess - True if the dialog should be hidden if
|
|
|
|
* normalization / validation succeeds, false otherwise.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_processServerURL(hideOnSuccess: boolean) {
|
2018-04-12 19:58:20 +00:00
|
|
|
const { serverURL } = this.props._settings;
|
2018-02-26 16:14:46 +00:00
|
|
|
const normalizedURL = normalizeUserInputURL(serverURL);
|
|
|
|
|
|
|
|
if (normalizedURL === null) {
|
|
|
|
this._showURLAlert();
|
2020-04-06 15:21:50 +00:00
|
|
|
|
|
|
|
return false;
|
2018-02-26 16:14:46 +00:00
|
|
|
}
|
2020-04-06 15:21:50 +00:00
|
|
|
|
|
|
|
this._onChangeServerURL(normalizedURL);
|
|
|
|
|
|
|
|
return hideOnSuccess;
|
2018-02-26 16:14:46 +00:00
|
|
|
}
|
|
|
|
|
2019-10-18 14:30:59 +00:00
|
|
|
/**
|
|
|
|
* Renders the advanced settings options.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {React$Element}
|
|
|
|
*/
|
|
|
|
_renderAdvancedSettings() {
|
2020-03-25 10:10:13 +00:00
|
|
|
const { disableCallIntegration, disableP2P, showAdvanced } = this.state;
|
2019-10-18 14:30:59 +00:00
|
|
|
|
|
|
|
if (!showAdvanced) {
|
|
|
|
return (
|
|
|
|
<FormRow
|
|
|
|
fieldSeparator = { true }
|
|
|
|
label = 'settingsView.showAdvanced'>
|
|
|
|
<Switch
|
|
|
|
onValueChange = { this._onShowAdvanced }
|
|
|
|
value = { showAdvanced } />
|
|
|
|
</FormRow>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<FormRow
|
|
|
|
fieldSeparator = { true }
|
|
|
|
label = 'settingsView.disableCallIntegration'>
|
|
|
|
<Switch
|
|
|
|
onValueChange = { this._onDisableCallIntegration }
|
2020-03-25 10:10:13 +00:00
|
|
|
value = { disableCallIntegration } />
|
2019-10-18 14:30:59 +00:00
|
|
|
</FormRow>
|
|
|
|
<FormRow
|
|
|
|
fieldSeparator = { true }
|
|
|
|
label = 'settingsView.disableP2P'>
|
|
|
|
<Switch
|
|
|
|
onValueChange = { this._onDisableP2P }
|
2020-03-25 10:10:13 +00:00
|
|
|
value = { disableP2P } />
|
2019-10-18 14:30:59 +00:00
|
|
|
</FormRow>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-26 16:14:46 +00:00
|
|
|
_setURLFieldReference: (React$ElementRef<*> | null) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores a reference to the URL field for later use.
|
|
|
|
*
|
|
|
|
* @param {Object} component - The field component.
|
|
|
|
* @protected
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_setURLFieldReference(component) {
|
|
|
|
this._urlField = component;
|
|
|
|
}
|
|
|
|
|
|
|
|
_showURLAlert: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows an alert telling the user that the URL he/she entered was invalid.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_showURLAlert() {
|
|
|
|
const { t } = this.props;
|
|
|
|
|
|
|
|
Alert.alert(
|
|
|
|
t('settingsView.alertTitle'),
|
|
|
|
t('settingsView.alertURLText'),
|
|
|
|
[
|
|
|
|
{
|
|
|
|
onPress: () => this._urlField.focus(),
|
|
|
|
text: t('settingsView.alertOk')
|
|
|
|
}
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2019-10-18 14:30:59 +00:00
|
|
|
|
|
|
|
_updateSettings: (Object) => void;
|
2018-02-26 16:14:46 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 17:41:39 +00:00
|
|
|
/**
|
|
|
|
* Maps part of the Redux state to the props of this component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
2020-04-06 15:21:50 +00:00
|
|
|
* @returns {Props}
|
2019-03-05 17:41:39 +00:00
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
|
|
|
return {
|
2020-04-06 15:21:50 +00:00
|
|
|
..._abstractMapStateToProps(state)
|
2019-03-05 17:41:39 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-02-26 16:14:46 +00:00
|
|
|
export default translate(connect(_mapStateToProps)(SettingsView));
|