Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

functions.web.js 3.4KB

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