您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

interceptComponent.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. switch (state['features/unsupported-browser'].name) {
  43. case 'WEBRTC_NOT_READY':
  44. return PluginRequiredBrowser;
  45. case 'WEBRTC_NOT_SUPPORTED':
  46. return UnsupportedDesktopBrowser;
  47. }
  48. }
  49. ];
  50. /**
  51. * Utility method that responsible for intercepting of route components based on
  52. * the set of defined rules.
  53. *
  54. * @param {Object|Function} stateOrGetState - Either Redux state object or
  55. * getState() function.
  56. * @param {ReactElement} component - Current route component to render.
  57. * @returns {ReactElement} If any of rules is satisfied returns intercepted
  58. * component.
  59. */
  60. export function interceptComponent(
  61. stateOrGetState: Object,
  62. component: ReactElement<*>) {
  63. let result;
  64. const state
  65. = typeof stateOrGetState === 'function'
  66. ? stateOrGetState()
  67. : stateOrGetState;
  68. for (const rule of _RULES) {
  69. result = rule(state);
  70. if (result) {
  71. break;
  72. }
  73. }
  74. return result || component;
  75. }