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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. /**
  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 state
  74. = typeof stateOrGetState === 'function'
  75. ? stateOrGetState()
  76. : stateOrGetState;
  77. // If mobile browser page was shown, there is no need to show it again.
  78. const { room } = state['features/base/conference'];
  79. const component = isRoomValid(room) ? Conference : WelcomePage;
  80. const route = RouteRegistry.getRouteByComponent(component);
  81. // Intercepts route components if any of component interceptor rules
  82. // is satisfied.
  83. route.component = _interceptComponent(state, component);
  84. return route;
  85. }
  86. /**
  87. * Intercepts route components based on a {@link _INTERCEPT_COMPONENT_RULES}.
  88. *
  89. * @param {Object|Function} stateOrGetState - Either Redux state object or
  90. * getState() function.
  91. * @param {ReactElement} component - Current route component to render.
  92. * @private
  93. * @returns {ReactElement} If any of the pre-defined rules is satisfied, returns
  94. * intercepted component.
  95. */
  96. function _interceptComponent(
  97. stateOrGetState: Object,
  98. component: ReactElement<*>) {
  99. let result;
  100. const state
  101. = typeof stateOrGetState === 'function'
  102. ? stateOrGetState()
  103. : stateOrGetState;
  104. for (const rule of _INTERCEPT_COMPONENT_RULES) {
  105. result = rule(state);
  106. if (result) {
  107. break;
  108. }
  109. }
  110. return result || component;
  111. }