2018-07-11 09:42:43 +00:00
|
|
|
// @flow
|
2017-11-16 18:26:14 +00:00
|
|
|
|
2018-07-11 09:42:43 +00:00
|
|
|
import React, { Fragment } from 'react';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2018-07-11 09:42:43 +00:00
|
|
|
import { BaseApp } from '../../base/app';
|
2017-07-26 19:27:29 +00:00
|
|
|
import { toURLString } from '../../base/util';
|
2019-04-17 15:05:32 +00:00
|
|
|
import '../../follow-me';
|
2017-11-23 17:03:33 +00:00
|
|
|
import { OverlayContainer } from '../../overlay';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2018-07-11 09:42:43 +00:00
|
|
|
import { appNavigate } from '../actions';
|
2018-07-11 08:57:07 +00:00
|
|
|
import { getDefaultURL } from '../functions';
|
2017-06-09 10:26:21 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2018-07-12 16:16:57 +00:00
|
|
|
* The type of React {@code Component} props of {@link AbstractApp}.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2018-07-11 09:42:43 +00:00
|
|
|
export type Props = {
|
|
|
|
|
2017-01-16 00:28:02 +00:00
|
|
|
/**
|
2018-07-11 09:42:43 +00:00
|
|
|
* XXX Refer to the implementation of loadURLObject: in
|
|
|
|
* ios/sdk/src/JitsiMeetView.m for further information.
|
2017-01-16 00:28:02 +00:00
|
|
|
*/
|
2018-07-11 09:42:43 +00:00
|
|
|
timestamp: any,
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2018-07-11 09:42:43 +00:00
|
|
|
/**
|
|
|
|
* The URL, if any, with which the app was launched.
|
|
|
|
*/
|
|
|
|
url: Object | string
|
|
|
|
};
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2018-07-11 09:42:43 +00:00
|
|
|
/**
|
|
|
|
* Base (abstract) class for main App component.
|
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
*/
|
|
|
|
export class AbstractApp extends BaseApp<Props, *> {
|
|
|
|
_init: Promise<*>;
|
2017-01-16 00:28:02 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2018-07-10 09:11:45 +00:00
|
|
|
* Initializes the app.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2019-01-01 23:50:11 +00:00
|
|
|
componentDidMount() {
|
|
|
|
super.componentDidMount();
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2018-07-11 09:42:43 +00:00
|
|
|
this._init.then(() => {
|
2018-07-12 16:16:57 +00:00
|
|
|
// If a URL was explicitly specified to this React Component, then
|
|
|
|
// open it; otherwise, use a default.
|
2017-12-14 17:02:32 +00:00
|
|
|
this._openURL(toURLString(this.props.url) || this._getDefaultURL());
|
|
|
|
});
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 21:29:28 +00:00
|
|
|
/**
|
2019-01-04 03:34:46 +00:00
|
|
|
* Implements React Component's componentDidUpdate.
|
2017-01-26 21:29:28 +00:00
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2019-01-04 03:34:46 +00:00
|
|
|
componentDidUpdate(prevProps: Props) {
|
|
|
|
const previousUrl = toURLString(prevProps.url);
|
|
|
|
const currentUrl = toURLString(this.props.url);
|
|
|
|
const previousTimestamp = prevProps.timestamp;
|
|
|
|
const currentTimestamp = this.props.timestamp;
|
2018-01-08 11:00:31 +00:00
|
|
|
|
2018-02-05 21:26:01 +00:00
|
|
|
this._init.then(() => {
|
2017-12-14 17:02:32 +00:00
|
|
|
// Deal with URL changes.
|
2017-07-06 18:27:00 +00:00
|
|
|
|
2019-01-04 03:34:46 +00:00
|
|
|
if (previousUrl !== currentUrl
|
2017-08-15 22:21:58 +00:00
|
|
|
|
2017-12-14 17:02:32 +00:00
|
|
|
// XXX Refer to the implementation of loadURLObject: in
|
|
|
|
// ios/sdk/src/JitsiMeetView.m for further information.
|
2019-01-04 03:34:46 +00:00
|
|
|
|| previousTimestamp !== currentTimestamp) {
|
|
|
|
this._openURL(currentUrl || this._getDefaultURL());
|
2017-12-14 17:02:32 +00:00
|
|
|
}
|
|
|
|
});
|
2017-01-26 21:29:28 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 17:02:32 +00:00
|
|
|
/**
|
2018-07-11 09:42:43 +00:00
|
|
|
* Creates an extra {@link ReactElement}s to be added (unconditionaly)
|
|
|
|
* alongside the main element.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2018-07-11 09:42:43 +00:00
|
|
|
* @abstract
|
2016-10-05 14:36:59 +00:00
|
|
|
* @protected
|
2018-07-12 16:16:57 +00:00
|
|
|
* @returns {ReactElement}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2018-07-11 09:42:43 +00:00
|
|
|
_createExtraElement() {
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<OverlayContainer />
|
|
|
|
</Fragment>
|
|
|
|
);
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2018-07-11 09:42:43 +00:00
|
|
|
_createMainElement: (React$Element<*>, Object) => ?React$Element<*>;
|
2017-01-26 21:29:28 +00:00
|
|
|
|
2017-01-15 19:05:17 +00:00
|
|
|
/**
|
2017-07-26 19:40:34 +00:00
|
|
|
* Gets the default URL to be opened when this {@code App} mounts.
|
2017-01-15 19:05:17 +00:00
|
|
|
*
|
2017-02-18 16:02:31 +00:00
|
|
|
* @protected
|
2017-07-26 19:40:34 +00:00
|
|
|
* @returns {string} The default URL to be opened when this {@code App}
|
|
|
|
* mounts.
|
2017-01-15 19:05:17 +00:00
|
|
|
*/
|
|
|
|
_getDefaultURL() {
|
2018-07-11 08:57:07 +00:00
|
|
|
return getDefaultURL(this.state.store);
|
2017-01-15 19:05:17 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2018-11-08 12:25:02 +00:00
|
|
|
* Navigates this {@code AbstractApp} to (i.e. Opens) a specific URL.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2018-02-26 19:37:12 +00:00
|
|
|
* @param {Object|string} url - The URL to navigate this {@code AbstractApp}
|
2018-11-08 12:25:02 +00:00
|
|
|
* to (i.e. The URL to open).
|
2016-10-05 14:36:59 +00:00
|
|
|
* @protected
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_openURL(url) {
|
2018-07-10 14:42:22 +00:00
|
|
|
this.state.store.dispatch(appNavigate(toURLString(url)));
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
}
|