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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. // Show only if we are about to join a conference.
  48. if (launchInWeb || !room || state['features/base/config'].disableDeepLinking || isVpaasMeeting(state)) {
  49. return Promise.resolve();
  50. }
  51. if (isMobileBrowser()) { // mobile
  52. const mobileAppPromo
  53. = typeof interfaceConfig === 'object'
  54. && interfaceConfig.MOBILE_APP_PROMO;
  55. return Promise.resolve(
  56. typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
  57. ? DeepLinkingMobilePage : NoMobileApp);
  58. }
  59. return _openDesktopApp(state).then(
  60. // eslint-disable-next-line no-confusing-arrow
  61. result => result ? DeepLinkingDesktopPage : undefined);
  62. }
  63. /**
  64. * Opens the desktop app.
  65. *
  66. * @param {Object} state - Object containing current redux state.
  67. * @returns {Promise<boolean>} - Resolves with true if the attempt to open the desktop app was successful and resolves
  68. * with false otherwise.
  69. */
  70. export function openDesktopApp(state) {
  71. return _openDesktopApp(state);
  72. }