Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
[RN] Refactor getting the default URL
Saúl Ibarra Corretgé3bfab7718f9d
diff --git a/react/features/app/actions.js b/react/features/app/actions.jsindex 4e5736393f..f7ca8b0605 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.jsindex 289b213210..55e695ad57 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.jsindex 38fa6d14de..d1f03d3e6f 100644--- a/react/features/app/functions.any.js+++ b/react/features/app/functions.any.js@@ -1,6 +1,7 @@// @flowimport { 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.jsindex d7904cafb9..3d06943924 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.jsnew file mode 100644index 0000000000..7cbbd98483--- /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.jsindex 62326a3526..c09864af8f 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.jsindex eea8d73936..086f53a9e1 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.jsindex 5cc4cb130c..590ce95d0f 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<Props> {*/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.jsindex 8cee672f74..e7e0602100 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<Props> {*/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};