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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 { _openDesktopApp } from './openDesktopApp';
  10. /**
  11. * Generates a deep linking URL based on the current window URL.
  12. *
  13. * @returns {string} - The generated URL.
  14. */
  15. export function generateDeepLinkingURL() {
  16. // If the user installed the app while this Component was displayed
  17. // (e.g. the user clicked the Download the App button), then we would
  18. // like to open the current URL in the mobile app. The only way to do it
  19. // appears to be a link with an app-specific scheme, not a Universal
  20. // Link.
  21. const appScheme = interfaceConfig.APP_SCHEME || 'org.jitsi.meet';
  22. const { href } = window.location;
  23. const regex = new RegExp(URI_PROTOCOL_PATTERN, 'gi');
  24. // Android: use an intent link, custom schemes don't work in all browsers.
  25. // https://developer.chrome.com/multidevice/android/intents
  26. if (Platform.OS === 'android') {
  27. // https://meet.jit.si/foo -> meet.jit.si/foo
  28. const url = href.replace(regex, '').substr(2);
  29. const pkg = interfaceConfig.ANDROID_APP_PACKAGE || 'org.jitsi.meet';
  30. return `intent://${url}#Intent;scheme=${appScheme};package=${pkg};end`;
  31. }
  32. // iOS: Replace the protocol part with the app scheme.
  33. return href.replace(regex, `${appScheme}:`);
  34. }
  35. /**
  36. * Resolves with the component that should be displayed if the deep linking page
  37. * should be shown and with <tt>undefined</tt> otherwise.
  38. *
  39. * @param {Object} state - Object containing current redux state.
  40. * @returns {Promise<Component>}
  41. */
  42. export function getDeepLinkingPage(state) {
  43. const { room } = state['features/base/conference'];
  44. // Show only if we are about to join a conference.
  45. if (!room || state['features/base/config'].disableDeepLinking) {
  46. return Promise.resolve();
  47. }
  48. const OS = Platform.OS;
  49. const isUsingMobileBrowser = OS === 'android' || OS === 'ios';
  50. if (isUsingMobileBrowser) { // mobile
  51. const mobileAppPromo
  52. = typeof interfaceConfig === 'object'
  53. && interfaceConfig.MOBILE_APP_PROMO;
  54. return Promise.resolve(
  55. typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
  56. ? DeepLinkingMobilePage : NoMobileApp);
  57. }
  58. // desktop
  59. const { launchInWeb } = state['features/deep-linking'];
  60. if (launchInWeb) {
  61. return Promise.resolve();
  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. }