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.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // @flow
  2. import { generateRoomWithoutSeparator } from 'js-utils/random';
  3. import type { Component } from 'react';
  4. import { isRoomValid } from '../base/conference';
  5. import JitsiMeetJS from '../base/lib-jitsi-meet';
  6. import { Platform } from '../base/react';
  7. import { toState } from '../base/redux';
  8. import { Conference } from '../conference';
  9. import { getDeepLinkingPage } from '../deep-linking';
  10. import { UnsupportedDesktopBrowser } from '../unsupported-browser';
  11. import {
  12. BlankPage,
  13. WelcomePage,
  14. isWelcomePageAppEnabled,
  15. isWelcomePageUserEnabled
  16. } from '../welcome';
  17. /**
  18. * Object describing application route.
  19. *
  20. * @typedef {Object} Route
  21. * @property {Component} component - React Component constructor.
  22. * @property {string|undefined} href - New location, in case navigation involves
  23. * a location change.
  24. */
  25. export type Route = {
  26. component: Class<Component<*>>,
  27. href: ?string
  28. };
  29. /**
  30. * Determines which route is to be rendered in order to depict a specific Redux
  31. * store.
  32. *
  33. * @param {(Function|Object)} stateful - THe redux store, state, or
  34. * {@code getState} function.
  35. * @returns {Promise<Route>}
  36. */
  37. export function _getRouteToRender(stateful: Function | Object): Promise<Route> {
  38. const state = toState(stateful);
  39. const { room } = state['features/base/conference'];
  40. const isMobileApp = navigator.product === 'ReactNative';
  41. const isMobileBrowser
  42. = !isMobileApp && (Platform.OS === 'android' || Platform.OS === 'ios');
  43. const route: Route = {
  44. component: BlankPage,
  45. href: undefined
  46. };
  47. return new Promise(resolve => {
  48. // First, check if the current endpoint supports WebRTC. We are
  49. // intentionally not performing the check for mobile browsers because:
  50. // - the WelcomePage is mobile ready;
  51. // - if the URL points to a conference, getDeepLinkingPage will take
  52. // care of it.
  53. if (!isMobileBrowser && !JitsiMeetJS.isWebRtcSupported()) {
  54. route.component = UnsupportedDesktopBrowser;
  55. resolve(route);
  56. return;
  57. }
  58. if (isRoomValid(room)) {
  59. if (isMobileApp) {
  60. route.component = Conference;
  61. resolve(route);
  62. } else {
  63. // Update the location if it doesn't match. This happens when a
  64. // room is joined from the welcome page. The reason for doing
  65. // this instead of using the history API is that we want to load
  66. // the config.js which takes the room into account.
  67. const { locationURL } = state['features/base/connection'];
  68. // eslint-disable-next-line no-negated-condition
  69. if (window.location.href !== locationURL.href) {
  70. route.href = locationURL.href;
  71. resolve(route);
  72. } else {
  73. // Maybe show deep-linking, otherwise go to Conference.
  74. getDeepLinkingPage(state).then(component => {
  75. route.component = component || Conference;
  76. resolve(route);
  77. });
  78. }
  79. }
  80. return;
  81. }
  82. if (!isWelcomePageUserEnabled(state)) {
  83. // Web: if the welcome page is disabled, go directly to a random
  84. // room.
  85. let href = window.location.href;
  86. href.endsWith('/') || (href += '/');
  87. route.href = href + generateRoomWithoutSeparator();
  88. } else if (isWelcomePageAppEnabled(state)) {
  89. // Mobile: only go to the welcome page if enabled.
  90. route.component = WelcomePage;
  91. }
  92. resolve(route);
  93. });
  94. }