選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

getRouteToRender.web.ts 4.1KB

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