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.

App.web.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import React from 'react';
  2. import { Provider } from 'react-redux';
  3. import {
  4. browserHistory,
  5. Route,
  6. Router
  7. } from 'react-router';
  8. import { push, syncHistoryWithStore } from 'react-router-redux';
  9. import { getDomain } from '../../base/connection';
  10. import { RouteRegistry } from '../../base/navigator';
  11. import { AbstractApp } from './AbstractApp';
  12. /**
  13. * Root application component.
  14. *
  15. * @extends AbstractApp
  16. */
  17. export class App extends AbstractApp {
  18. /**
  19. * Initializes a new App instance.
  20. *
  21. * @param {Object} props - The read-only React Component props with which
  22. * the new instance is to be initialized.
  23. */
  24. constructor(props) {
  25. super(props);
  26. /**
  27. * Create an enhanced history that syncs navigation events with the
  28. * store.
  29. * @link https://github.com/reactjs/react-router-redux#how-it-works
  30. */
  31. this.history = syncHistoryWithStore(browserHistory, props.store);
  32. // Bind event handlers so they are only bound once for every instance.
  33. this._onRouteEnter = this._onRouteEnter.bind(this);
  34. this._routerCreateElement = this._routerCreateElement.bind(this);
  35. }
  36. /**
  37. * Temporarily, prevents the super from dispatching Redux actions until they
  38. * are integrated into the Web App.
  39. *
  40. * @returns {void}
  41. */
  42. componentWillMount() {
  43. // FIXME Do not override the super once the dispatching of Redux actions
  44. // is integrated into the Web App.
  45. }
  46. /**
  47. * Temporarily, prevents the super from dispatching Redux actions until they
  48. * are integrated into the Web App.
  49. *
  50. * @returns {void}
  51. */
  52. componentWillUnmount() {
  53. // FIXME Do not override the super once the dispatching of Redux actions
  54. // is integrated into the Web App.
  55. }
  56. /**
  57. * Implements React's {@link Component#render()}.
  58. *
  59. * @inheritdoc
  60. * @returns {ReactElement}
  61. */
  62. render() {
  63. const routes = RouteRegistry.getRoutes();
  64. return (
  65. <Provider store = { this.props.store }>
  66. <Router
  67. createElement = { this._routerCreateElement }
  68. history = { this.history }>
  69. { routes.map(r =>
  70. <Route
  71. component = { r.component }
  72. key = { r.component }
  73. path = { r.path } />
  74. ) }
  75. </Router>
  76. </Provider>
  77. );
  78. }
  79. /**
  80. * Navigates to a specific Route (via platform-specific means).
  81. *
  82. * @param {Route} route - The Route to which to navigate.
  83. * @returns {void}
  84. */
  85. _navigate(route) {
  86. let path = route.path;
  87. const store = this.props.store;
  88. // The syntax :room bellow is defined by react-router. It "matches a URL
  89. // segment up to the next /, ?, or #. The matched string is called a
  90. // param."
  91. path
  92. = path.replace(
  93. /:room/g,
  94. store.getState()['features/base/conference'].room);
  95. return store.dispatch(push(path));
  96. }
  97. /**
  98. * Invoked by react-router to notify this App that a Route is about to be
  99. * rendered.
  100. *
  101. * @private
  102. * @returns {void}
  103. */
  104. _onRouteEnter() {
  105. // XXX The following is mandatory. Otherwise, moving back & forward
  106. // through the browser's history could leave this App on the Conference
  107. // page without a room name.
  108. // Our Router configuration (at the time of this writing) is such that
  109. // each Route corresponds to a single URL. Hence, entering into a Route
  110. // is like opening a URL.
  111. // XXX In order to unify work with URLs in web and native environments,
  112. // we will construct URL here with correct domain from config.
  113. const currentDomain = getDomain(this.props.store.getState);
  114. const url
  115. = new URL(window.location.pathname, `https://${currentDomain}`)
  116. .toString();
  117. this._openURL(url);
  118. }
  119. /**
  120. * Create a ReactElement from the specified component and props on behalf of
  121. * the associated Router.
  122. *
  123. * @param {Component} component - The component from which the ReactElement
  124. * is to be created.
  125. * @param {Object} props - The read-only React Component props with which
  126. * the ReactElement is to be initialized.
  127. * @private
  128. * @returns {ReactElement}
  129. */
  130. _routerCreateElement(component, props) {
  131. return this._createElement(component, props);
  132. }
  133. }
  134. /**
  135. * App component's property types.
  136. *
  137. * @static
  138. */
  139. App.propTypes = AbstractApp.propTypes;