2017-02-07 14:45:51 +00:00
|
|
|
/* @flow */
|
2017-02-02 16:01:03 +00:00
|
|
|
|
2017-01-20 14:20:20 +00:00
|
|
|
import { Platform } from '../react';
|
2017-02-02 16:01:03 +00:00
|
|
|
import {
|
2017-02-03 12:51:39 +00:00
|
|
|
NoMobileApp,
|
2017-02-02 16:01:03 +00:00
|
|
|
PluginRequiredBrowser,
|
2017-02-03 12:51:39 +00:00
|
|
|
UnsupportedDesktopBrowser,
|
2017-02-02 16:01:03 +00:00
|
|
|
UnsupportedMobileBrowser
|
|
|
|
} from '../../unsupported-browser';
|
2017-01-20 14:20:20 +00:00
|
|
|
|
2017-02-07 14:45:51 +00:00
|
|
|
declare var APP: Object;
|
|
|
|
declare var interfaceConfig: Object;
|
2017-02-21 22:24:47 +00:00
|
|
|
declare var JitsiMeetJS: Object;
|
2017-02-07 14:45:51 +00:00
|
|
|
|
2017-01-20 14:20:20 +00:00
|
|
|
/**
|
|
|
|
* Array of rules defining whether we should intercept component to render
|
|
|
|
* or not.
|
|
|
|
*
|
2017-02-02 15:46:09 +00:00
|
|
|
* @private
|
2017-02-14 22:28:15 +00:00
|
|
|
* @param {Object} state - Object containing current Redux state.
|
2017-01-20 14:20:20 +00:00
|
|
|
* @returns {ReactElement|void}
|
2017-02-02 15:46:09 +00:00
|
|
|
* @type {Function[]}
|
2017-01-20 14:20:20 +00:00
|
|
|
*/
|
2017-02-02 15:46:09 +00:00
|
|
|
const _RULES = [
|
2017-01-20 14:20:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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).
|
|
|
|
*
|
2017-02-14 22:28:15 +00:00
|
|
|
* @param {Object} state - Redux state of the app.
|
2017-01-25 22:11:44 +00:00
|
|
|
* @returns {UnsupportedMobileBrowser|void} If the rule is satisfied then
|
|
|
|
* we should intercept existing component by UnsupportedMobileBrowser.
|
2017-01-20 14:20:20 +00:00
|
|
|
*/
|
2017-01-28 03:29:09 +00:00
|
|
|
() => {
|
2017-01-20 14:20:20 +00:00
|
|
|
const OS = Platform.OS;
|
|
|
|
|
2017-01-28 03:29:09 +00:00
|
|
|
if (OS === 'android' || OS === 'ios') {
|
2017-02-03 12:51:39 +00:00
|
|
|
return (
|
|
|
|
interfaceConfig.MOBILE_APP_ENABLED
|
|
|
|
? UnsupportedMobileBrowser
|
|
|
|
: NoMobileApp);
|
2017-01-20 14:20:20 +00:00
|
|
|
}
|
2017-02-02 16:01:03 +00:00
|
|
|
},
|
2017-02-14 22:28:15 +00:00
|
|
|
state => {
|
2017-02-21 22:24:47 +00:00
|
|
|
switch (state['features/unsupported-browser'].name) {
|
|
|
|
case 'WEBRTC_NOT_READY':
|
|
|
|
return PluginRequiredBrowser;
|
2017-02-02 16:01:03 +00:00
|
|
|
|
2017-02-21 22:24:47 +00:00
|
|
|
case 'WEBRTC_NOT_SUPPORTED':
|
2017-02-14 22:28:15 +00:00
|
|
|
return UnsupportedDesktopBrowser;
|
|
|
|
}
|
2017-01-20 14:20:20 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2017-02-07 14:45:51 +00:00
|
|
|
* @param {ReactElement} component - Current route component to render.
|
2017-01-20 14:20:20 +00:00
|
|
|
* @returns {ReactElement} If any of rules is satisfied returns intercepted
|
|
|
|
* component.
|
|
|
|
*/
|
2017-02-07 14:45:51 +00:00
|
|
|
export function interceptComponent(
|
|
|
|
stateOrGetState: Object,
|
|
|
|
component: ReactElement<*>) {
|
2017-01-20 14:20:20 +00:00
|
|
|
let result;
|
|
|
|
const state
|
|
|
|
= typeof stateOrGetState === 'function'
|
2017-01-25 22:11:44 +00:00
|
|
|
? stateOrGetState()
|
|
|
|
: stateOrGetState;
|
2017-01-20 14:20:20 +00:00
|
|
|
|
2017-02-02 15:46:09 +00:00
|
|
|
for (const rule of _RULES) {
|
2017-01-20 14:20:20 +00:00
|
|
|
result = rule(state);
|
|
|
|
if (result) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-07 14:45:51 +00:00
|
|
|
return result || component;
|
2017-01-20 14:20:20 +00:00
|
|
|
}
|