Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

functions.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. * Promise that resolves when the window load event is received.
  13. *
  14. * @type {Promise<void>}
  15. */
  16. const windowLoadedPromise = new Promise(resolve => {
  17. /**
  18. * Handler for the window load event.
  19. *
  20. * @returns {void}
  21. */
  22. function onWindowLoad() {
  23. resolve();
  24. window.removeEventListener('load', onWindowLoad);
  25. }
  26. window.addEventListener('load', onWindowLoad);
  27. });
  28. /**
  29. * Generates a deep linking URL based on the current window URL.
  30. *
  31. * @returns {string} - The generated URL.
  32. */
  33. export function generateDeepLinkingURL() {
  34. // If the user installed the app while this Component was displayed
  35. // (e.g. the user clicked the Download the App button), then we would
  36. // like to open the current URL in the mobile app. The only way to do it
  37. // appears to be a link with an app-specific scheme, not a Universal
  38. // Link.
  39. const appScheme = interfaceConfig.APP_SCHEME || 'org.jitsi.meet';
  40. // Replace the protocol part with the app scheme.
  41. return window.location.href.replace(
  42. new RegExp(`^${URI_PROTOCOL_PATTERN}`), `${appScheme}:`);
  43. }
  44. /**
  45. * Resolves with the component that should be displayed if the deep linking page
  46. * should be shown and with <tt>undefined</tt> otherwise.
  47. *
  48. * @param {Object} state - Object containing current redux state.
  49. * @returns {Promise<Component>}
  50. */
  51. export function getDeepLinkingPage(state) {
  52. const { room } = state['features/base/conference'];
  53. // Show only if we are about to join a conference.
  54. if (!room) {
  55. return Promise.resolve();
  56. }
  57. const OS = Platform.OS;
  58. const isUsingMobileBrowser = OS === 'android' || OS === 'ios';
  59. if (isUsingMobileBrowser) { // mobile
  60. const mobileAppPromo
  61. = typeof interfaceConfig === 'object'
  62. && interfaceConfig.MOBILE_APP_PROMO;
  63. return Promise.resolve(
  64. typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
  65. ? DeepLinkingMobilePage : NoMobileApp);
  66. }
  67. // desktop
  68. const { launchInWeb } = state['features/deep-linking'];
  69. if (launchInWeb) {
  70. return Promise.resolve();
  71. }
  72. return _shouldShowDeepLinkingDesktopPage().then(
  73. // eslint-disable-next-line no-confusing-arrow
  74. show => show ? DeepLinkingDesktopPage : undefined);
  75. }
  76. /**
  77. * Opens the desktop app.
  78. *
  79. * @returns {void}
  80. */
  81. export function openDesktopApp() {
  82. windowLoadedPromise.then(() => {
  83. // If the code for opening the deep link is executed before the window
  84. // load event, something with the internal chrome state goes wrong. The
  85. // result is that no window load event is received which is the cause
  86. // for some permission prompts to not be displayed. In our case the GUM
  87. // prompt wasn't displayed which causes the GUM call to never finish.
  88. window.location.href = generateDeepLinkingURL();
  89. });
  90. }