You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.web.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* @flow */
  2. import { Platform } from '../base/react';
  3. import { toState } from '../base/redux';
  4. import {
  5. NoMobileApp,
  6. PluginRequiredBrowser,
  7. UnsupportedDesktopBrowser,
  8. UnsupportedMobileBrowser
  9. } from '../unsupported-browser';
  10. import {
  11. // eslint-disable-next-line camelcase
  12. _getRouteToRender as _super_getRouteToRender
  13. } from './functions.native';
  14. declare var APP: Object;
  15. declare var interfaceConfig: Object;
  16. declare var loggingConfig: Object;
  17. /**
  18. * Array of rules defining whether we should {@link _interceptComponent} to
  19. * render.
  20. *
  21. * @private
  22. * @param {Object} state - Object containing current redux state.
  23. * @returns {ReactElement|void}
  24. * @type {Function[]}
  25. */
  26. const _INTERCEPT_COMPONENT_RULES = [
  27. /**
  28. * This rule describes case when user opens application using mobile
  29. * browser. In order to promote the app, we choose to suggest the mobile
  30. * app even if the browser supports the app (e.g. Google Chrome with
  31. * WebRTC support on Android).
  32. *
  33. * @param {Object} state - The redux state of the app.
  34. * @returns {UnsupportedMobileBrowser|void} If the rule is satisfied then
  35. * we should intercept existing component by UnsupportedMobileBrowser.
  36. */
  37. () => {
  38. const OS = Platform.OS;
  39. if (OS === 'android' || OS === 'ios') {
  40. const mobileAppPromo
  41. = typeof interfaceConfig === 'object'
  42. && interfaceConfig.MOBILE_APP_PROMO;
  43. return (
  44. typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
  45. ? UnsupportedMobileBrowser
  46. : NoMobileApp);
  47. }
  48. },
  49. state => {
  50. const { webRTCReady } = state['features/base/lib-jitsi-meet'];
  51. switch (typeof webRTCReady) {
  52. case 'boolean':
  53. if (webRTCReady === false) {
  54. return UnsupportedDesktopBrowser;
  55. }
  56. break;
  57. case 'undefined':
  58. // If webRTCReady is not set, then we cannot base a decision on it.
  59. break;
  60. default:
  61. return PluginRequiredBrowser;
  62. }
  63. }
  64. ];
  65. /**
  66. * Determines which route is to be rendered in order to depict a specific redux
  67. * store.
  68. *
  69. * @param {(Object|Function)} stateOrGetState - The redux state or
  70. * {@link getState} function.
  71. * @returns {Route}
  72. */
  73. export function _getRouteToRender(stateOrGetState: Object | Function) {
  74. const route = _super_getRouteToRender(stateOrGetState);
  75. // Intercepts route components if any of component interceptor rules is
  76. // satisfied.
  77. route.component = _interceptComponent(stateOrGetState, route.component);
  78. return route;
  79. }
  80. /**
  81. * Intercepts route components based on a {@link _INTERCEPT_COMPONENT_RULES}.
  82. *
  83. * @param {Object|Function} stateOrGetState - The redux state or
  84. * {@link getState} function.
  85. * @param {ReactElement} component - Current route component to render.
  86. * @private
  87. * @returns {ReactElement} If any of the pre-defined rules is satisfied, returns
  88. * intercepted component.
  89. */
  90. function _interceptComponent(
  91. stateOrGetState: Object | Function,
  92. component: ReactElement<*>) {
  93. let result;
  94. const state = toState(stateOrGetState);
  95. for (const rule of _INTERCEPT_COMPONENT_RULES) {
  96. result = rule(state);
  97. if (result) {
  98. break;
  99. }
  100. }
  101. return result || component;
  102. }