Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

App.web.js 3.5KB

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