2018-05-23 21:10:04 +00:00
|
|
|
// @flow
|
2017-10-02 23:08:07 +00:00
|
|
|
|
2018-05-23 10:48:59 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
2017-05-09 05:15:43 +00:00
|
|
|
import { setRoom } from '../base/conference';
|
2018-05-14 20:49:00 +00:00
|
|
|
import {
|
|
|
|
configWillLoad,
|
|
|
|
loadConfigError,
|
|
|
|
restoreConfig,
|
|
|
|
setConfig,
|
|
|
|
storeConfig
|
|
|
|
} from '../base/config';
|
2019-05-22 10:01:58 +00:00
|
|
|
import { connect, disconnect, setLocationURL } from '../base/connection';
|
2017-04-23 20:14:02 +00:00
|
|
|
import { loadConfig } from '../base/lib-jitsi-meet';
|
2019-05-22 10:01:58 +00:00
|
|
|
import { createDesiredLocalTracks } from '../base/tracks';
|
2018-07-02 21:22:51 +00:00
|
|
|
import { parseURIString, toURLString } from '../base/util';
|
|
|
|
import { setFatalError } from '../overlay';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2018-07-11 08:57:07 +00:00
|
|
|
import { getDefaultURL } from './functions';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2018-07-02 21:22:51 +00:00
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
|
|
|
2017-05-26 22:11:33 +00:00
|
|
|
declare var APP: Object;
|
2016-12-14 12:09:29 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2017-05-09 05:15:43 +00:00
|
|
|
* Triggers an in-app navigation to a specific route. Allows navigation to be
|
|
|
|
* abstracted between the mobile/React Native and Web/React applications.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2018-02-27 20:21:28 +00:00
|
|
|
* @param {string|undefined} uri - The URI to which to navigate. It may be a
|
2017-05-09 05:15:43 +00:00
|
|
|
* full URL with an HTTP(S) scheme, a full or partial URI with the app-specific
|
2017-05-26 22:11:33 +00:00
|
|
|
* scheme, or a mere room name.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2017-05-09 05:15:43 +00:00
|
|
|
export function appNavigate(uri: ?string) {
|
2019-04-08 11:18:35 +00:00
|
|
|
return async (dispatch: Dispatch<any>, getState: Function) => {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2017-04-19 14:52:27 +00:00
|
|
|
|
2019-04-08 11:18:35 +00:00
|
|
|
location.protocol || (location.protocol = 'https:');
|
2019-04-09 15:53:12 +00:00
|
|
|
const { contextRoot, host, room } = location;
|
2019-04-08 11:18:35 +00:00
|
|
|
const locationURL = new URL(location.toString());
|
2017-08-31 19:16:44 +00:00
|
|
|
|
2019-05-22 10:01:58 +00:00
|
|
|
// Disconnect from any current conference.
|
|
|
|
// FIXME: unify with web.
|
|
|
|
if (navigator.product === 'ReactNative') {
|
|
|
|
dispatch(disconnect());
|
|
|
|
}
|
|
|
|
|
2019-04-09 15:53:12 +00:00
|
|
|
dispatch(configWillLoad(locationURL, room));
|
2017-04-19 14:52:27 +00:00
|
|
|
|
2019-04-08 11:18:35 +00:00
|
|
|
let protocol = location.protocol.toLowerCase();
|
2016-12-07 22:06:16 +00:00
|
|
|
|
2019-04-08 11:18:35 +00:00
|
|
|
// The React Native app supports an app-specific scheme which is sure to not
|
|
|
|
// be supported by fetch.
|
|
|
|
protocol !== 'http:' && protocol !== 'https:' && (protocol = 'https:');
|
2017-01-25 22:11:44 +00:00
|
|
|
|
2019-04-08 11:18:35 +00:00
|
|
|
const baseURL = `${protocol}//${host}${contextRoot || '/'}`;
|
|
|
|
let url = `${baseURL}config.js`;
|
2017-05-09 05:15:43 +00:00
|
|
|
|
2019-04-08 11:18:35 +00:00
|
|
|
// XXX In order to support multiple shards, tell the room to the deployment.
|
|
|
|
room && (url += `?room=${room.toLowerCase()}`);
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2019-04-08 11:18:35 +00:00
|
|
|
let config;
|
|
|
|
|
2019-05-23 08:17:42 +00:00
|
|
|
// Avoid (re)loading the config when there is no room.
|
|
|
|
if (!room) {
|
2019-04-08 11:18:35 +00:00
|
|
|
config = restoreConfig(baseURL);
|
2019-05-23 08:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!config) {
|
|
|
|
try {
|
|
|
|
config = await loadConfig(url);
|
|
|
|
dispatch(storeConfig(baseURL, config));
|
|
|
|
} catch (error) {
|
|
|
|
config = restoreConfig(baseURL);
|
2017-09-05 20:53:39 +00:00
|
|
|
|
2019-05-23 08:17:42 +00:00
|
|
|
if (!config) {
|
|
|
|
dispatch(loadConfigError(error, locationURL));
|
2017-08-28 11:20:53 +00:00
|
|
|
|
2019-05-23 08:17:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-09-05 20:53:39 +00:00
|
|
|
}
|
2019-04-08 11:18:35 +00:00
|
|
|
}
|
2017-08-28 11:20:53 +00:00
|
|
|
|
2019-05-22 10:01:58 +00:00
|
|
|
if (getState()['features/base/config'].locationURL !== locationURL) {
|
2019-04-08 11:18:35 +00:00
|
|
|
dispatch(loadConfigError(new Error('Config no longer needed!'), locationURL));
|
2019-05-22 10:01:58 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(setLocationURL(locationURL));
|
|
|
|
dispatch(setConfig(config));
|
|
|
|
dispatch(setRoom(room));
|
|
|
|
|
|
|
|
// FIXME: unify with web, currently the connection and track creation happens in conference.js.
|
|
|
|
if (room && navigator.product === 'ReactNative') {
|
|
|
|
dispatch(createDesiredLocalTracks());
|
|
|
|
dispatch(connect());
|
2019-04-08 11:18:35 +00:00
|
|
|
}
|
|
|
|
};
|
2017-05-09 05:15:43 +00:00
|
|
|
}
|
2018-05-14 20:49:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirects to another page generated by replacing the path in the original URL
|
|
|
|
* with the given path.
|
|
|
|
*
|
|
|
|
* @param {(string)} pathname - The path to navigate to.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function redirectWithStoredParams(pathname: string) {
|
2019-03-19 15:42:25 +00:00
|
|
|
return (dispatch: Dispatch<any>, getState: Function) => {
|
2018-05-14 20:49:00 +00:00
|
|
|
const { locationURL } = getState()['features/base/connection'];
|
|
|
|
const newLocationURL = new URL(locationURL.href);
|
|
|
|
|
|
|
|
newLocationURL.pathname = pathname;
|
|
|
|
window.location.assign(newLocationURL.toString());
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-07-02 21:22:51 +00:00
|
|
|
/**
|
|
|
|
* Reloads the page.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function reloadNow() {
|
|
|
|
return (dispatch: Dispatch<Function>, getState: Function) => {
|
|
|
|
dispatch(setFatalError(undefined));
|
|
|
|
|
|
|
|
const { locationURL } = getState()['features/base/connection'];
|
|
|
|
|
|
|
|
logger.info(`Reloading the conference using URL: ${locationURL}`);
|
|
|
|
|
|
|
|
if (navigator.product === 'ReactNative') {
|
|
|
|
dispatch(appNavigate(toURLString(locationURL)));
|
|
|
|
} else {
|
|
|
|
dispatch(reloadWithStoredParams());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-05-14 20:49:00 +00:00
|
|
|
/**
|
|
|
|
* Reloads the page by restoring the original URL.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function reloadWithStoredParams() {
|
2019-03-19 15:42:25 +00:00
|
|
|
return (dispatch: Dispatch<any>, getState: Function) => {
|
2018-05-14 20:49:00 +00:00
|
|
|
const { locationURL } = getState()['features/base/connection'];
|
|
|
|
const windowLocation = window.location;
|
|
|
|
const oldSearchString = windowLocation.search;
|
|
|
|
|
|
|
|
windowLocation.replace(locationURL.toString());
|
|
|
|
|
|
|
|
if (window.self !== window.top
|
|
|
|
&& locationURL.search === oldSearchString) {
|
|
|
|
// NOTE: Assuming that only the hash or search part of the URL will
|
|
|
|
// be changed!
|
|
|
|
// location.reload will not trigger redirect/reload for iframe when
|
|
|
|
// only the hash params are changed. That's why we need to call
|
|
|
|
// reload in addition to replace.
|
|
|
|
windowLocation.reload();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|