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

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