You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

getRouteToRender.web.ts 3.5KB

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