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

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