Skip to content

Commit

Permalink
fix(app) simplify appNavigate on web
Browse files Browse the repository at this point in the history
Loading the config can never fail since it uses SSI and it's checked
before page even loads.
  • Loading branch information
saghul committed Jul 7, 2023
1 parent a51b377 commit f7e593f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 65 deletions.
65 changes: 5 additions & 60 deletions react/features/app/actions.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@ import { API_ID } from '../../../modules/API';
import { setRoom } from '../base/conference/actions';
import {
configWillLoad,
loadConfigError,
setConfig,
storeConfig
setConfig
} from '../base/config/actions';
import { createFakeConfig, restoreConfig } from '../base/config/functions.web';
import { setLocationURL } from '../base/connection/actions.web';
import { loadConfig } from '../base/lib-jitsi-meet/functions.web';
import { inIframe } from '../base/util/iframeUtils';
import { parseURLParams } from '../base/util/parseURLParams';
import {
appendURLParam,
getBackendSafeRoomName,
parseURIString
} from '../base/util/uri';
import { parseURIString } from '../base/util/uri';
import { isVpaasMeeting } from '../jaas/functions';
import { clearNotifications, showNotification } from '../notifications/actions';
import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
Expand Down Expand Up @@ -68,7 +60,8 @@ export function appNavigate(uri?: string) {
}

location.protocol || (location.protocol = 'https:');
const { contextRoot, host, room } = location;

const { room } = location;
const locationURL = new URL(location.toString());

// There are notifications now that gets displayed after we technically left
Expand All @@ -77,55 +70,7 @@ export function appNavigate(uri?: string) {

dispatch(configWillLoad(locationURL, room));

let protocol = location.protocol.toLowerCase();

// The React Native app supports an app-specific scheme which is sure to not
// be supported by fetch.
protocol !== 'http:' && protocol !== 'https:' && (protocol = 'https:');

const baseURL = `${protocol}//${host}${contextRoot || '/'}`;
let url = `${baseURL}config.js`;

// XXX In order to support multiple shards, tell the room to the deployment.
room && (url = appendURLParam(url, 'room', getBackendSafeRoomName(room) ?? ''));

const { release } = parseURLParams(location, true, 'search');

release && (url = appendURLParam(url, 'release', release));

let config;

// Avoid (re)loading the config when there is no room.
if (!room) {
config = restoreConfig(baseURL);
}

if (!config) {
try {
config = await loadConfig(url);
dispatch(storeConfig(baseURL, config));
} catch (error: any) {
config = restoreConfig(baseURL);

if (!config) {
if (room) {
dispatch(loadConfigError(error, locationURL));

return;
}

// If there is no room (we are on the welcome page), don't fail, just create a fake one.
logger.warn('Failed to load config but there is no room, applying a fake one');
config = createFakeConfig(baseURL);
}
}
}

if (getState()['features/base/config'].locationURL !== locationURL) {
dispatch(loadConfigError(new Error('Config no longer needed!'), locationURL));

return;
}
const config = await loadConfig();

dispatch(setLocationURL(locationURL));
dispatch(setConfig(config));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface IProps {
domain: string;
focus?: string;
muc: string;
visitorFocus: string;
visitorFocus?: string;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion react/features/base/config/configType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export interface IConfig {
domain: string;
focus?: string;
muc: string;
visitorFocus: string;
visitorFocus?: string;
};
iAmRecorder?: boolean;
iAmSipGateway?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions react/features/base/lib-jitsi-meet/functions.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ export * from './functions.any';
/**
* Loads config.js from a specific remote server.
*
* @param {string} url - The URL to load.
* @returns {Promise<Object>}
* @param {string} _url - The URL to load.
* @returns {Promise<IConfig>}
*/
export async function loadConfig(url: string) { // eslint-disable-line @typescript-eslint/no-unused-vars
export async function loadConfig(_url?: string) {
// Return "the config.js file" from the global scope - that is how the
// Web app on both the client and the server was implemented before the
// React Native app was even conceived.
Expand Down

0 comments on commit f7e593f

Please sign in to comment.