2016-10-05 14:36:59 +00:00
|
|
|
import React, { Component } from 'react';
|
2017-03-01 02:55:12 +00:00
|
|
|
import { I18nextProvider } from 'react-i18next';
|
2017-01-16 00:28:02 +00:00
|
|
|
import { Provider } from 'react-redux';
|
2017-01-26 21:29:28 +00:00
|
|
|
import { compose, createStore } from 'redux';
|
|
|
|
import Thunk from 'redux-thunk';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-03-01 02:55:12 +00:00
|
|
|
import { i18next } from '../../base/i18n';
|
2016-10-05 14:36:59 +00:00
|
|
|
import {
|
|
|
|
localParticipantJoined,
|
|
|
|
localParticipantLeft
|
|
|
|
} from '../../base/participants';
|
2017-01-29 01:56:35 +00:00
|
|
|
import { RouteRegistry } from '../../base/react';
|
2017-01-26 21:29:28 +00:00
|
|
|
import { MiddlewareRegistry, ReducerRegistry } from '../../base/redux';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
appNavigate,
|
|
|
|
appWillMount,
|
|
|
|
appWillUnmount
|
|
|
|
} from '../actions';
|
|
|
|
|
2017-03-07 16:50:17 +00:00
|
|
|
declare var APP: Object;
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Base (abstract) class for main App component.
|
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
*/
|
|
|
|
export class AbstractApp extends Component {
|
2016-12-01 01:52:39 +00:00
|
|
|
/**
|
|
|
|
* AbstractApp component's property types.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
static propTypes = {
|
|
|
|
config: React.PropTypes.object,
|
|
|
|
store: React.PropTypes.object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The URL, if any, with which the app was launched.
|
|
|
|
*/
|
|
|
|
url: React.PropTypes.string
|
2017-01-25 22:11:44 +00:00
|
|
|
}
|
2016-12-01 01:52:39 +00:00
|
|
|
|
2017-01-16 00:28:02 +00:00
|
|
|
/**
|
2017-02-05 02:29:24 +00:00
|
|
|
* Initializes a new AbstractApp instance.
|
2017-01-16 00:28:02 +00:00
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only React Component props with which
|
|
|
|
* the new instance is to be initialized.
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
/**
|
2017-01-26 21:29:28 +00:00
|
|
|
* The Route rendered by this AbstractApp.
|
2017-01-16 00:28:02 +00:00
|
|
|
*
|
|
|
|
* @type {Route}
|
|
|
|
*/
|
2017-01-26 21:29:28 +00:00
|
|
|
route: undefined,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Redux store used by this AbstractApp.
|
|
|
|
*
|
|
|
|
* @type {Store}
|
|
|
|
*/
|
|
|
|
store: this._maybeCreateStore(props)
|
2017-01-16 00:28:02 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Init lib-jitsi-meet and create local participant when component is going
|
|
|
|
* to be mounted.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentWillMount() {
|
2017-01-26 21:29:28 +00:00
|
|
|
const dispatch = this._getStore().dispatch;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
dispatch(appWillMount(this));
|
|
|
|
|
2017-03-07 16:50:17 +00:00
|
|
|
// FIXME I believe it makes more sense for a middleware to dispatch
|
|
|
|
// localParticipantJoined on APP_WILL_MOUNT because the order of actions
|
|
|
|
// is important, not the call site. Moreover, we've got localParticipant
|
|
|
|
// business logic in the React Component (i.e. UI) AbstractApp now.
|
|
|
|
let localParticipant;
|
|
|
|
|
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
localParticipant = {
|
|
|
|
avatarID: APP.settings.getAvatarId(),
|
|
|
|
avatarURL: APP.settings.getAvatarUrl(),
|
|
|
|
email: APP.settings.getEmail()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
dispatch(localParticipantJoined(localParticipant));
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-02-18 16:02:31 +00:00
|
|
|
// If a URL was explicitly specified to this React Component, then open
|
|
|
|
// it; otherwise, use a default.
|
|
|
|
this._openURL(this.props.url || this._getDefaultURL());
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 21:29:28 +00:00
|
|
|
/**
|
|
|
|
* Notifies this mounted React Component that it will receive new props.
|
|
|
|
* Makes sure that this AbstractApp has a Redux store to use.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @param {Object} nextProps - The read-only React Component props that this
|
|
|
|
* instance will receive.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
// The consumer of this AbstractApp did not provide a Redux store.
|
|
|
|
if (typeof nextProps.store === 'undefined'
|
|
|
|
|
|
|
|
// The consumer of this AbstractApp did provide a Redux store
|
|
|
|
// before. Which means that the consumer changed their mind. In
|
|
|
|
// such a case this instance should create its own internal
|
|
|
|
// Redux store. If the consumer did not provide a Redux store
|
|
|
|
// before, then this instance is using its own internal Redux
|
|
|
|
// store already.
|
|
|
|
&& typeof this.props.store !== 'undefined') {
|
|
|
|
this.setState({
|
|
|
|
store: this._maybeCreateStore(nextProps)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Dispose lib-jitsi-meet and remove local participant when component is
|
|
|
|
* going to be unmounted.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentWillUnmount() {
|
2017-01-26 21:29:28 +00:00
|
|
|
const dispatch = this._getStore().dispatch;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
dispatch(localParticipantLeft());
|
|
|
|
|
|
|
|
dispatch(appWillUnmount(this));
|
|
|
|
}
|
|
|
|
|
2017-03-02 03:33:49 +00:00
|
|
|
/**
|
|
|
|
* Gets a Location object from the window with information about the current
|
|
|
|
* location of the document. Explicitly defined to allow extenders to
|
|
|
|
* override because React Native does not usually have a location property
|
|
|
|
* on its window unless debugging remotely in which case the browser that is
|
|
|
|
* the remote debugger will provide a location property on the window.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @returns {Location} A Location object with information about the current
|
|
|
|
* location of the document.
|
|
|
|
*/
|
|
|
|
getWindowLocation() {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2017-01-16 00:28:02 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const route = this.state.route;
|
|
|
|
|
|
|
|
if (route) {
|
|
|
|
return (
|
2017-03-01 02:55:12 +00:00
|
|
|
<I18nextProvider i18n = { i18next }>
|
2017-02-22 19:49:39 +00:00
|
|
|
<Provider store = { this._getStore() }>
|
|
|
|
{
|
|
|
|
this._createElement(route.component)
|
|
|
|
}
|
|
|
|
</Provider>
|
|
|
|
</I18nextProvider>
|
2017-01-16 00:28:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Create a ReactElement from the specified component, the specified props
|
|
|
|
* and the props of this AbstractApp which are suitable for propagation to
|
|
|
|
* the children of this Component.
|
|
|
|
*
|
|
|
|
* @param {Component} component - The component from which the ReactElement
|
|
|
|
* is to be created.
|
|
|
|
* @param {Object} props - The read-only React Component props with which
|
|
|
|
* the ReactElement is to be initialized.
|
|
|
|
* @returns {ReactElement}
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
_createElement(component, props) {
|
|
|
|
/* eslint-disable no-unused-vars, lines-around-comment */
|
|
|
|
const {
|
|
|
|
// Don't propagate the config prop(erty) because the config is
|
|
|
|
// stored inside the Redux state and, thus, is visible to the
|
|
|
|
// children anyway.
|
|
|
|
config,
|
|
|
|
// Don't propagate the dispatch and store props because they usually
|
|
|
|
// come from react-redux and programmers don't really expect them to
|
|
|
|
// be inherited but rather explicitly connected.
|
|
|
|
dispatch, // eslint-disable-line react/prop-types
|
|
|
|
store,
|
|
|
|
// The url property was introduced to be consumed entirely by
|
|
|
|
// AbstractApp.
|
|
|
|
url,
|
|
|
|
// The remaining props, if any, are considered suitable for
|
|
|
|
// propagation to the children of this Component.
|
|
|
|
...thisProps
|
|
|
|
} = this.props;
|
|
|
|
/* eslint-enable no-unused-vars, lines-around-comment */
|
|
|
|
|
|
|
|
// eslint-disable-next-line object-property-newline
|
|
|
|
return React.createElement(component, { ...thisProps, ...props });
|
|
|
|
}
|
|
|
|
|
2017-01-26 21:29:28 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new Redux store instance suitable for use by
|
|
|
|
* this AbstractApp.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {Store} - A new Redux store instance suitable for use by
|
|
|
|
* this AbstractApp.
|
|
|
|
*/
|
|
|
|
_createStore() {
|
|
|
|
// Create combined reducer from all reducers in ReducerRegistry.
|
|
|
|
const reducer = ReducerRegistry.combineReducers();
|
|
|
|
|
|
|
|
// Apply all registered middleware from the MiddlewareRegistry and
|
|
|
|
// additional 3rd party middleware:
|
|
|
|
// - Thunk - allows us to dispatch async actions easily. For more info
|
|
|
|
// @see https://github.com/gaearon/redux-thunk.
|
|
|
|
let middleware = MiddlewareRegistry.applyMiddleware(Thunk);
|
|
|
|
|
|
|
|
// Try to enable Redux DevTools Chrome extension in order to make it
|
|
|
|
// available for the purposes of facilitating development.
|
|
|
|
let devToolsExtension;
|
|
|
|
|
|
|
|
if (typeof window === 'object'
|
|
|
|
&& (devToolsExtension = window.devToolsExtension)) {
|
|
|
|
middleware = compose(middleware, devToolsExtension());
|
|
|
|
}
|
|
|
|
|
|
|
|
return createStore(reducer, middleware);
|
|
|
|
}
|
|
|
|
|
2017-01-15 19:05:17 +00:00
|
|
|
/**
|
|
|
|
* Gets the default URL to be opened when this App mounts.
|
|
|
|
*
|
2017-02-18 16:02:31 +00:00
|
|
|
* @protected
|
2017-01-15 19:05:17 +00:00
|
|
|
* @returns {string} The default URL to be opened when this App mounts.
|
|
|
|
*/
|
|
|
|
_getDefaultURL() {
|
|
|
|
// If the execution environment provides a Location abstraction, then
|
|
|
|
// this App at already at that location but it must be made aware of the
|
|
|
|
// fact.
|
2017-03-02 03:33:49 +00:00
|
|
|
const windowLocation = this.getWindowLocation();
|
2017-01-15 19:05:17 +00:00
|
|
|
|
|
|
|
if (windowLocation) {
|
2017-02-18 16:02:31 +00:00
|
|
|
const href = windowLocation.toString();
|
|
|
|
|
|
|
|
if (href) {
|
|
|
|
return href;
|
2017-01-15 19:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// By default, open the domain configured in the configuration file
|
|
|
|
// which may be the domain at which the whole server infrastructure is
|
|
|
|
// deployed.
|
|
|
|
const config = this.props.config;
|
|
|
|
|
|
|
|
if (typeof config === 'object') {
|
|
|
|
const hosts = config.hosts;
|
|
|
|
|
|
|
|
if (typeof hosts === 'object') {
|
|
|
|
const domain = hosts.domain;
|
|
|
|
|
|
|
|
if (domain) {
|
|
|
|
return `https://${domain}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'https://meet.jit.si';
|
|
|
|
}
|
|
|
|
|
2017-01-26 21:29:28 +00:00
|
|
|
/**
|
|
|
|
* Gets the Redux store used by this AbstractApp.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {Store} - The Redux store used by this AbstractApp.
|
|
|
|
*/
|
|
|
|
_getStore() {
|
|
|
|
let store = this.state.store;
|
|
|
|
|
|
|
|
if (typeof store === 'undefined') {
|
|
|
|
store = this.props.store;
|
|
|
|
}
|
|
|
|
|
|
|
|
return store;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a Redux store to be used by this AbstractApp if such as store is
|
|
|
|
* not defined by the consumer of this AbstractApp through its
|
|
|
|
* read-only React Component props.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only React Component props that will
|
|
|
|
* eventually be received by this AbstractApp.
|
|
|
|
* @private
|
|
|
|
* @returns {Store} - The Redux store to be used by this AbstractApp.
|
|
|
|
*/
|
|
|
|
_maybeCreateStore(props) {
|
|
|
|
// The application Jitsi Meet is architected with Redux. However, I do
|
|
|
|
// not want consumers of the App React Component to be forced into
|
|
|
|
// dealing with Redux. If the consumer did not provide an external Redux
|
|
|
|
// store, utilize an internal Redux store.
|
|
|
|
let store = props.store;
|
|
|
|
|
|
|
|
if (typeof store === 'undefined') {
|
|
|
|
store = this._createStore();
|
2017-01-31 20:58:48 +00:00
|
|
|
|
|
|
|
// This is temporary workaround to be able to dispatch actions from
|
|
|
|
// non-reactified parts of the code (conference.js for example).
|
|
|
|
// Don't use in the react code!!!
|
|
|
|
// FIXME: remove when the reactification is finished!
|
2017-02-20 09:36:46 +00:00
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
APP.store = store;
|
|
|
|
}
|
2017-01-26 21:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return store;
|
|
|
|
}
|
|
|
|
|
2017-01-16 00:28:02 +00:00
|
|
|
/**
|
|
|
|
* Navigates to a specific Route.
|
|
|
|
*
|
|
|
|
* @param {Route} route - The Route to which to navigate.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_navigate(route) {
|
2017-01-25 22:11:44 +00:00
|
|
|
if (RouteRegistry.areRoutesEqual(this.state.route, route)) {
|
|
|
|
return;
|
2017-01-19 15:47:22 +00:00
|
|
|
}
|
2017-01-25 22:11:44 +00:00
|
|
|
|
|
|
|
let nextState = {
|
|
|
|
...this.state,
|
|
|
|
route
|
|
|
|
};
|
|
|
|
|
|
|
|
// The Web App was using react-router so it utilized react-router's
|
|
|
|
// onEnter. During the removal of react-router, modifications were
|
|
|
|
// minimized by preserving the onEnter interface:
|
|
|
|
// (1) Router would provide its nextState to the Route's onEnter. As the
|
|
|
|
// role of Router is now this AbstractApp, provide its nextState.
|
|
|
|
// (2) A replace function would be provided to the Route in case it
|
|
|
|
// chose to redirect to another path.
|
|
|
|
this._onRouteEnter(route, nextState, pathname => {
|
2017-02-05 02:29:24 +00:00
|
|
|
this._openURL(pathname);
|
2017-01-25 22:11:44 +00:00
|
|
|
|
|
|
|
// Do not proceed with the route because it chose to redirect to
|
|
|
|
// another path.
|
|
|
|
nextState = undefined;
|
|
|
|
});
|
|
|
|
|
|
|
|
nextState && this.setState(nextState);
|
2017-01-16 00:28:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies this App that a specific Route is about to be rendered.
|
|
|
|
*
|
|
|
|
* @param {Route} route - The Route that is about to be rendered.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onRouteEnter(route, ...args) {
|
|
|
|
// Notify the route that it is about to be entered.
|
|
|
|
const onEnter = route.onEnter;
|
|
|
|
|
|
|
|
if (typeof onEnter === 'function') {
|
|
|
|
onEnter(...args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Navigates this AbstractApp to (i.e. opens) a specific URL.
|
|
|
|
*
|
|
|
|
* @param {string} url - The URL to which to navigate this AbstractApp (i.e.
|
|
|
|
* the URL to open).
|
|
|
|
* @protected
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_openURL(url) {
|
2017-01-26 21:29:28 +00:00
|
|
|
this._getStore().dispatch(appNavigate(url));
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
}
|