2017-04-21 10:00:50 +00:00
|
|
|
import { setRoom, setRoomURL } from '../base/conference';
|
2017-04-23 20:14:02 +00:00
|
|
|
import { setConfig } from '../base/config';
|
2017-01-10 21:55:31 +00:00
|
|
|
import { getDomain, setDomain } from '../base/connection';
|
2017-04-23 20:14:02 +00:00
|
|
|
import { loadConfig } from '../base/lib-jitsi-meet';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-01-15 04:05:56 +00:00
|
|
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
|
2016-10-05 14:36:59 +00:00
|
|
|
import {
|
2016-12-14 12:09:29 +00:00
|
|
|
_getRouteToRender,
|
2017-02-01 04:25:09 +00:00
|
|
|
_parseURIString,
|
2016-12-14 12:09:29 +00:00
|
|
|
init
|
2016-10-05 14:36:59 +00:00
|
|
|
} from './functions';
|
|
|
|
|
2017-01-10 19:06:18 +00:00
|
|
|
/**
|
2017-01-10 21:55:31 +00:00
|
|
|
* Temporary solution. Should dispatch actions related to initial settings of
|
|
|
|
* the app like setting log levels, reading the config parameters from query
|
|
|
|
* string etc.
|
2017-01-10 19:06:18 +00:00
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function appInit() {
|
2017-04-21 10:00:50 +00:00
|
|
|
return (dispatch, getState) => init(getState());
|
2017-01-10 19:06:18 +00:00
|
|
|
}
|
2016-12-14 12:09:29 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Triggers an in-app navigation to a different route. Allows navigation to be
|
|
|
|
* abstracted between the mobile and web versions.
|
|
|
|
*
|
2017-02-18 16:02:31 +00:00
|
|
|
* @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
|
|
|
|
* sheme, or a mere room name.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2017-02-18 16:02:31 +00:00
|
|
|
export function appNavigate(uri) {
|
2016-10-05 14:36:59 +00:00
|
|
|
return (dispatch, getState) => {
|
2016-12-27 16:03:30 +00:00
|
|
|
const state = getState();
|
|
|
|
const oldDomain = getDomain(state);
|
2017-04-19 14:52:27 +00:00
|
|
|
const defaultURL = state['features/app'].app._getDefaultURL();
|
|
|
|
let urlObject;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-02-18 16:02:31 +00:00
|
|
|
// eslint-disable-next-line prefer-const
|
|
|
|
let { domain, room } = _parseURIString(uri);
|
|
|
|
|
|
|
|
// If the specified URI does not identify a domain, use the app's
|
|
|
|
// default.
|
|
|
|
if (typeof domain === 'undefined') {
|
|
|
|
domain
|
2017-04-19 14:52:27 +00:00
|
|
|
= _parseURIString(defaultURL)
|
2017-02-18 16:02:31 +00:00
|
|
|
.domain;
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-04-19 14:52:27 +00:00
|
|
|
if (room) {
|
|
|
|
const splitUrl = uri.split(domain);
|
|
|
|
const urlWithoutDomain = splitUrl[splitUrl.length - 1];
|
|
|
|
|
|
|
|
urlObject = new URL(urlWithoutDomain, `https://${domain}`);
|
|
|
|
}
|
|
|
|
|
2017-04-21 10:00:50 +00:00
|
|
|
dispatch(setRoomURL(urlObject));
|
2017-04-19 14:52:27 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
// TODO Kostiantyn Tsaregradskyi: We should probably detect if user is
|
|
|
|
// currently in a conference and ask her if she wants to close the
|
|
|
|
// current conference and start a new one with the new room name or
|
|
|
|
// domain.
|
|
|
|
|
2017-01-18 12:21:30 +00:00
|
|
|
if (typeof domain === 'undefined' || oldDomain === domain) {
|
2017-01-25 22:11:44 +00:00
|
|
|
dispatchSetRoomAndNavigate();
|
2016-10-05 14:36:59 +00:00
|
|
|
} else if (oldDomain !== domain) {
|
|
|
|
// Update domain without waiting for config to be loaded to prevent
|
|
|
|
// race conditions when we will start to load config multiple times.
|
|
|
|
dispatch(setDomain(domain));
|
|
|
|
|
2016-12-07 22:06:16 +00:00
|
|
|
// If domain has changed, we need to load the config of the new
|
2017-02-18 16:02:31 +00:00
|
|
|
// domain and set it, and only after that we can navigate to a
|
2016-12-07 22:06:16 +00:00
|
|
|
// different route.
|
2016-10-05 14:36:59 +00:00
|
|
|
loadConfig(`https://${domain}`)
|
2016-12-07 22:06:16 +00:00
|
|
|
.then(
|
|
|
|
config => configLoaded(/* err */ undefined, config),
|
2017-01-18 12:21:30 +00:00
|
|
|
err => configLoaded(err, /* config */ undefined))
|
2017-01-25 22:11:44 +00:00
|
|
|
.then(dispatchSetRoomAndNavigate);
|
2016-12-07 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies that an attempt to load the config(uration) of domain has
|
|
|
|
* completed.
|
|
|
|
*
|
|
|
|
* @param {string|undefined} err - If the loading has failed, the error
|
|
|
|
* detailing the cause of the failure.
|
|
|
|
* @param {Object|undefined} config - If the loading has succeeded, the
|
|
|
|
* loaded config(uration).
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function configLoaded(err, config) {
|
|
|
|
if (err) {
|
|
|
|
// XXX The failure could be, for example, because of a
|
|
|
|
// certificate-related error. In which case the connection will
|
|
|
|
// fail later in Strophe anyway even if we use the default
|
|
|
|
// config here.
|
|
|
|
|
|
|
|
// The function loadConfig will log the err.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(setConfig(config));
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
2017-01-25 22:11:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatches _setRoomAndNavigate in the Redux store.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function dispatchSetRoomAndNavigate() {
|
|
|
|
// If both domain and room vars became undefined, that means we're
|
|
|
|
// actually dealing with just room name and not with URL.
|
|
|
|
dispatch(
|
|
|
|
_setRoomAndNavigate(
|
|
|
|
typeof room === 'undefined' && typeof domain === 'undefined'
|
2017-02-18 16:02:31 +00:00
|
|
|
? uri
|
2017-01-25 22:11:44 +00:00
|
|
|
: room));
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals that a specific App will mount (in the terms of React).
|
|
|
|
*
|
|
|
|
* @param {App} app - The App which will mount.
|
|
|
|
* @returns {{
|
|
|
|
* type: APP_WILL_MOUNT,
|
|
|
|
* app: App
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function appWillMount(app) {
|
|
|
|
return {
|
|
|
|
type: APP_WILL_MOUNT,
|
|
|
|
app
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals that a specific App will unmount (in the terms of React).
|
|
|
|
*
|
|
|
|
* @param {App} app - The App which will unmount.
|
|
|
|
* @returns {{
|
|
|
|
* type: APP_WILL_UNMOUNT,
|
|
|
|
* app: App
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function appWillUnmount(app) {
|
|
|
|
return {
|
|
|
|
type: APP_WILL_UNMOUNT,
|
|
|
|
app
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-25 22:11:44 +00:00
|
|
|
/**
|
|
|
|
* Navigates to a route in accord with a specific Redux state.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state which determines/identifies the route
|
|
|
|
* to navigate to.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _navigate(state) {
|
|
|
|
const app = state['features/app'].app;
|
|
|
|
const routeToRender = _getRouteToRender(state);
|
|
|
|
|
|
|
|
app._navigate(routeToRender);
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Sets room and navigates to new route if needed.
|
|
|
|
*
|
|
|
|
* @param {string} newRoom - New room name.
|
|
|
|
* @private
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
function _setRoomAndNavigate(newRoom) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch(setRoom(newRoom));
|
2017-01-25 22:11:44 +00:00
|
|
|
_navigate(getState());
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
}
|