[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.
This commit is contained in:
Saúl Ibarra Corretgé 2018-07-11 10:57:07 +02:00 committed by Lyubo Marinov
parent 980648df4d
commit 3bfab7718f
9 changed files with 60 additions and 35 deletions

View File

@ -16,6 +16,7 @@ import { parseURIString, toURLString } from '../base/util';
import { setFatalError } from '../overlay'; import { setFatalError } from '../overlay';
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes'; import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
import { getDefaultURL } from './functions';
const logger = require('jitsi-meet-logger').getLogger(__filename); 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 // If the specified location (URI) does not identify a host, use the app's
// default. // default.
if (!location || !location.host) { if (!location || !location.host) {
const defaultLocation const defaultLocation = parseURIString(getDefaultURL(getState));
= parseURIString(getState()['features/app'].app._getDefaultURL());
if (location) { if (location) {
location.host = defaultLocation.host; location.host = defaultLocation.host;

View File

@ -20,15 +20,7 @@ import { toURLString } from '../../base/util';
import { OverlayContainer } from '../../overlay'; import { OverlayContainer } from '../../overlay';
import { appNavigate, appWillMount, appWillUnmount } from '../actions'; import { appNavigate, appWillMount, appWillUnmount } from '../actions';
import { getDefaultURL } from '../functions';
/**
* 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';
/** /**
* Base (abstract) class for main App component. * Base (abstract) class for main App component.
@ -322,24 +314,7 @@ export class AbstractApp extends Component {
* mounts. * mounts.
*/ */
_getDefaultURL() { _getDefaultURL() {
// If the execution environment provides a Location abstraction, then return getDefaultURL(this.state.store);
// 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);
} }
/** /**

View File

@ -1,6 +1,7 @@
// @flow // @flow
import { toState } from '../base/redux'; import { toState } from '../base/redux';
import { getServerURL } from '../base/settings';
/** /**
* Gets the value of a specific React {@code Component} prop of the currently * 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; 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);
}

View File

@ -1,6 +1,7 @@
// @flow // @flow
import { APP_WILL_MOUNT } from '../../app'; import { APP_WILL_MOUNT, getDefaultURL } from '../../app';
import { SET_ROOM } from '../conference'; import { SET_ROOM } from '../conference';
import { MiddlewareRegistry } from '../redux'; import { MiddlewareRegistry } from '../redux';
import { parseURIString } from '../util'; import { parseURIString } from '../util';
@ -32,8 +33,7 @@ MiddlewareRegistry.register(store => next => action => {
* @returns {Promise} * @returns {Promise}
*/ */
function _appWillMount({ dispatch, getState }) { function _appWillMount({ dispatch, getState }) {
const defaultURL const defaultURL = parseURIString(getDefaultURL(getState));
= parseURIString(getState()['features/app'].app._getDefaultURL());
dispatch(addKnownDomains(defaultURL.host)); dispatch(addKnownDomains(defaultURL.host));
} }

View File

@ -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';

View File

@ -3,6 +3,7 @@
import { parseURLParams } from '../config'; import { parseURLParams } from '../config';
import { toState } from '../redux'; import { toState } from '../redux';
import { DEFAULT_SERVER_URL } from './constants';
/** /**
* Returns the effective value of a configuration/preference/setting by applying * Returns the effective value of a configuration/preference/setting by applying
@ -83,3 +84,16 @@ export function getPropertyValue(
return undefined; 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;
}

View File

@ -1,4 +1,5 @@
export * from './actions'; export * from './actions';
export * from './constants';
export * from './functions'; export * from './functions';
import './middleware'; import './middleware';

View File

@ -2,7 +2,7 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { appNavigate } from '../../app'; import { appNavigate, getDefaultURL } from '../../app';
import { import {
getLocalizedDateFormatter, getLocalizedDateFormatter,
getLocalizedDurationFormatter, getLocalizedDurationFormatter,
@ -226,7 +226,7 @@ class RecentList extends Component<Props> {
*/ */
export function _mapStateToProps(state: Object) { export function _mapStateToProps(state: Object) {
return { return {
_defaultServerURL: state['features/app'].app._getDefaultURL(), _defaultServerURL: getDefaultURL(state),
_recentList: state['features/recent-list'] _recentList: state['features/recent-list']
}; };
} }

View File

@ -2,6 +2,7 @@
import { Component } from 'react'; import { Component } from 'react';
import { getDefaultURL } from '../../app';
import { updateSettings } from '../../base/settings'; import { updateSettings } from '../../base/settings';
/** /**
@ -173,7 +174,7 @@ export class AbstractSettingsView extends Component<Props> {
*/ */
export function _mapStateToProps(state: Object) { export function _mapStateToProps(state: Object) {
return { return {
_serverURL: state['features/app'].app._getDefaultURL(), _serverURL: getDefaultURL(state),
_settings: state['features/base/settings'], _settings: state['features/base/settings'],
_visible: state['features/settings'].visible _visible: state['features/settings'].visible
}; };