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

getRouteToRender.web.ts 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // @ts-expect-error
  2. import { generateRoomWithoutSeparator } from '@jitsi/js-utils/random';
  3. import { IStateful } from '../base/app/types';
  4. import { isRoomValid } from '../base/conference/functions';
  5. import { isSupportedBrowser } from '../base/environment/environment';
  6. import { toState } from '../base/redux/functions';
  7. // eslint-disable-next-line lines-around-comment
  8. // @ts-ignore
  9. import Conference from '../conference/components/web/Conference';
  10. import { getDeepLinkingPage } from '../deep-linking/functions';
  11. import UnsupportedDesktopBrowser from '../unsupported-browser/components/UnsupportedDesktopBrowser';
  12. import BlankPage from '../welcome/components/BlankPage.web';
  13. import WelcomePage from '../welcome/components/WelcomePage.web';
  14. import { getCustomLandingPageURL, isWelcomePageEnabled } from '../welcome/functions';
  15. import { IReduxState } from './types';
  16. /**
  17. * Determines which route is to be rendered in order to depict a specific Redux
  18. * store.
  19. *
  20. * @param {(Function|Object)} stateful - THe redux store, state, or
  21. * {@code getState} function.
  22. * @returns {Promise<Object>}
  23. */
  24. export function _getRouteToRender(stateful: IStateful) {
  25. const state = toState(stateful);
  26. return _getWebConferenceRoute(state) || _getWebWelcomePageRoute(state);
  27. }
  28. /**
  29. * Returns the {@code Route} to display when trying to access a conference if
  30. * a valid conference is being joined.
  31. *
  32. * @param {Object} state - The redux state.
  33. * @returns {Promise|undefined}
  34. */
  35. function _getWebConferenceRoute(state: IReduxState) {
  36. if (!isRoomValid(state['features/base/conference'].room)) {
  37. return;
  38. }
  39. const route = _getEmptyRoute();
  40. // Update the location if it doesn't match. This happens when a room is
  41. // joined from the welcome page. The reason for doing this instead of using
  42. // the history API is that we want to load the config.js which takes the
  43. // room into account.
  44. const { locationURL } = state['features/base/connection'];
  45. if (window.location.href !== locationURL?.href) {
  46. route.href = locationURL?.href;
  47. return Promise.resolve(route);
  48. }
  49. return getDeepLinkingPage(state)
  50. .then(deepLinkComponent => {
  51. if (deepLinkComponent) {
  52. route.component = deepLinkComponent;
  53. } else if (isSupportedBrowser()) {
  54. route.component = Conference;
  55. } else {
  56. route.component = UnsupportedDesktopBrowser;
  57. }
  58. return route;
  59. });
  60. }
  61. /**
  62. * Returns the {@code Route} to display when trying to access the welcome page.
  63. *
  64. * @param {Object} state - The redux state.
  65. * @returns {Promise<Object>}
  66. */
  67. function _getWebWelcomePageRoute(state: IReduxState) {
  68. const route = _getEmptyRoute();
  69. if (isWelcomePageEnabled(state)) {
  70. if (isSupportedBrowser()) {
  71. const customLandingPage = getCustomLandingPageURL(state);
  72. if (customLandingPage) {
  73. route.href = customLandingPage;
  74. } else {
  75. route.component = WelcomePage;
  76. }
  77. } else {
  78. route.component = UnsupportedDesktopBrowser;
  79. }
  80. } else {
  81. // Web: if the welcome page is disabled, go directly to a random room.
  82. const url = new URL(window.location.href);
  83. url.pathname += generateRoomWithoutSeparator();
  84. route.href = url.href;
  85. }
  86. return Promise.resolve(route);
  87. }
  88. /**
  89. * Returns the default {@code Route}.
  90. *
  91. * @returns {Object}
  92. */
  93. function _getEmptyRoute(): {
  94. component: React.ReactNode;
  95. href?: string;
  96. } {
  97. return {
  98. component: BlankPage,
  99. href: undefined
  100. };
  101. }