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.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* global interfaceConfig */
  2. import { URI_PROTOCOL_PATTERN } from '../base/util';
  3. import { Platform } from '../base/react';
  4. import {
  5. DeepLinkingDesktopPage,
  6. DeepLinkingMobilePage,
  7. NoMobileApp
  8. } from './components';
  9. import { _shouldShowDeepLinkingDesktopPage }
  10. from './shouldShowDeepLinkingDesktopPage';
  11. /**
  12. * Generates a deep linking URL based on the current window URL.
  13. *
  14. * @returns {string} - The generated URL.
  15. */
  16. export function generateDeepLinkingURL() {
  17. // If the user installed the app while this Component was displayed
  18. // (e.g. the user clicked the Download the App button), then we would
  19. // like to open the current URL in the mobile app. The only way to do it
  20. // appears to be a link with an app-specific scheme, not a Universal
  21. // Link.
  22. const appScheme = interfaceConfig.APP_SCHEME || 'org.jitsi.meet';
  23. // Replace the protocol part with the app scheme.
  24. return window.location.href.replace(
  25. new RegExp(`^${URI_PROTOCOL_PATTERN}`), `${appScheme}:`);
  26. }
  27. /**
  28. * Resolves with the component that should be displayed if the deep linking page
  29. * should be shown and with <tt>undefined</tt> otherwise.
  30. *
  31. * @param {Object} state - Object containing current redux state.
  32. * @returns {Promise<Component>}
  33. */
  34. export function getDeepLinkingPage(state) {
  35. const { room } = state['features/base/conference'];
  36. // Show only if we are about to join a conference.
  37. if (!room) {
  38. return Promise.resolve();
  39. }
  40. const OS = Platform.OS;
  41. const isUsingMobileBrowser = OS === 'android' || OS === 'ios';
  42. if (isUsingMobileBrowser) { // mobile
  43. const mobileAppPromo
  44. = typeof interfaceConfig === 'object'
  45. && interfaceConfig.MOBILE_APP_PROMO;
  46. return Promise.resolve(
  47. typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
  48. ? DeepLinkingMobilePage : NoMobileApp);
  49. }
  50. // desktop
  51. const { launchInWeb } = state['features/deep-linking'];
  52. if (launchInWeb) {
  53. return Promise.resolve();
  54. }
  55. return _shouldShowDeepLinkingDesktopPage().then(
  56. // eslint-disable-next-line no-confusing-arrow
  57. show => show ? DeepLinkingDesktopPage : undefined);
  58. }
  59. /**
  60. * Opens the desktop app.
  61. *
  62. * @returns {void}
  63. */
  64. export function openDesktopApp() {
  65. window.location.href = generateDeepLinkingURL();
  66. }