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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 and is attempting to join a conference. In order to promote the
  30. * app, we choose to suggest the mobile app even if the browser supports the
  31. * app (e.g. Google Chrome with 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. const { room } = state['features/base/conference'];
  41. const isUsingMobileBrowser = OS === 'android' || OS === 'ios';
  42. /**
  43. * Checking for presence of a room is done so that interception only
  44. * occurs when trying to enter a meeting but pages outside of meeting,
  45. * like WelcomePage, can still display.
  46. */
  47. if (room && isUsingMobileBrowser) {
  48. const mobileAppPromo
  49. = typeof interfaceConfig === 'object'
  50. && interfaceConfig.MOBILE_APP_PROMO;
  51. return (
  52. typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
  53. ? UnsupportedMobileBrowser
  54. : NoMobileApp);
  55. }
  56. },
  57. state => {
  58. const { webRTCReady } = state['features/base/lib-jitsi-meet'];
  59. switch (typeof webRTCReady) {
  60. case 'boolean':
  61. if (webRTCReady === false) {
  62. return UnsupportedDesktopBrowser;
  63. }
  64. break;
  65. case 'undefined':
  66. // If webRTCReady is not set, then we cannot base a decision on it.
  67. break;
  68. default:
  69. return PluginRequiredBrowser;
  70. }
  71. }
  72. ];
  73. /**
  74. * Determines which route is to be rendered in order to depict a specific redux
  75. * store.
  76. *
  77. * @param {(Object|Function)} stateOrGetState - The redux state or
  78. * {@link getState} function.
  79. * @returns {Route}
  80. */
  81. export function _getRouteToRender(stateOrGetState: Object | Function) {
  82. const route = _super_getRouteToRender(stateOrGetState);
  83. // Intercepts route components if any of component interceptor rules is
  84. // satisfied.
  85. route.component = _interceptComponent(stateOrGetState, route.component);
  86. return route;
  87. }
  88. /**
  89. * Intercepts route components based on a {@link _INTERCEPT_COMPONENT_RULES}.
  90. *
  91. * @param {Object|Function} stateOrGetState - The redux state or
  92. * {@link getState} function.
  93. * @param {ReactElement} component - Current route component to render.
  94. * @private
  95. * @returns {ReactElement} If any of the pre-defined rules is satisfied, returns
  96. * intercepted component.
  97. */
  98. function _interceptComponent(
  99. stateOrGetState: Object | Function,
  100. component: React$Element<*>) {
  101. let result;
  102. const state = toState(stateOrGetState);
  103. for (const rule of _INTERCEPT_COMPONENT_RULES) {
  104. result = rule(state);
  105. if (result) {
  106. break;
  107. }
  108. }
  109. return result || component;
  110. }
  111. /**
  112. * Returns application name.
  113. *
  114. * @returns {string} The application name.
  115. */
  116. export function getName() {
  117. return interfaceConfig.APP_NAME;
  118. }