jitsi-meet/react/features/app/functions.web.js
Lyubo Marinov 0b8c12de0e Simplify route navigation
I see it as the first step in simplifying the route navigate of the
JavaScript app by removing BlankWelcomePage from _getRouteToRender. From
a faraway point of view, the app is at the route at which it is not in a
conference. Historically, the route was known as the Welcome page. But
mobile complicated the route by saying that actually it may not want to
see the room name input and join button.

Additionally, I renamed BlankWelcomePage to BlankPage because I don't
think of it as a WelcomePage alternative but rather as a more generic
BlankPage which may be utilized elsewhere in the future.

I plan for the next steps to:
* Merge Entryway, _interceptComponent, and _getRouteToRender in one
React Component rendered by AbstractApp so that the whole logic is in
one file;
* Get rid of RouteRegistry and routes.
2017-08-22 16:38:14 -05:00

121 lines
3.4 KiB
JavaScript

/* @flow */
import { Platform } from '../base/react';
import {
NoMobileApp,
PluginRequiredBrowser,
UnsupportedDesktopBrowser,
UnsupportedMobileBrowser
} from '../unsupported-browser';
import {
// eslint-disable-next-line camelcase
_getRouteToRender as _super_getRouteToRender
} from './functions.native';
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 base a decision on it.
break;
default:
return PluginRequiredBrowser;
}
}
];
/**
* 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}
*/
export function _getRouteToRender(stateOrGetState: Object | Function) {
const route = _super_getRouteToRender(stateOrGetState);
// Intercepts route components if any of component interceptor rules is
// satisfied.
route.component = _interceptComponent(stateOrGetState, route.component);
return route;
}
/**
* 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;
}