Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { AbstractApp } from './AbstractApp';
  2. import { getLocationContextRoot } from '../functions';
  3. import '../../room-lock';
  4. /**
  5. * Root application component.
  6. *
  7. * @extends AbstractApp
  8. */
  9. export class App extends AbstractApp {
  10. /**
  11. * App component's property types.
  12. *
  13. * @static
  14. */
  15. static propTypes = AbstractApp.propTypes
  16. /**
  17. * Initializes a new App instance.
  18. *
  19. * @param {Object} props - The read-only React Component props with which
  20. * the new instance is to be initialized.
  21. */
  22. constructor(props) {
  23. super(props);
  24. this.state = {
  25. ...this.state,
  26. /**
  27. * The context root of window.location i.e. this Web App.
  28. *
  29. * @type {string}
  30. */
  31. windowLocationContextRoot: this._getWindowLocationContextRoot()
  32. };
  33. }
  34. /**
  35. * Gets a Location object from the window with information about the current
  36. * location of the document.
  37. *
  38. * @inheritdoc
  39. */
  40. getWindowLocation() {
  41. return window.location;
  42. }
  43. /**
  44. * Gets the context root of this Web App from window.location.
  45. *
  46. * @private
  47. * @returns {string} The context root of window.location i.e. this Web App.
  48. */
  49. _getWindowLocationContextRoot() {
  50. return getLocationContextRoot(this.getWindowLocation());
  51. }
  52. /**
  53. * Navigates to a specific Route (via platform-specific means).
  54. *
  55. * @param {Route} route - The Route to which to navigate.
  56. * @protected
  57. * @returns {void}
  58. */
  59. _navigate(route) {
  60. let path = route.path;
  61. const store = this._getStore();
  62. // The syntax :room bellow is defined by react-router. It "matches a URL
  63. // segment up to the next /, ?, or #. The matched string is called a
  64. // param."
  65. path
  66. = path.replace(
  67. /:room/g,
  68. store.getState()['features/base/conference'].room);
  69. path = this._routePath2WindowLocationPathname(path);
  70. // Navigate to the specified Route.
  71. const windowLocation = this.getWindowLocation();
  72. if (windowLocation.pathname === path) {
  73. // The browser is at the specified path already and what remains is
  74. // to make this App instance aware of the route to be rendered at
  75. // the current location.
  76. super._navigate(route);
  77. } else {
  78. // The browser must go to the specified location. Once the specified
  79. // location becomes current, the App will be made aware of the route
  80. // to be rendered at it.
  81. windowLocation.pathname = path;
  82. }
  83. }
  84. /**
  85. * Converts a specific Route path to a window.location.pathname.
  86. *
  87. * @param {string} path - A Route path to be converted to/represeted as a
  88. * window.location.pathname.
  89. * @private
  90. * @returns {string} A window.location.pathname-compatible representation of
  91. * the specified Route path.
  92. */
  93. _routePath2WindowLocationPathname(path) {
  94. let pathname = this.state.windowLocationContextRoot;
  95. pathname.endsWith('/') || (pathname += '/');
  96. pathname += path.startsWith('/') ? path.substring(1) : path;
  97. return pathname;
  98. }
  99. }