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.ts 3.6KB

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