Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

getRouteToRender.web.ts 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // @ts-expect-error
  2. import { generateRoomWithoutSeparator } from '@jitsi/js-utils/random';
  3. import { getTokenAuthUrl } from '../authentication/functions.web';
  4. import { IStateful } from '../base/app/types';
  5. import { isRoomValid } from '../base/conference/functions';
  6. import { isSupportedBrowser } from '../base/environment/environment';
  7. import { browser } from '../base/lib-jitsi-meet';
  8. import { toState } from '../base/redux/functions';
  9. import { parseURIString } from '../base/util/uri';
  10. import Conference from '../conference/components/web/Conference';
  11. import { getDeepLinkingPage } from '../deep-linking/functions';
  12. import UnsupportedDesktopBrowser from '../unsupported-browser/components/UnsupportedDesktopBrowser';
  13. import BlankPage from '../welcome/components/BlankPage.web';
  14. import WelcomePage from '../welcome/components/WelcomePage.web';
  15. import { getCustomLandingPageURL, isWelcomePageEnabled } from '../welcome/functions';
  16. import { IReduxState } from './types';
  17. /**
  18. * Determines which route is to be rendered in order to depict a specific Redux
  19. * store.
  20. *
  21. * @param {(Function|Object)} stateful - THe redux store, state, or
  22. * {@code getState} function.
  23. * @returns {Promise<Object>}
  24. */
  25. export function _getRouteToRender(stateful: IStateful) {
  26. const state = toState(stateful);
  27. return _getWebConferenceRoute(state) || _getWebWelcomePageRoute(state);
  28. }
  29. /**
  30. * Returns the {@code Route} to display when trying to access a conference if
  31. * a valid conference is being joined.
  32. *
  33. * @param {Object} state - The redux state.
  34. * @returns {Promise|undefined}
  35. */
  36. function _getWebConferenceRoute(state: IReduxState) {
  37. const room = state['features/base/conference'].room;
  38. if (!isRoomValid(room)) {
  39. return;
  40. }
  41. const route = _getEmptyRoute();
  42. const config = state['features/base/config'];
  43. // if we have auto redirect enabled, and we have previously logged in successfully
  44. // let's redirect to the auth url to get the token and login again
  45. if (!browser.isElectron() && config.tokenAuthUrl && config.tokenAuthUrlAutoRedirect
  46. && state['features/authentication'].tokenAuthUrlSuccessful
  47. && !state['features/base/jwt'].jwt && room) {
  48. const { locationURL = { href: '' } as URL } = state['features/base/connection'];
  49. const { tenant } = parseURIString(locationURL.href) || {};
  50. const { startAudioOnly } = config;
  51. return getTokenAuthUrl(
  52. config,
  53. locationURL,
  54. {
  55. audioMuted: false,
  56. audioOnlyEnabled: startAudioOnly,
  57. skipPrejoin: false,
  58. videoMuted: false
  59. },
  60. room,
  61. tenant
  62. )
  63. .then((url: string | undefined) => {
  64. route.href = url;
  65. return route;
  66. })
  67. .catch(() => Promise.resolve(route));
  68. }
  69. // Update the location if it doesn't match. This happens when a room is
  70. // joined from the welcome page. The reason for doing this instead of using
  71. // the history API is that we want to load the config.js which takes the
  72. // room into account.
  73. const { locationURL } = state['features/base/connection'];
  74. if (window.location.href !== locationURL?.href) {
  75. route.href = locationURL?.href;
  76. return Promise.resolve(route);
  77. }
  78. return getDeepLinkingPage(state)
  79. .then(deepLinkComponent => {
  80. if (deepLinkComponent) {
  81. route.component = deepLinkComponent;
  82. } else if (isSupportedBrowser()) {
  83. route.component = Conference;
  84. } else {
  85. route.component = UnsupportedDesktopBrowser;
  86. }
  87. return route;
  88. });
  89. }
  90. /**
  91. * Returns the {@code Route} to display when trying to access the welcome page.
  92. *
  93. * @param {Object} state - The redux state.
  94. * @returns {Promise<Object>}
  95. */
  96. function _getWebWelcomePageRoute(state: IReduxState) {
  97. const route = _getEmptyRoute();
  98. if (isWelcomePageEnabled(state)) {
  99. if (isSupportedBrowser()) {
  100. const customLandingPage = getCustomLandingPageURL(state);
  101. if (customLandingPage) {
  102. route.href = customLandingPage;
  103. } else {
  104. route.component = WelcomePage;
  105. }
  106. } else {
  107. route.component = UnsupportedDesktopBrowser;
  108. }
  109. } else {
  110. // Web: if the welcome page is disabled, go directly to a random room.
  111. const url = new URL(window.location.href);
  112. url.pathname += generateRoomWithoutSeparator();
  113. route.href = url.href;
  114. }
  115. return Promise.resolve(route);
  116. }
  117. /**
  118. * Returns the default {@code Route}.
  119. *
  120. * @returns {Object}
  121. */
  122. function _getEmptyRoute(): { component: React.ReactNode; href?: string; } {
  123. return {
  124. component: BlankPage,
  125. href: undefined
  126. };
  127. }