Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

functions.ts 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* eslint-disable lines-around-comment */
  2. import { IReduxState } from '../app/types';
  3. import { isMobileBrowser } from '../base/environment/utils';
  4. import Platform from '../base/react/Platform';
  5. import { URI_PROTOCOL_PATTERN } from '../base/util/uri';
  6. import { isVpaasMeeting } from '../jaas/functions';
  7. // @ts-ignore
  8. import DeepLinkingDesktopPage from './components/DeepLinkingDesktopPage';
  9. // @ts-ignore
  10. import DeepLinkingMobilePage from './components/DeepLinkingMobilePage';
  11. // @ts-ignore
  12. import NoMobileApp from './components/NoMobileApp';
  13. import { _openDesktopApp } from './openDesktopApp';
  14. /* eslint-enable lines-around-comment */
  15. /**
  16. * Generates a deep linking URL based on the current window URL.
  17. *
  18. * @param {Object} state - Object containing current redux state.
  19. *
  20. * @returns {string} - The generated URL.
  21. */
  22. export function generateDeepLinkingURL(state: IReduxState) {
  23. // If the user installed the app while this Component was displayed
  24. // (e.g. the user clicked the Download the App button), then we would
  25. // like to open the current URL in the mobile app. The only way to do it
  26. // appears to be a link with an app-specific scheme, not a Universal
  27. // Link.
  28. const { href } = window.location;
  29. const regex = new RegExp(URI_PROTOCOL_PATTERN, 'gi');
  30. // @ts-ignore
  31. const mobileConfig = state['features/base/config'].deeplinking?.[Platform.OS] || {};
  32. const { appScheme, appPackage } = mobileConfig;
  33. // Android: use an intent link, custom schemes don't work in all browsers.
  34. // https://developer.chrome.com/multidevice/android/intents
  35. if (Platform.OS === 'android') {
  36. // https://meet.jit.si/foo -> meet.jit.si/foo
  37. const url = href.replace(regex, '').substr(2);
  38. return `intent://${url}#Intent;scheme=${appScheme};package=${appPackage};end`;
  39. }
  40. // iOS: Replace the protocol part with the app scheme.
  41. return href.replace(regex, `${appScheme}:`);
  42. }
  43. /**
  44. * Resolves with the component that should be displayed if the deep linking page
  45. * should be shown and with <tt>undefined</tt> otherwise.
  46. *
  47. * @param {Object} state - Object containing current redux state.
  48. * @returns {Promise<Component>}
  49. */
  50. export function getDeepLinkingPage(state: IReduxState) {
  51. const { room } = state['features/base/conference'];
  52. const { launchInWeb } = state['features/deep-linking'];
  53. const deeplinking = state['features/base/config'].deeplinking || {};
  54. // @ts-ignore
  55. const { appScheme } = deeplinking?.[Platform.OS as keyof typeof deeplinking] || {};
  56. // Show only if we are about to join a conference.
  57. if (launchInWeb
  58. || !room
  59. || state['features/base/config'].deeplinking?.disabled
  60. || (isVpaasMeeting(state) && (!appScheme || appScheme === 'com.8x8.meet'))) {
  61. return Promise.resolve();
  62. }
  63. if (isMobileBrowser()) { // mobile
  64. const mobileAppPromo
  65. = typeof interfaceConfig === 'object'
  66. && interfaceConfig.MOBILE_APP_PROMO;
  67. return Promise.resolve(
  68. typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
  69. ? DeepLinkingMobilePage : NoMobileApp);
  70. }
  71. return _openDesktopApp(state).then(
  72. // eslint-disable-next-line no-confusing-arrow
  73. result => result ? DeepLinkingDesktopPage : undefined);
  74. }
  75. /**
  76. * Opens the desktop app.
  77. *
  78. * @param {Object} state - Object containing current redux state.
  79. * @returns {Promise<boolean>} - Resolves with true if the attempt to open the desktop app was successful and resolves
  80. * with false otherwise.
  81. */
  82. export function openDesktopApp(state: IReduxState) {
  83. return _openDesktopApp(state);
  84. }