From 3bfab7718f9dbdd48aa5b67c37bfa11eccfc0086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Wed, 11 Jul 2018 10:57:07 +0200 Subject: [PATCH] [RN] Refactor getting the default URL Move it away from AbstractApp into an auxiliary function. In addition, introduce a new `getServerURL` function which gets the configured server URL and defaults to meet.jit.si as before. --- react/features/app/actions.js | 4 +-- react/features/app/components/AbstractApp.js | 29 ++----------------- react/features/app/functions.any.js | 28 ++++++++++++++++++ .../features/base/known-domains/middleware.js | 6 ++-- react/features/base/settings/constants.js | 6 ++++ react/features/base/settings/functions.js | 14 +++++++++ react/features/base/settings/index.js | 1 + .../components/RecentList.native.js | 4 +-- .../components/AbstractSettingsView.js | 3 +- 9 files changed, 60 insertions(+), 35 deletions(-) create mode 100644 react/features/base/settings/constants.js diff --git a/react/features/app/actions.js b/react/features/app/actions.js index 4e5736393..f7ca8b060 100644 --- a/react/features/app/actions.js +++ b/react/features/app/actions.js @@ -16,6 +16,7 @@ import { parseURIString, toURLString } from '../base/util'; import { setFatalError } from '../overlay'; import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes'; +import { getDefaultURL } from './functions'; const logger = require('jitsi-meet-logger').getLogger(__filename); @@ -116,8 +117,7 @@ function _appNavigateToOptionalLocation( // If the specified location (URI) does not identify a host, use the app's // default. if (!location || !location.host) { - const defaultLocation - = parseURIString(getState()['features/app'].app._getDefaultURL()); + const defaultLocation = parseURIString(getDefaultURL(getState)); if (location) { location.host = defaultLocation.host; diff --git a/react/features/app/components/AbstractApp.js b/react/features/app/components/AbstractApp.js index 289b21321..55e695ad5 100644 --- a/react/features/app/components/AbstractApp.js +++ b/react/features/app/components/AbstractApp.js @@ -20,15 +20,7 @@ import { toURLString } from '../../base/util'; import { OverlayContainer } from '../../overlay'; import { appNavigate, appWillMount, appWillUnmount } from '../actions'; - -/** - * The default URL to open if no other was specified to {@code AbstractApp} via - * props. - * - * FIXME: This is not at the best place here. This should be either in the - * base/settings feature or a default in base/config. - */ -const DEFAULT_URL = 'https://meet.jit.si'; +import { getDefaultURL } from '../functions'; /** * Base (abstract) class for main App component. @@ -322,24 +314,7 @@ export class AbstractApp extends Component { * mounts. */ _getDefaultURL() { - // If the execution environment provides a Location abstraction, then - // this App at already at that location but it must be made aware of the - // fact. - const windowLocation = this.getWindowLocation(); - - if (windowLocation) { - const href = windowLocation.toString(); - - if (href) { - return href; - } - } - - return ( - this.props.defaultURL - || this.state.store.getState()['features/base/settings'] - .serverURL - || DEFAULT_URL); + return getDefaultURL(this.state.store); } /** diff --git a/react/features/app/functions.any.js b/react/features/app/functions.any.js index 38fa6d14d..d1f03d3e6 100644 --- a/react/features/app/functions.any.js +++ b/react/features/app/functions.any.js @@ -1,6 +1,7 @@ // @flow import { toState } from '../base/redux'; +import { getServerURL } from '../base/settings'; /** * Gets the value of a specific React {@code Component} prop of the currently @@ -26,3 +27,30 @@ export function getAppProp(stateful: Function | Object, propName: string) { return undefined; } + +/** + * Retrieves the default URL for the app. This can either come from a prop to + * the root App component or be configured in the settings. + * + * @param {Function|Object} stateful - The redux store or {@code getState} + * function. + * @returns {string} - Default URL for the app. + */ +export function getDefaultURL(stateful: Function | Object) { + const state = toState(stateful); + const { app } = state['features/app']; + + // If the execution environment provides a Location abstraction (e.g. a Web + // browser), then we'll presume it's the one and only base URL it can be on. + const windowLocation = app.getWindowLocation(); + + if (windowLocation) { + const href = windowLocation.toString(); + + if (href) { + return href; + } + } + + return getAppProp(state, 'defaultURL') || getServerURL(state); +} diff --git a/react/features/base/known-domains/middleware.js b/react/features/base/known-domains/middleware.js index d7904cafb..3d0694392 100644 --- a/react/features/base/known-domains/middleware.js +++ b/react/features/base/known-domains/middleware.js @@ -1,6 +1,7 @@ // @flow -import { APP_WILL_MOUNT } from '../../app'; +import { APP_WILL_MOUNT, getDefaultURL } from '../../app'; + import { SET_ROOM } from '../conference'; import { MiddlewareRegistry } from '../redux'; import { parseURIString } from '../util'; @@ -32,8 +33,7 @@ MiddlewareRegistry.register(store => next => action => { * @returns {Promise} */ function _appWillMount({ dispatch, getState }) { - const defaultURL - = parseURIString(getState()['features/app'].app._getDefaultURL()); + const defaultURL = parseURIString(getDefaultURL(getState)); dispatch(addKnownDomains(defaultURL.host)); } diff --git a/react/features/base/settings/constants.js b/react/features/base/settings/constants.js new file mode 100644 index 000000000..7cbbd9848 --- /dev/null +++ b/react/features/base/settings/constants.js @@ -0,0 +1,6 @@ +// @flow + +/** + * The default server URL to open if no other was specified. + */ +export const DEFAULT_SERVER_URL = 'https://meet.jit.si'; diff --git a/react/features/base/settings/functions.js b/react/features/base/settings/functions.js index 62326a352..c09864af8 100644 --- a/react/features/base/settings/functions.js +++ b/react/features/base/settings/functions.js @@ -3,6 +3,7 @@ import { parseURLParams } from '../config'; import { toState } from '../redux'; +import { DEFAULT_SERVER_URL } from './constants'; /** * Returns the effective value of a configuration/preference/setting by applying @@ -83,3 +84,16 @@ export function getPropertyValue( return undefined; } + +/** + * Gets the currently configured server URL. + * + * @param {Object|Function} stateful - The redux state object or + * {@code getState} function. + * @returns {string} - The currently configured server URL. + */ +export function getServerURL(stateful: Object | Function) { + const state = toState(stateful); + + return state['features/base/settings'].serverURL || DEFAULT_SERVER_URL; +} diff --git a/react/features/base/settings/index.js b/react/features/base/settings/index.js index eea8d7393..086f53a9e 100644 --- a/react/features/base/settings/index.js +++ b/react/features/base/settings/index.js @@ -1,4 +1,5 @@ export * from './actions'; +export * from './constants'; export * from './functions'; import './middleware'; diff --git a/react/features/recent-list/components/RecentList.native.js b/react/features/recent-list/components/RecentList.native.js index 5cc4cb130..590ce95d0 100644 --- a/react/features/recent-list/components/RecentList.native.js +++ b/react/features/recent-list/components/RecentList.native.js @@ -2,7 +2,7 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; -import { appNavigate } from '../../app'; +import { appNavigate, getDefaultURL } from '../../app'; import { getLocalizedDateFormatter, getLocalizedDurationFormatter, @@ -226,7 +226,7 @@ class RecentList extends Component { */ export function _mapStateToProps(state: Object) { return { - _defaultServerURL: state['features/app'].app._getDefaultURL(), + _defaultServerURL: getDefaultURL(state), _recentList: state['features/recent-list'] }; } diff --git a/react/features/settings/components/AbstractSettingsView.js b/react/features/settings/components/AbstractSettingsView.js index 8cee672f7..e7e060210 100644 --- a/react/features/settings/components/AbstractSettingsView.js +++ b/react/features/settings/components/AbstractSettingsView.js @@ -2,6 +2,7 @@ import { Component } from 'react'; +import { getDefaultURL } from '../../app'; import { updateSettings } from '../../base/settings'; /** @@ -173,7 +174,7 @@ export class AbstractSettingsView extends Component { */ export function _mapStateToProps(state: Object) { return { - _serverURL: state['features/app'].app._getDefaultURL(), + _serverURL: getDefaultURL(state), _settings: state['features/base/settings'], _visible: state['features/settings'].visible };