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

functions.ts 3.5KB

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