2017-07-21 21:12:02 +00:00
|
|
|
import { getLocationContextRoot } from '../../base/util';
|
2017-03-07 03:43:41 +00:00
|
|
|
import '../../room-lock';
|
|
|
|
|
2017-07-21 21:12:02 +00:00
|
|
|
import { AbstractApp } from './AbstractApp';
|
|
|
|
|
2016-11-23 21:46:46 +00:00
|
|
|
/**
|
|
|
|
* Root application component.
|
|
|
|
*
|
|
|
|
* @extends AbstractApp
|
|
|
|
*/
|
|
|
|
export class App extends AbstractApp {
|
2016-12-01 01:52:39 +00:00
|
|
|
/**
|
|
|
|
* App component's property types.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
2017-06-09 10:26:21 +00:00
|
|
|
static propTypes = AbstractApp.propTypes;
|
2016-12-01 01:52:39 +00:00
|
|
|
|
2017-02-05 02:29:24 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new App instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only React Component props with which
|
|
|
|
* the new instance is to be initialized.
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
...this.state,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The context root of window.location i.e. this Web App.
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
windowLocationContextRoot: this._getWindowLocationContextRoot()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-15 19:05:17 +00:00
|
|
|
/**
|
|
|
|
* Gets a Location object from the window with information about the current
|
|
|
|
* location of the document.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2017-03-02 03:33:49 +00:00
|
|
|
getWindowLocation() {
|
2017-01-15 19:05:17 +00:00
|
|
|
return window.location;
|
|
|
|
}
|
|
|
|
|
2017-02-05 02:29:24 +00:00
|
|
|
/**
|
|
|
|
* Gets the context root of this Web App from window.location.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {string} The context root of window.location i.e. this Web App.
|
|
|
|
*/
|
|
|
|
_getWindowLocationContextRoot() {
|
2017-05-09 05:15:43 +00:00
|
|
|
return getLocationContextRoot(this.getWindowLocation());
|
2017-02-05 02:29:24 +00:00
|
|
|
}
|
|
|
|
|
2016-12-12 21:13:17 +00:00
|
|
|
/**
|
2017-01-10 19:06:18 +00:00
|
|
|
* Navigates to a specific Route (via platform-specific means).
|
2016-12-12 21:13:17 +00:00
|
|
|
*
|
2017-01-10 19:06:18 +00:00
|
|
|
* @param {Route} route - The Route to which to navigate.
|
2017-01-16 00:28:02 +00:00
|
|
|
* @protected
|
2017-01-10 19:06:18 +00:00
|
|
|
* @returns {void}
|
2016-12-12 21:13:17 +00:00
|
|
|
*/
|
2017-01-10 19:06:18 +00:00
|
|
|
_navigate(route) {
|
2017-07-06 18:39:59 +00:00
|
|
|
let path;
|
2016-12-12 21:13:17 +00:00
|
|
|
|
2017-07-06 18:39:59 +00:00
|
|
|
if (route) {
|
|
|
|
path = route.path;
|
|
|
|
|
|
|
|
const store = this._getStore();
|
|
|
|
|
|
|
|
// The syntax :room bellow is defined by react-router. It "matches a
|
|
|
|
// URL segment up to the next /, ?, or #. The matched string is
|
|
|
|
// called a param."
|
|
|
|
path
|
|
|
|
= path.replace(
|
|
|
|
/:room/g,
|
|
|
|
store.getState()['features/base/conference'].room);
|
|
|
|
path = this._routePath2WindowLocationPathname(path);
|
|
|
|
}
|
2017-01-10 19:06:18 +00:00
|
|
|
|
2017-01-16 00:28:02 +00:00
|
|
|
// Navigate to the specified Route.
|
2017-03-02 03:33:49 +00:00
|
|
|
const windowLocation = this.getWindowLocation();
|
2017-08-01 00:34:19 +00:00
|
|
|
let promise;
|
2017-01-16 00:28:02 +00:00
|
|
|
|
2017-07-06 18:39:59 +00:00
|
|
|
if (!route || windowLocation.pathname === path) {
|
2017-01-16 00:28:02 +00:00
|
|
|
// The browser is at the specified path already and what remains is
|
|
|
|
// to make this App instance aware of the route to be rendered at
|
|
|
|
// the current location.
|
2017-08-01 00:34:19 +00:00
|
|
|
|
|
|
|
// XXX Refer to the super's _navigate for an explanation why a
|
|
|
|
// Promise is returned.
|
|
|
|
promise = super._navigate(route);
|
2017-01-16 00:28:02 +00:00
|
|
|
} else {
|
|
|
|
// The browser must go to the specified location. Once the specified
|
|
|
|
// location becomes current, the App will be made aware of the route
|
|
|
|
// to be rendered at it.
|
|
|
|
windowLocation.pathname = path;
|
2017-01-10 21:55:31 +00:00
|
|
|
}
|
2017-08-01 00:34:19 +00:00
|
|
|
|
|
|
|
return promise || Promise.resolve();
|
2016-11-23 21:46:46 +00:00
|
|
|
}
|
2017-02-05 02:29:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a specific Route path to a window.location.pathname.
|
|
|
|
*
|
|
|
|
* @param {string} path - A Route path to be converted to/represeted as a
|
|
|
|
* window.location.pathname.
|
|
|
|
* @private
|
|
|
|
* @returns {string} A window.location.pathname-compatible representation of
|
|
|
|
* the specified Route path.
|
|
|
|
*/
|
|
|
|
_routePath2WindowLocationPathname(path) {
|
|
|
|
let pathname = this.state.windowLocationContextRoot;
|
|
|
|
|
|
|
|
pathname.endsWith('/') || (pathname += '/');
|
|
|
|
pathname += path.startsWith('/') ? path.substring(1) : path;
|
|
|
|
|
|
|
|
return pathname;
|
|
|
|
}
|
2016-11-23 21:46:46 +00:00
|
|
|
}
|