Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

getRouteToRender.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. if (navigator.product === 'ReactNative') {
  40. return _getMobileRoute(state);
  41. }
  42. return _getWebConferenceRoute(state) || _getWebWelcomePageRoute(state);
  43. }
  44. /**
  45. * Returns the {@code Route} to display on the React Native app.
  46. *
  47. * @param {Object} state - The redux state.
  48. * @returns {Promise<Route>}
  49. */
  50. function _getMobileRoute(state): Promise<Route> {
  51. const route = _getEmptyRoute();
  52. if (isRoomValid(state['features/base/conference'].room)) {
  53. route.component = Conference;
  54. } else if (isWelcomePageAppEnabled(state)) {
  55. route.component = WelcomePage;
  56. } else {
  57. route.component = BlankPage;
  58. }
  59. return Promise.resolve(route);
  60. }
  61. /**
  62. * Returns the {@code Route} to display when trying to access a conference if
  63. * a valid conference is being joined.
  64. *
  65. * @param {Object} state - The redux state.
  66. * @returns {Promise<Route>|undefined}
  67. */
  68. function _getWebConferenceRoute(state): ?Promise<Route> {
  69. if (!isRoomValid(state['features/base/conference'].room)) {
  70. return;
  71. }
  72. const route = _getEmptyRoute();
  73. // Update the location if it doesn't match. This happens when a room is
  74. // joined from the welcome page. The reason for doing this instead of using
  75. // the history API is that we want to load the config.js which takes the
  76. // room into account.
  77. const { locationURL } = state['features/base/connection'];
  78. if (window.location.href !== locationURL.href) {
  79. route.href = locationURL.href;
  80. return Promise.resolve(route);
  81. }
  82. return getDeepLinkingPage(state)
  83. .then(deepLinkComponent => {
  84. if (deepLinkComponent) {
  85. route.component = deepLinkComponent;
  86. } else if (_isSupportedBrowser()) {
  87. route.component = Conference;
  88. } else {
  89. route.component = UnsupportedDesktopBrowser;
  90. }
  91. return route;
  92. });
  93. }
  94. /**
  95. * Returns the {@code Route} to display when trying to access the welcome page.
  96. *
  97. * @param {Object} state - The redux state.
  98. * @returns {Promise<Route>}
  99. */
  100. function _getWebWelcomePageRoute(state): Promise<Route> {
  101. const route = _getEmptyRoute();
  102. if (isWelcomePageUserEnabled(state)) {
  103. if (_isSupportedBrowser()) {
  104. route.component = WelcomePage;
  105. } else {
  106. route.component = UnsupportedDesktopBrowser;
  107. }
  108. } else {
  109. // Web: if the welcome page is disabled, go directly to a random room.
  110. let href = window.location.href;
  111. href.endsWith('/') || (href += '/');
  112. route.href = href + generateRoomWithoutSeparator();
  113. }
  114. return Promise.resolve(route);
  115. }
  116. /**
  117. * Returns whether or not the current browser should allow the app to display.
  118. *
  119. * @returns {boolean}
  120. */
  121. function _isSupportedBrowser() {
  122. if (navigator.product === 'ReactNative') {
  123. return false;
  124. }
  125. // We are intentionally allow mobile browsers because:
  126. // - the WelcomePage is mobile ready;
  127. // - if the URL points to a conference, getDeepLinkingPage will take
  128. // care of it.
  129. return Platform.OS === 'android'
  130. || Platform.OS === 'ios'
  131. || JitsiMeetJS.isWebRtcSupported();
  132. }
  133. /**
  134. * Returns the default {@code Route}.
  135. *
  136. * @returns {Route}
  137. */
  138. function _getEmptyRoute(): Route {
  139. return {
  140. component: BlankPage,
  141. href: undefined
  142. };
  143. }