You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /* eslint-disable lines-around-comment */
  2. import { Link } from '@react-navigation/native';
  3. import _ from 'lodash';
  4. import React, { Component } from 'react';
  5. import { WithTranslation } from 'react-i18next';
  6. import {
  7. Alert,
  8. NativeModules,
  9. Platform,
  10. ScrollView,
  11. Text,
  12. View
  13. } from 'react-native';
  14. import {
  15. Divider,
  16. TextInput
  17. } from 'react-native-paper';
  18. // @ts-ignore
  19. import { getDefaultURL } from '../../../app/functions';
  20. import { IState } from '../../../app/types';
  21. // @ts-ignore
  22. import { Avatar } from '../../../base/avatar';
  23. import { translate } from '../../../base/i18n/functions';
  24. // @ts-ignore
  25. import JitsiScreen from '../../../base/modal/components/JitsiScreen';
  26. import { getLocalParticipant } from '../../../base/participants/functions';
  27. import { connect } from '../../../base/redux/functions';
  28. // @ts-ignore
  29. import { updateSettings } from '../../../base/settings';
  30. import BaseThemeNative from '../../../base/ui/components/BaseTheme.native';
  31. import Switch from '../../../base/ui/components/native/Switch';
  32. // @ts-ignore
  33. import { screen } from '../../../mobile/navigation/routes';
  34. // @ts-ignore
  35. import { AVATAR_SIZE } from '../../../welcome/components/styles';
  36. // @ts-ignore
  37. import { isServerURLChangeEnabled, normalizeUserInputURL } from '../../functions';
  38. // @ts-ignore
  39. import FormRow from './FormRow';
  40. // @ts-ignore
  41. import FormSectionAccordion from './FormSectionAccordion';
  42. // @ts-ignore
  43. import styles, { PLACEHOLDER_COLOR, PLACEHOLDER_TEXT_COLOR } from './styles';
  44. /**
  45. * Application information module.
  46. */
  47. const { AppInfo } = NativeModules;
  48. interface State {
  49. /**
  50. * State variable for the disable call integration switch.
  51. */
  52. disableCallIntegration: boolean;
  53. /**
  54. * State variable for the disable crash reporting switch.
  55. */
  56. disableCrashReporting: boolean;
  57. /**
  58. * State variable for the disable p2p switch.
  59. */
  60. disableP2P: boolean;
  61. /**
  62. * Whether the self view is disabled or not.
  63. */
  64. disableSelfView: boolean;
  65. /**
  66. * State variable for the display name field.
  67. */
  68. displayName: string;
  69. /**
  70. * State variable for the email field.
  71. */
  72. email: string;
  73. /**
  74. * State variable for the server URL field.
  75. */
  76. serverURL: string;
  77. /**
  78. * State variable for start car mode.
  79. */
  80. startCarMode: boolean;
  81. /**
  82. * State variable for the start with audio muted switch.
  83. */
  84. startWithAudioMuted: boolean;
  85. /**
  86. * State variable for the start with video muted switch.
  87. */
  88. startWithVideoMuted: boolean;
  89. }
  90. /**
  91. * The type of the React {@code Component} props of
  92. * {@link SettingsView}.
  93. */
  94. interface Props extends WithTranslation {
  95. /**
  96. * The ID of the local participant.
  97. */
  98. _localParticipantId: string;
  99. /**
  100. * The default URL for when there is no custom URL set in the settings.
  101. *
  102. * @protected
  103. */
  104. _serverURL: string;
  105. /**
  106. * Flag indicating if URL can be changed by user.
  107. *
  108. * @protected
  109. */
  110. _serverURLChangeEnabled: boolean;
  111. /**
  112. * The current settings object.
  113. */
  114. _settings: {
  115. disableCallIntegration: boolean;
  116. disableCrashReporting: boolean;
  117. disableP2P: boolean;
  118. disableSelfView: boolean;
  119. displayName: string;
  120. email: string;
  121. serverURL: string;
  122. startCarMode: boolean;
  123. startWithAudioMuted: boolean;
  124. startWithVideoMuted: boolean;
  125. };
  126. /**
  127. * Whether {@link SettingsView} is visible.
  128. *
  129. * @protected
  130. */
  131. _visible: boolean;
  132. /**
  133. * Redux store dispatch function.
  134. */
  135. dispatch: Function;
  136. /**
  137. * Default prop for navigating between screen components(React Navigation).
  138. */
  139. navigation: Object;
  140. }
  141. /**
  142. * The native container rendering the app settings page.
  143. */
  144. class SettingsView extends Component<Props, State> {
  145. _urlField: Object;
  146. /**
  147. *
  148. * Initializes a new {@code SettingsView} instance.
  149. *
  150. * @inheritdoc
  151. */
  152. constructor(props: Props) {
  153. super(props);
  154. const {
  155. disableCallIntegration,
  156. disableCrashReporting,
  157. disableP2P,
  158. disableSelfView,
  159. displayName,
  160. email,
  161. serverURL,
  162. startCarMode,
  163. startWithAudioMuted,
  164. startWithVideoMuted
  165. } = props._settings || {};
  166. this.state = {
  167. disableCallIntegration,
  168. disableCrashReporting,
  169. disableP2P,
  170. disableSelfView,
  171. displayName,
  172. email,
  173. serverURL,
  174. startCarMode,
  175. startWithAudioMuted,
  176. startWithVideoMuted
  177. };
  178. // Bind event handlers so they are only bound once per instance.
  179. this._onBlurServerURL = this._onBlurServerURL.bind(this);
  180. this._onChangeDisplayName = this._onChangeDisplayName.bind(this);
  181. this._onChangeEmail = this._onChangeEmail.bind(this);
  182. this._onChangeServerURL = this._onChangeServerURL.bind(this);
  183. this._onClose = this._onClose.bind(this);
  184. this._onDisableCallIntegration = this._onDisableCallIntegration.bind(this);
  185. this._onDisableCrashReporting = this._onDisableCrashReporting.bind(this);
  186. this._onDisableP2P = this._onDisableP2P.bind(this);
  187. this._onDisableSelfView = this._onDisableSelfView.bind(this);
  188. this._onStartAudioMutedChange
  189. = this._onStartAudioMutedChange.bind(this);
  190. this._onStartCarmodeInLowBandwidthMode
  191. = this._onStartCarmodeInLowBandwidthMode.bind(this);
  192. this._onStartVideoMutedChange
  193. = this._onStartVideoMutedChange.bind(this);
  194. this._setURLFieldReference = this._setURLFieldReference.bind(this);
  195. this._showURLAlert = this._showURLAlert.bind(this);
  196. }
  197. /**
  198. * Updates and syncs settings.
  199. *
  200. * @inheritdoc
  201. * @returns {void}
  202. */
  203. componentDidUpdate(prevProps: Props) {
  204. const { _settings } = this.props;
  205. if (!_.isEqual(prevProps._settings, _settings)) {
  206. // @ts-ignore
  207. // eslint-disable-next-line react/no-did-update-set-state
  208. this.setState(_settings);
  209. }
  210. }
  211. /**
  212. * Implements React's {@link Component#render()}, renders the settings page.
  213. *
  214. * @inheritdoc
  215. * @returns {ReactElement}
  216. */
  217. render() {
  218. const {
  219. disableCallIntegration,
  220. disableCrashReporting,
  221. disableP2P,
  222. disableSelfView,
  223. displayName,
  224. email,
  225. serverURL,
  226. startCarMode,
  227. startWithAudioMuted,
  228. startWithVideoMuted
  229. } = this.state;
  230. const { t } = this.props;
  231. const textInputTheme = {
  232. colors: {
  233. background: BaseThemeNative.palette.ui01,
  234. placeholder: BaseThemeNative.palette.text01,
  235. primary: PLACEHOLDER_COLOR,
  236. underlineColor: 'transparent',
  237. text: BaseThemeNative.palette.text01
  238. }
  239. };
  240. return (
  241. <JitsiScreen
  242. safeAreaInsets = { [ 'bottom', 'left', 'right' ] }
  243. style = { styles.settingsViewContainer }>
  244. <ScrollView>
  245. <View style = { styles.avatarContainer }>
  246. <Avatar
  247. participantId = { this.props._localParticipantId }
  248. size = { AVATAR_SIZE } />
  249. </View>
  250. <FormSectionAccordion
  251. label = 'settingsView.profileSection'>
  252. <TextInput
  253. autoCorrect = { false }
  254. label = { t('settingsView.displayName') }
  255. mode = 'outlined'
  256. onChangeText = { this._onChangeDisplayName }
  257. placeholder = { t('settingsView.displayNamePlaceholderText') }
  258. placeholderTextColor = { PLACEHOLDER_TEXT_COLOR }
  259. spellCheck = { false }
  260. style = { styles.textInputContainer }
  261. textContentType = { 'name' } // iOS only
  262. theme = { textInputTheme }
  263. value = { displayName } />
  264. <Divider style = { styles.fieldSeparator } />
  265. <TextInput
  266. autoCapitalize = 'none'
  267. autoCorrect = { false }
  268. keyboardType = { 'email-address' }
  269. label = { t('settingsView.email') }
  270. mode = 'outlined'
  271. onChangeText = { this._onChangeEmail }
  272. placeholder = 'email@example.com'
  273. placeholderTextColor = { PLACEHOLDER_TEXT_COLOR }
  274. spellCheck = { false }
  275. style = { styles.textInputContainer }
  276. textContentType = { 'emailAddress' } // iOS only
  277. theme = { textInputTheme }
  278. value = { email } />
  279. </FormSectionAccordion>
  280. <FormSectionAccordion
  281. label = 'settingsView.conferenceSection'>
  282. <TextInput
  283. autoCapitalize = 'none'
  284. autoCorrect = { false }
  285. editable = { this.props._serverURLChangeEnabled }
  286. keyboardType = { 'url' }
  287. label = { t('settingsView.serverURL') }
  288. mode = 'outlined'
  289. onBlur = { this._onBlurServerURL }
  290. onChangeText = { this._onChangeServerURL }
  291. placeholder = { this.props._serverURL }
  292. placeholderTextColor = { PLACEHOLDER_TEXT_COLOR }
  293. spellCheck = { false }
  294. style = { styles.textInputContainer }
  295. textContentType = { 'URL' } // iOS only
  296. theme = { textInputTheme }
  297. value = { serverURL } />
  298. <Divider style = { styles.fieldSeparator } />
  299. <FormRow label = 'settingsView.startCarModeInLowBandwidthMode'>
  300. <Switch
  301. checked = { startCarMode }
  302. // @ts-ignore
  303. onChange = { this._onStartCarmodeInLowBandwidthMode } />
  304. </FormRow>
  305. <Divider style = { styles.fieldSeparator } />
  306. <FormRow
  307. label = 'settingsView.startWithAudioMuted'>
  308. <Switch
  309. checked = { startWithAudioMuted }
  310. // @ts-ignore
  311. onChange = { this._onStartAudioMutedChange } />
  312. </FormRow>
  313. <Divider style = { styles.fieldSeparator } />
  314. <FormRow label = 'settingsView.startWithVideoMuted'>
  315. <Switch
  316. checked = { startWithVideoMuted }
  317. // @ts-ignore
  318. onChange = { this._onStartVideoMutedChange } />
  319. </FormRow>
  320. <Divider style = { styles.fieldSeparator } />
  321. <FormRow label = 'videothumbnail.hideSelfView'>
  322. <Switch
  323. checked = { disableSelfView }
  324. // @ts-ignore
  325. onChange = { this._onDisableSelfView } />
  326. </FormRow>
  327. </FormSectionAccordion>
  328. <FormSectionAccordion
  329. label = 'settingsView.links'>
  330. <Link
  331. style = { styles.sectionLink }
  332. // @ts-ignore
  333. to = {{ screen: screen.settings.links.help }}>
  334. { t('settingsView.help') }
  335. </Link>
  336. <Divider style = { styles.fieldSeparator } />
  337. <Link
  338. style = { styles.sectionLink }
  339. // @ts-ignore
  340. to = {{ screen: screen.settings.links.terms }}>
  341. { t('settingsView.terms') }
  342. </Link>
  343. <Divider style = { styles.fieldSeparator } />
  344. <Link
  345. style = { styles.sectionLink }
  346. // @ts-ignore
  347. to = {{ screen: screen.settings.links.privacy }}>
  348. { t('settingsView.privacy') }
  349. </Link>
  350. </FormSectionAccordion>
  351. <FormSectionAccordion
  352. label = 'settingsView.buildInfoSection'>
  353. <FormRow
  354. label = 'settingsView.version'>
  355. <Text style = { styles.text }>
  356. {`${AppInfo.version} build ${AppInfo.buildNumber}`}
  357. </Text>
  358. </FormRow>
  359. </FormSectionAccordion>
  360. <FormSectionAccordion
  361. label = 'settingsView.advanced'>
  362. { Platform.OS === 'android' && (
  363. <>
  364. <FormRow
  365. label = 'settingsView.disableCallIntegration'>
  366. <Switch
  367. checked = { disableCallIntegration }
  368. // @ts-ignore
  369. onChange = { this._onDisableCallIntegration } />
  370. </FormRow>
  371. <Divider style = { styles.fieldSeparator } />
  372. </>
  373. )}
  374. <FormRow
  375. label = 'settingsView.disableP2P'>
  376. <Switch
  377. checked = { disableP2P }
  378. // @ts-ignore
  379. onChange = { this._onDisableP2P } />
  380. </FormRow>
  381. <Divider style = { styles.fieldSeparator } />
  382. {AppInfo.GOOGLE_SERVICES_ENABLED && (
  383. <FormRow
  384. fieldSeparator = { true }
  385. label = 'settingsView.disableCrashReporting'>
  386. <Switch
  387. checked = { disableCrashReporting }
  388. // @ts-ignore
  389. onChange = { this._onDisableCrashReporting } />
  390. </FormRow>
  391. )}
  392. </FormSectionAccordion>
  393. </ScrollView>
  394. </JitsiScreen>
  395. );
  396. }
  397. /**
  398. * Handler the server URL lose focus event. Here we validate the server URL
  399. * and update it to the normalized version, or show an error if incorrect.
  400. *
  401. * @private
  402. * @returns {void}
  403. */
  404. _onBlurServerURL() {
  405. this._processServerURL(false /* hideOnSuccess */);
  406. }
  407. /**
  408. * Handles the display name field value change.
  409. *
  410. * @param {string} displayName - The value typed in the name field.
  411. * @protected
  412. * @returns {void}
  413. */
  414. _onChangeDisplayName(displayName: string) {
  415. this.setState({
  416. displayName
  417. });
  418. this._updateSettings({
  419. displayName
  420. });
  421. }
  422. /**
  423. * Handles the email field value change.
  424. *
  425. * @param {string} email - The value typed in the email field.
  426. * @protected
  427. * @returns {void}
  428. */
  429. _onChangeEmail(email: string) {
  430. this.setState({
  431. email
  432. });
  433. this._updateSettings({
  434. email
  435. });
  436. }
  437. /**
  438. * Handles the server name field value change.
  439. *
  440. * @param {string} serverURL - The server URL typed in the server field.
  441. * @protected
  442. * @returns {void}
  443. */
  444. _onChangeServerURL(serverURL: string) {
  445. this.setState({
  446. serverURL
  447. });
  448. this._updateSettings({
  449. serverURL
  450. });
  451. }
  452. /**
  453. * Handles the disable call integration change event.
  454. *
  455. * @param {boolean} disableCallIntegration - The new value
  456. * option.
  457. * @private
  458. * @returns {void}
  459. */
  460. _onDisableCallIntegration(disableCallIntegration: boolean) {
  461. this.setState({
  462. disableCallIntegration
  463. });
  464. this._updateSettings({
  465. disableCallIntegration
  466. });
  467. }
  468. /**
  469. * Handles the disable P2P change event.
  470. *
  471. * @param {boolean} disableP2P - The new value
  472. * option.
  473. * @private
  474. * @returns {void}
  475. */
  476. _onDisableP2P(disableP2P: boolean) {
  477. this.setState({
  478. disableP2P
  479. });
  480. this._updateSettings({
  481. disableP2P
  482. });
  483. }
  484. /** .
  485. * Handles the disable self view change event.
  486. *
  487. * @param {boolean} disableSelfView - The new value.
  488. * @private
  489. * @returns {void}
  490. */
  491. _onDisableSelfView(disableSelfView: boolean) {
  492. this.setState({
  493. disableSelfView
  494. });
  495. this._updateSettings({
  496. disableSelfView
  497. });
  498. }
  499. /** .
  500. * Handles car mode in low bandwidth mode.
  501. *
  502. * @param {boolean} startCarMode - The new value.
  503. * @private
  504. * @returns {void}
  505. */
  506. _onStartCarmodeInLowBandwidthMode(startCarMode: boolean) {
  507. this.setState({
  508. startCarMode
  509. });
  510. this._updateSettings({
  511. startCarMode
  512. });
  513. }
  514. /**
  515. * Handles the disable crash reporting change event.
  516. *
  517. * @param {boolean} disableCrashReporting - The new value
  518. * option.
  519. * @private
  520. * @returns {void}
  521. */
  522. _onDisableCrashReporting(disableCrashReporting: boolean) {
  523. if (disableCrashReporting) {
  524. this._showCrashReportingDisableAlert();
  525. } else {
  526. this._disableCrashReporting(disableCrashReporting);
  527. }
  528. }
  529. /**
  530. * Callback to be invoked on closing the modal. Also invokes normalizeUserInputURL to validate
  531. * the URL entered by the user.
  532. *
  533. * @returns {boolean} - True if the modal can be closed.
  534. */
  535. _onClose() {
  536. return this._processServerURL(true /* hideOnSuccess */);
  537. }
  538. /**
  539. * Handles the start audio muted change event.
  540. *
  541. * @param {boolean} startWithAudioMuted - The new value for the start audio muted
  542. * option.
  543. * @protected
  544. * @returns {void}
  545. */
  546. _onStartAudioMutedChange(startWithAudioMuted: boolean) {
  547. this.setState({
  548. startWithAudioMuted
  549. });
  550. this._updateSettings({
  551. startWithAudioMuted
  552. });
  553. }
  554. /**
  555. * Handles the start video muted change event.
  556. *
  557. * @param {boolean} startWithVideoMuted - The new value for the start video muted
  558. * option.
  559. * @protected
  560. * @returns {void}
  561. */
  562. _onStartVideoMutedChange(startWithVideoMuted: boolean) {
  563. this.setState({
  564. startWithVideoMuted
  565. });
  566. this._updateSettings({
  567. startWithVideoMuted
  568. });
  569. }
  570. /**
  571. * Processes the server URL. It normalizes it and an error alert is
  572. * displayed in case it's incorrect.
  573. *
  574. * @param {boolean} hideOnSuccess - True if the dialog should be hidden if
  575. * normalization / validation succeeds, false otherwise.
  576. * @private
  577. * @returns {void}
  578. */
  579. _processServerURL(hideOnSuccess: boolean) {
  580. // @ts-ignore
  581. const { serverURL } = this.props._settings;
  582. const normalizedURL = normalizeUserInputURL(serverURL);
  583. if (normalizedURL === null) {
  584. this._showURLAlert();
  585. return false;
  586. }
  587. this._onChangeServerURL(normalizedURL);
  588. return hideOnSuccess;
  589. }
  590. /**
  591. * Stores a reference to the URL field for later use.
  592. *
  593. * @param {Object} component - The field component.
  594. * @protected
  595. * @returns {void}
  596. */
  597. _setURLFieldReference(component: object) {
  598. this._urlField = component;
  599. }
  600. /**
  601. * Shows an alert telling the user that the URL he/she entered was invalid.
  602. *
  603. * @returns {void}
  604. */
  605. _showURLAlert() {
  606. const { t } = this.props;
  607. Alert.alert(
  608. t('settingsView.alertTitle'),
  609. t('settingsView.alertURLText'),
  610. [
  611. {
  612. // @ts-ignore
  613. onPress: () => this._urlField.focus(),
  614. text: t('settingsView.alertOk')
  615. }
  616. ]
  617. );
  618. }
  619. /**
  620. * Shows an alert warning the user about disabling crash reporting.
  621. *
  622. * @returns {void}
  623. */
  624. _showCrashReportingDisableAlert() {
  625. const { t } = this.props;
  626. Alert.alert(
  627. t('settingsView.alertTitle'),
  628. t('settingsView.disableCrashReportingWarning'),
  629. [
  630. {
  631. onPress: () => this._disableCrashReporting(true),
  632. text: t('settingsView.alertOk')
  633. },
  634. {
  635. text: t('settingsView.alertCancel')
  636. }
  637. ]
  638. );
  639. }
  640. /**
  641. * Updates the settings and sets state for disableCrashReporting.
  642. *
  643. * @param {boolean} disableCrashReporting - Whether crash reporting is disabled or not.
  644. * @returns {void}
  645. */
  646. _disableCrashReporting(disableCrashReporting: boolean) {
  647. this.setState({
  648. disableCrashReporting
  649. });
  650. this._updateSettings({
  651. disableCrashReporting
  652. });
  653. }
  654. /**
  655. * Updates the persisted settings on any change.
  656. *
  657. * @param {Object} updateObject - The partial update object for the
  658. * settings.
  659. * @private
  660. * @returns {void}
  661. */
  662. _updateSettings(updateObject: Object) {
  663. const { dispatch } = this.props;
  664. dispatch(updateSettings(updateObject));
  665. }
  666. }
  667. /**
  668. * Maps part of the Redux state to the props of this component.
  669. *
  670. * @param {Object} state - The Redux state.
  671. * @returns {Props}
  672. */
  673. function _mapStateToProps(state: IState) {
  674. const localParticipant = getLocalParticipant(state);
  675. return {
  676. _localParticipantId: localParticipant?.id,
  677. _serverURL: getDefaultURL(state),
  678. _serverURLChangeEnabled: isServerURLChangeEnabled(state),
  679. _settings: state['features/base/settings'],
  680. _visible: state['features/settings'].visible
  681. };
  682. }
  683. export default translate(connect(_mapStateToProps)(SettingsView));