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

getRouteToRender.web.js 3.0KB

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