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.

interceptComponent.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* @flow */
  2. import { Platform } from '../react';
  3. import {
  4. NoMobileApp,
  5. PluginRequiredBrowser,
  6. UnsupportedDesktopBrowser,
  7. UnsupportedMobileBrowser
  8. } from '../../unsupported-browser';
  9. declare var APP: Object;
  10. declare var interfaceConfig: Object;
  11. declare var JitsiMeetJS: Object;
  12. /**
  13. * Array of rules defining whether we should intercept component to render
  14. * or not.
  15. *
  16. * @private
  17. * @param {Object} state - Object containing current Redux state.
  18. * @returns {ReactElement|void}
  19. * @type {Function[]}
  20. */
  21. const _RULES = [
  22. /**
  23. * This rule describes case when user opens application using mobile
  24. * browser. In order to promote the app, we choose to suggest the mobile
  25. * app even if the browser supports the app (e.g. Google Chrome with
  26. * WebRTC support on Android).
  27. *
  28. * @param {Object} state - Redux state of the app.
  29. * @returns {UnsupportedMobileBrowser|void} If the rule is satisfied then
  30. * we should intercept existing component by UnsupportedMobileBrowser.
  31. */
  32. () => {
  33. const OS = Platform.OS;
  34. if (OS === 'android' || OS === 'ios') {
  35. return (
  36. interfaceConfig.MOBILE_APP_ENABLED
  37. ? UnsupportedMobileBrowser
  38. : NoMobileApp);
  39. }
  40. },
  41. state => {
  42. const { webRTCReady } = state['features/base/lib-jitsi-meet'];
  43. switch (typeof webRTCReady) {
  44. case 'boolean':
  45. if (webRTCReady === false) {
  46. return UnsupportedDesktopBrowser;
  47. }
  48. break;
  49. case 'undefined':
  50. // If webRTCReady is not set, then we cannot use it to take a
  51. // decision.
  52. break;
  53. default:
  54. return PluginRequiredBrowser;
  55. }
  56. }
  57. ];
  58. /**
  59. * Utility method that responsible for intercepting of route components based on
  60. * the set of defined rules.
  61. *
  62. * @param {Object|Function} stateOrGetState - Either Redux state object or
  63. * getState() function.
  64. * @param {ReactElement} component - Current route component to render.
  65. * @returns {ReactElement} If any of rules is satisfied returns intercepted
  66. * component.
  67. */
  68. export function interceptComponent(
  69. stateOrGetState: Object,
  70. component: ReactElement<*>) {
  71. let result;
  72. const state
  73. = typeof stateOrGetState === 'function'
  74. ? stateOrGetState()
  75. : stateOrGetState;
  76. for (const rule of _RULES) {
  77. result = rule(state);
  78. if (result) {
  79. break;
  80. }
  81. }
  82. return result || component;
  83. }