您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. const { href } = window.location;
  41. const regex = new RegExp(URI_PROTOCOL_PATTERN, 'gi');
  42. // Android: use an intent link, custom schemes don't work in all browsers.
  43. // https://developer.chrome.com/multidevice/android/intents
  44. if (Platform.OS === 'android') {
  45. // https://meet.jit.si/foo -> meet.jit.si/foo
  46. const url = href.replace(regex, '').substr(3);
  47. const pkg = interfaceConfig.ANDROID_APP_PACKAGE || 'org.jitsi.meet';
  48. return `intent://${url}/#Intent;scheme=${appScheme};package=${pkg};end`;
  49. }
  50. // iOS: Replace the protocol part with the app scheme.
  51. return href.replace(regex, `${appScheme}:`);
  52. }
  53. /**
  54. * Resolves with the component that should be displayed if the deep linking page
  55. * should be shown and with <tt>undefined</tt> otherwise.
  56. *
  57. * @param {Object} state - Object containing current redux state.
  58. * @returns {Promise<Component>}
  59. */
  60. export function getDeepLinkingPage(state) {
  61. const { room } = state['features/base/conference'];
  62. // Show only if we are about to join a conference.
  63. if (!room) {
  64. return Promise.resolve();
  65. }
  66. const OS = Platform.OS;
  67. const isUsingMobileBrowser = OS === 'android' || OS === 'ios';
  68. if (isUsingMobileBrowser) { // mobile
  69. const mobileAppPromo
  70. = typeof interfaceConfig === 'object'
  71. && interfaceConfig.MOBILE_APP_PROMO;
  72. return Promise.resolve(
  73. typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
  74. ? DeepLinkingMobilePage : NoMobileApp);
  75. }
  76. // desktop
  77. const { launchInWeb } = state['features/deep-linking'];
  78. if (launchInWeb) {
  79. return Promise.resolve();
  80. }
  81. return _shouldShowDeepLinkingDesktopPage().then(
  82. // eslint-disable-next-line no-confusing-arrow
  83. show => show ? DeepLinkingDesktopPage : undefined);
  84. }
  85. /**
  86. * Opens the desktop app.
  87. *
  88. * @returns {void}
  89. */
  90. export function openDesktopApp() {
  91. windowLoadedPromise.then(() => {
  92. // If the code for opening the deep link is executed before the window
  93. // load event, something with the internal chrome state goes wrong. The
  94. // result is that no window load event is received which is the cause
  95. // for some permission prompts to not be displayed. In our case the GUM
  96. // prompt wasn't displayed which causes the GUM call to never finish.
  97. window.location.href = generateDeepLinkingURL();
  98. });
  99. }