2017-04-14 16:48:40 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-01-15 04:05:56 +00:00
|
|
|
import { isRoomValid } from '../base/conference';
|
2017-04-14 16:48:40 +00:00
|
|
|
import { Platform, RouteRegistry } from '../base/react';
|
2017-01-15 04:05:56 +00:00
|
|
|
import { Conference } from '../conference';
|
2017-04-14 16:48:40 +00:00
|
|
|
import {
|
|
|
|
NoMobileApp,
|
|
|
|
PluginRequiredBrowser,
|
|
|
|
UnsupportedDesktopBrowser,
|
|
|
|
UnsupportedMobileBrowser
|
|
|
|
} from '../unsupported-browser';
|
2017-01-15 04:05:56 +00:00
|
|
|
import { WelcomePage } from '../welcome';
|
|
|
|
|
2017-04-14 16:48:40 +00:00
|
|
|
declare var APP: Object;
|
|
|
|
declare var interfaceConfig: Object;
|
|
|
|
declare var loggingConfig: Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of rules defining whether we should {@link _interceptComponent} to
|
|
|
|
* render.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} state - Object containing current Redux state.
|
|
|
|
* @returns {ReactElement|void}
|
|
|
|
* @type {Function[]}
|
|
|
|
*/
|
|
|
|
const _INTERCEPT_COMPONENT_RULES = [
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This rule describes case when user opens application using mobile
|
|
|
|
* browser. In order to promote the app, we choose to suggest the mobile
|
|
|
|
* app even if the browser supports the app (e.g. Google Chrome with
|
|
|
|
* WebRTC support on Android).
|
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state of the app.
|
|
|
|
* @returns {UnsupportedMobileBrowser|void} If the rule is satisfied then
|
|
|
|
* we should intercept existing component by UnsupportedMobileBrowser.
|
|
|
|
*/
|
|
|
|
() => {
|
|
|
|
const OS = Platform.OS;
|
|
|
|
|
|
|
|
if (OS === 'android' || OS === 'ios') {
|
|
|
|
const mobileAppPromo
|
|
|
|
= typeof interfaceConfig === 'object'
|
|
|
|
&& interfaceConfig.MOBILE_APP_PROMO;
|
|
|
|
|
|
|
|
return (
|
|
|
|
typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
|
|
|
|
? UnsupportedMobileBrowser
|
|
|
|
: NoMobileApp);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
state => {
|
|
|
|
const { webRTCReady } = state['features/base/lib-jitsi-meet'];
|
|
|
|
|
|
|
|
switch (typeof webRTCReady) {
|
|
|
|
case 'boolean':
|
|
|
|
if (webRTCReady === false) {
|
|
|
|
return UnsupportedDesktopBrowser;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'undefined':
|
|
|
|
// If webRTCReady is not set, then we cannot use it to take a
|
|
|
|
// decision.
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return PluginRequiredBrowser;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
2016-12-14 12:09:29 +00:00
|
|
|
|
2016-12-27 16:03:30 +00:00
|
|
|
/**
|
|
|
|
* Determines which route is to be rendered in order to depict a specific Redux
|
|
|
|
* store.
|
|
|
|
*
|
|
|
|
* @param {(Object|Function)} stateOrGetState - Redux state or Regux getState()
|
|
|
|
* method.
|
|
|
|
* @returns {Route}
|
|
|
|
*/
|
2017-04-14 16:48:40 +00:00
|
|
|
export function _getRouteToRender(stateOrGetState: Object | Function) {
|
2016-12-27 16:03:30 +00:00
|
|
|
const state
|
|
|
|
= typeof stateOrGetState === 'function'
|
|
|
|
? stateOrGetState()
|
|
|
|
: stateOrGetState;
|
|
|
|
|
2017-01-19 15:47:22 +00:00
|
|
|
// If mobile browser page was shown, there is no need to show it again.
|
2017-01-18 12:21:30 +00:00
|
|
|
const { room } = state['features/base/conference'];
|
|
|
|
const component = isRoomValid(room) ? Conference : WelcomePage;
|
2017-01-19 15:47:22 +00:00
|
|
|
const route = RouteRegistry.getRouteByComponent(component);
|
2016-12-27 16:03:30 +00:00
|
|
|
|
2017-01-20 14:20:20 +00:00
|
|
|
// Intercepts route components if any of component interceptor rules
|
|
|
|
// is satisfied.
|
2017-04-14 16:48:40 +00:00
|
|
|
route.component = _interceptComponent(state, component);
|
2016-12-27 16:03:30 +00:00
|
|
|
|
2017-01-18 12:21:30 +00:00
|
|
|
return route;
|
|
|
|
}
|
|
|
|
|
2017-04-14 16:48:40 +00:00
|
|
|
/**
|
|
|
|
* Intercepts route components based on a {@link _INTERCEPT_COMPONENT_RULES}.
|
|
|
|
*
|
|
|
|
* @param {Object|Function} stateOrGetState - Either Redux state object or
|
|
|
|
* getState() function.
|
|
|
|
* @param {ReactElement} component - Current route component to render.
|
|
|
|
* @private
|
|
|
|
* @returns {ReactElement} If any of the pre-defined rules is satisfied, returns
|
|
|
|
* intercepted component.
|
|
|
|
*/
|
|
|
|
function _interceptComponent(
|
|
|
|
stateOrGetState: Object,
|
|
|
|
component: ReactElement<*>) {
|
|
|
|
let result;
|
|
|
|
const state
|
|
|
|
= typeof stateOrGetState === 'function'
|
|
|
|
? stateOrGetState()
|
|
|
|
: stateOrGetState;
|
|
|
|
|
|
|
|
for (const rule of _INTERCEPT_COMPONENT_RULES) {
|
|
|
|
result = rule(state);
|
|
|
|
if (result) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result || component;
|
|
|
|
}
|