2022-10-21 11:09:15 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
|
|
|
import { setRoom } from '../base/conference/actions';
|
2022-03-17 14:13:58 +00:00
|
|
|
import {
|
|
|
|
configWillLoad,
|
|
|
|
loadConfigError,
|
|
|
|
setConfig,
|
|
|
|
storeConfig
|
2022-10-21 11:09:15 +00:00
|
|
|
} from '../base/config/actions';
|
|
|
|
import {
|
|
|
|
createFakeConfig,
|
|
|
|
restoreConfig
|
|
|
|
} from '../base/config/functions';
|
|
|
|
import { connect, disconnect, setLocationURL } from '../base/connection/actions';
|
2022-04-12 08:38:30 +00:00
|
|
|
import { loadConfig } from '../base/lib-jitsi-meet/functions.native';
|
2022-10-21 11:09:15 +00:00
|
|
|
import { createDesiredLocalTracks } from '../base/tracks/actions';
|
|
|
|
import { parseURLParams } from '../base/util/parseURLParams';
|
2022-03-17 14:13:58 +00:00
|
|
|
import {
|
2022-06-16 12:27:41 +00:00
|
|
|
appendURLParam,
|
2022-03-17 14:13:58 +00:00
|
|
|
getBackendSafeRoomName,
|
|
|
|
parseURIString,
|
|
|
|
toURLString
|
2022-10-21 11:09:15 +00:00
|
|
|
} from '../base/util/uri';
|
|
|
|
// @ts-ignore
|
2022-06-16 09:49:07 +00:00
|
|
|
import { isPrejoinPageEnabled } from '../mobile/navigation/functions';
|
|
|
|
import {
|
|
|
|
goBackToRoot,
|
|
|
|
navigateRoot
|
2022-10-21 11:09:15 +00:00
|
|
|
// @ts-ignore
|
2022-06-16 09:49:07 +00:00
|
|
|
} from '../mobile/navigation/rootNavigationContainerRef';
|
2022-10-21 11:09:15 +00:00
|
|
|
// @ts-ignore
|
2022-03-17 14:13:58 +00:00
|
|
|
import { screen } from '../mobile/navigation/routes';
|
2022-10-21 11:09:15 +00:00
|
|
|
import { clearNotifications } from '../notifications/actions';
|
|
|
|
// @ts-ignore
|
2022-03-17 14:13:58 +00:00
|
|
|
import { setFatalError } from '../overlay';
|
|
|
|
|
2022-10-21 11:09:15 +00:00
|
|
|
import { addTrackStateToURL, getDefaultURL } from './functions.native';
|
2022-03-17 14:13:58 +00:00
|
|
|
import logger from './logger';
|
2022-10-21 11:09:15 +00:00
|
|
|
import { IStore } from './types';
|
2022-03-17 14:13:58 +00:00
|
|
|
|
|
|
|
export * from './actions.any';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggers an in-app navigation to a specific route. Allows navigation to be
|
|
|
|
* abstracted between the mobile/React Native and Web/React applications.
|
|
|
|
*
|
|
|
|
* @param {string|undefined} uri - The URI to which to navigate. It may be a
|
|
|
|
* full URL with an HTTP(S) scheme, a full or partial URI with the app-specific
|
|
|
|
* scheme, or a mere room name.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2022-07-11 12:30:37 +00:00
|
|
|
export function appNavigate(uri?: string) {
|
2022-04-12 09:31:30 +00:00
|
|
|
logger.info(`appNavigate to ${uri}`);
|
|
|
|
|
2022-10-21 11:09:15 +00:00
|
|
|
return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
2022-03-17 14:13:58 +00:00
|
|
|
let location = parseURIString(uri);
|
|
|
|
|
|
|
|
// If the specified location (URI) does not identify a host, use the app's
|
|
|
|
// default.
|
|
|
|
if (!location || !location.host) {
|
|
|
|
const defaultLocation = parseURIString(getDefaultURL(getState));
|
|
|
|
|
|
|
|
if (location) {
|
|
|
|
location.host = defaultLocation.host;
|
|
|
|
|
|
|
|
// FIXME Turn location's host, hostname, and port properties into
|
|
|
|
// setters in order to reduce the risks of inconsistent state.
|
|
|
|
location.hostname = defaultLocation.hostname;
|
|
|
|
location.pathname
|
|
|
|
= defaultLocation.pathname + location.pathname.substr(1);
|
|
|
|
location.port = defaultLocation.port;
|
|
|
|
location.protocol = defaultLocation.protocol;
|
|
|
|
} else {
|
|
|
|
location = defaultLocation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
location.protocol || (location.protocol = 'https:');
|
|
|
|
const { contextRoot, host, room } = location;
|
|
|
|
const locationURL = new URL(location.toString());
|
|
|
|
|
|
|
|
if (room) {
|
|
|
|
navigateRoot(screen.connecting);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(disconnect());
|
|
|
|
|
|
|
|
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.
|
2022-10-21 11:09:15 +00:00
|
|
|
room && (url = appendURLParam(url, 'room', getBackendSafeRoomName(room) ?? ''));
|
2022-06-16 12:27:41 +00:00
|
|
|
|
|
|
|
const { release } = parseURLParams(location, true, 'search');
|
|
|
|
|
|
|
|
release && (url = appendURLParam(url, 'release', release));
|
2022-03-17 14:13:58 +00:00
|
|
|
|
|
|
|
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));
|
2022-10-21 11:09:15 +00:00
|
|
|
} catch (error: any) {
|
2022-03-17 14:13:58 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(setLocationURL(locationURL));
|
|
|
|
dispatch(setConfig(config));
|
|
|
|
dispatch(setRoom(room));
|
|
|
|
|
|
|
|
if (room) {
|
|
|
|
dispatch(createDesiredLocalTracks());
|
2022-10-13 14:05:21 +00:00
|
|
|
dispatch(clearNotifications());
|
2022-06-16 09:49:07 +00:00
|
|
|
|
|
|
|
if (isPrejoinPageEnabled(getState())) {
|
|
|
|
navigateRoot(screen.preJoin);
|
|
|
|
} else {
|
|
|
|
dispatch(connect());
|
|
|
|
navigateRoot(screen.conference.root);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
goBackToRoot(getState(), dispatch);
|
2022-03-17 14:13:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-28 10:07:58 +00:00
|
|
|
/**
|
|
|
|
* Check if the welcome page is enabled and redirects to it.
|
|
|
|
* If requested show a thank you dialog before that.
|
|
|
|
* If we have a close page enabled, redirect to it without
|
|
|
|
* showing any other dialog.
|
|
|
|
*
|
2022-11-01 21:12:33 +00:00
|
|
|
* @param {Object} options - Ignored.
|
2022-10-28 10:07:58 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2022-11-01 21:12:33 +00:00
|
|
|
export function maybeRedirectToWelcomePage(options: any) { // eslint-disable-line @typescript-eslint/no-unused-vars
|
2022-10-28 10:07:58 +00:00
|
|
|
// Dummy.
|
|
|
|
}
|
|
|
|
|
2022-03-17 14:13:58 +00:00
|
|
|
/**
|
|
|
|
* Reloads the page.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function reloadNow() {
|
2022-10-21 11:09:15 +00:00
|
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
2022-03-17 14:13:58 +00:00
|
|
|
dispatch(setFatalError(undefined));
|
|
|
|
|
|
|
|
const state = getState();
|
|
|
|
const { locationURL } = state['features/base/connection'];
|
|
|
|
|
|
|
|
// Preserve the local tracks muted state after the reload.
|
2022-10-21 11:09:15 +00:00
|
|
|
// @ts-ignore
|
2022-03-17 14:13:58 +00:00
|
|
|
const newURL = addTrackStateToURL(locationURL, state);
|
|
|
|
|
|
|
|
logger.info(`Reloading the conference using URL: ${locationURL}`);
|
|
|
|
|
|
|
|
dispatch(appNavigate(toURLString(newURL)));
|
|
|
|
};
|
|
|
|
}
|