diff --git a/react/features/app/functions.web.js b/react/features/app/functions.web.js index 835620358..23b2402ef 100644 --- a/react/features/app/functions.web.js +++ b/react/features/app/functions.web.js @@ -1,10 +1,17 @@ -/* global APP, loggingConfig */ +/* @flow */ + +import Logger from 'jitsi-meet-logger'; import { isRoomValid } from '../base/conference'; import JitsiMeetJS from '../base/lib-jitsi-meet'; -import { RouteRegistry } from '../base/react'; -import { interceptComponent } from '../base/util'; +import { Platform, RouteRegistry } from '../base/react'; import { Conference } from '../conference'; +import { + NoMobileApp, + PluginRequiredBrowser, + UnsupportedDesktopBrowser, + UnsupportedMobileBrowser +} from '../unsupported-browser'; import { WelcomePage } from '../welcome'; import URLProcessor from '../../../modules/config/URLProcessor'; @@ -13,7 +20,65 @@ import KeyboardShortcut import getTokenData from '../../../modules/tokendata/TokenData'; import JitsiMeetLogStorage from '../../../modules/util/JitsiMeetLogStorage'; -const Logger = require('jitsi-meet-logger'); +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; + } + } +]; export { _parseURIString } from './functions.native'; @@ -25,7 +90,7 @@ export { _parseURIString } from './functions.native'; * method. * @returns {Route} */ -export function _getRouteToRender(stateOrGetState) { +export function _getRouteToRender(stateOrGetState: Object | Function) { const state = typeof stateOrGetState === 'function' ? stateOrGetState() @@ -38,7 +103,7 @@ export function _getRouteToRender(stateOrGetState) { // Intercepts route components if any of component interceptor rules // is satisfied. - route.component = interceptComponent(state, component); + route.component = _interceptComponent(state, component); return route; } @@ -118,3 +183,32 @@ function _initLogging() { JitsiMeetJS.addGlobalLogTransport(APP.logCollector); } } + +/** + * 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; +} diff --git a/react/features/base/util/index.js b/react/features/base/util/index.js index a98be1d9e..2fe772beb 100644 --- a/react/features/base/util/index.js +++ b/react/features/base/util/index.js @@ -1,4 +1,3 @@ -export * from './interceptComponent'; export * from './loadScript'; export * from './randomUtil'; export * from './roomnameGenerator'; diff --git a/react/features/base/util/interceptComponent.js b/react/features/base/util/interceptComponent.js deleted file mode 100644 index 860556eef..000000000 --- a/react/features/base/util/interceptComponent.js +++ /dev/null @@ -1,98 +0,0 @@ -/* @flow */ - -import { Platform } from '../react'; -import { - NoMobileApp, - PluginRequiredBrowser, - UnsupportedDesktopBrowser, - UnsupportedMobileBrowser -} from '../../unsupported-browser'; - -declare var APP: Object; -declare var interfaceConfig: Object; -declare var JitsiMeetJS: Object; - -/** - * Array of rules defining whether we should intercept component to render - * or not. - * - * @private - * @param {Object} state - Object containing current Redux state. - * @returns {ReactElement|void} - * @type {Function[]} - */ -const _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; - } - } -]; - -/** - * Utility method that responsible for intercepting of route components based on - * the set of defined rules. - * - * @param {Object|Function} stateOrGetState - Either Redux state object or - * getState() function. - * @param {ReactElement} component - Current route component to render. - * @returns {ReactElement} If any of rules is satisfied returns intercepted - * component. - */ -export function interceptComponent( - stateOrGetState: Object, - component: ReactElement<*>) { - let result; - const state - = typeof stateOrGetState === 'function' - ? stateOrGetState() - : stateOrGetState; - - for (const rule of _RULES) { - result = rule(state); - if (result) { - break; - } - } - - return result || component; -}