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 3.1KB

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