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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 './getRouteToRender';
  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. // eslint-disable-next-line no-unused-vars
  38. state => {
  39. const OS = Platform.OS;
  40. if (OS === 'android' || OS === 'ios') {
  41. const mobileAppPromo
  42. = typeof interfaceConfig === 'object'
  43. && interfaceConfig.MOBILE_APP_PROMO;
  44. return (
  45. typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
  46. ? UnsupportedMobileBrowser
  47. : NoMobileApp);
  48. }
  49. },
  50. state => {
  51. const { webRTCReady } = state['features/base/lib-jitsi-meet'];
  52. switch (typeof webRTCReady) {
  53. case 'boolean':
  54. if (webRTCReady === false) {
  55. return UnsupportedDesktopBrowser;
  56. }
  57. break;
  58. case 'undefined':
  59. // If webRTCReady is not set, then we cannot base a decision on it.
  60. break;
  61. default:
  62. return PluginRequiredBrowser;
  63. }
  64. }
  65. ];
  66. /**
  67. * Determines which route is to be rendered in order to depict a specific redux
  68. * store.
  69. *
  70. * @param {(Object|Function)} stateOrGetState - The redux state or
  71. * {@link getState} function.
  72. * @returns {Route}
  73. */
  74. export function _getRouteToRender(stateOrGetState: Object | Function) {
  75. const route = _super_getRouteToRender(stateOrGetState);
  76. // Intercepts route components if any of component interceptor rules is
  77. // satisfied.
  78. route.component = _interceptComponent(stateOrGetState, route.component);
  79. return route;
  80. }
  81. /**
  82. * Intercepts route components based on a {@link _INTERCEPT_COMPONENT_RULES}.
  83. *
  84. * @param {Object|Function} stateOrGetState - The redux state or
  85. * {@link getState} function.
  86. * @param {ReactElement} component - Current route component to render.
  87. * @private
  88. * @returns {ReactElement} If any of the pre-defined rules is satisfied, returns
  89. * intercepted component.
  90. */
  91. function _interceptComponent(
  92. stateOrGetState: Object | Function,
  93. component: React$Element<*>) {
  94. let result;
  95. const state = toState(stateOrGetState);
  96. for (const rule of _INTERCEPT_COMPONENT_RULES) {
  97. result = rule(state);
  98. if (result) {
  99. break;
  100. }
  101. }
  102. return result || component;
  103. }
  104. /**
  105. * Returns application name.
  106. *
  107. * @returns {string} The application name.
  108. */
  109. export function getName() {
  110. return interfaceConfig.APP_NAME;
  111. }