Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

getRouteToRender.web.ts 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. return getTokenAuthUrl(config, room, tenant, false, locationURL)
  51. .then((url: string | undefined) => {
  52. route.href = url;
  53. return route;
  54. })
  55. .catch(() => Promise.resolve(route));
  56. }
  57. // Update the location if it doesn't match. This happens when a room is
  58. // joined from the welcome page. The reason for doing this instead of using
  59. // the history API is that we want to load the config.js which takes the
  60. // room into account.
  61. const { locationURL } = state['features/base/connection'];
  62. if (window.location.href !== locationURL?.href) {
  63. route.href = locationURL?.href;
  64. return Promise.resolve(route);
  65. }
  66. return getDeepLinkingPage(state)
  67. .then(deepLinkComponent => {
  68. if (deepLinkComponent) {
  69. route.component = deepLinkComponent;
  70. } else if (isSupportedBrowser()) {
  71. route.component = Conference;
  72. } else {
  73. route.component = UnsupportedDesktopBrowser;
  74. }
  75. return route;
  76. });
  77. }
  78. /**
  79. * Returns the {@code Route} to display when trying to access the welcome page.
  80. *
  81. * @param {Object} state - The redux state.
  82. * @returns {Promise<Object>}
  83. */
  84. function _getWebWelcomePageRoute(state: IReduxState) {
  85. const route = _getEmptyRoute();
  86. if (isWelcomePageEnabled(state)) {
  87. if (isSupportedBrowser()) {
  88. const customLandingPage = getCustomLandingPageURL(state);
  89. if (customLandingPage) {
  90. route.href = customLandingPage;
  91. } else {
  92. route.component = WelcomePage;
  93. }
  94. } else {
  95. route.component = UnsupportedDesktopBrowser;
  96. }
  97. } else {
  98. // Web: if the welcome page is disabled, go directly to a random room.
  99. const url = new URL(window.location.href);
  100. url.pathname += generateRoomWithoutSeparator();
  101. route.href = url.href;
  102. }
  103. return Promise.resolve(route);
  104. }
  105. /**
  106. * Returns the default {@code Route}.
  107. *
  108. * @returns {Object}
  109. */
  110. function _getEmptyRoute(): {
  111. component: React.ReactNode;
  112. href?: string;
  113. } {
  114. return {
  115. component: BlankPage,
  116. href: undefined
  117. };
  118. }