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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /* global APP, JitsiMeetJS, loggingConfig $ */
  2. import React from 'react';
  3. import { Provider } from 'react-redux';
  4. import { compose } from 'redux';
  5. import {
  6. browserHistory,
  7. Route,
  8. Router
  9. } from 'react-router';
  10. import { push, syncHistoryWithStore } from 'react-router-redux';
  11. import { getDomain } from '../../base/connection';
  12. import { RouteRegistry } from '../../base/navigator';
  13. import { AbstractApp } from './AbstractApp';
  14. import settings from '../../../../modules/settings/Settings';
  15. import URLProcessor from '../../../../modules/config/URLProcessor';
  16. import getTokenData from '../../../../modules/tokendata/TokenData';
  17. import JitsiMeetLogStorage from '../../../../modules/util/JitsiMeetLogStorage';
  18. // eslint-disable-next-line max-len
  19. import KeyboardShortcut from '../../../../modules/keyboardshortcut/keyboardshortcut';
  20. const Logger = require('jitsi-meet-logger');
  21. const LogCollector = Logger.LogCollector;
  22. /**
  23. * Root application component.
  24. *
  25. * @extends AbstractApp
  26. */
  27. export class App extends AbstractApp {
  28. /**
  29. * App component's property types.
  30. *
  31. * @static
  32. */
  33. static propTypes = AbstractApp.propTypes;
  34. /**
  35. * Initializes a new App instance.
  36. *
  37. * @param {Object} props - The read-only React Component props with which
  38. * the new instance is to be initialized.
  39. */
  40. constructor(props) {
  41. super(props);
  42. /**
  43. * Create an enhanced history that syncs navigation events with the
  44. * store.
  45. * @link https://github.com/reactjs/react-router-redux#how-it-works
  46. */
  47. this.history = syncHistoryWithStore(browserHistory, props.store);
  48. // Bind event handlers so they are only bound once for every instance.
  49. this._onRouteEnter = this._onRouteEnter.bind(this);
  50. this._routerCreateElement = this._routerCreateElement.bind(this);
  51. this._getRoute = this._getRoute.bind(this);
  52. this._getRoutes = this._getRoutes.bind(this);
  53. }
  54. /**
  55. * Init translation from old app.
  56. *
  57. * @inheritdoc
  58. */
  59. componentWillMount(...args) {
  60. super.componentWillMount(...args);
  61. URLProcessor.setConfigParametersFromUrl();
  62. /* APP.init BEGIN */
  63. /* Init logging BEGIN */
  64. // Adjust logging level
  65. configureLoggingLevels();
  66. // Create the LogCollector and register it as the global log transport.
  67. // It is done early to capture as much logs as possible. Captured logs
  68. // will be cached, before the JitsiMeetLogStorage gets ready (statistics
  69. // module is initialized).
  70. if (!APP.logCollector && !loggingConfig.disableLogCollector) {
  71. APP.logCollector = new LogCollector(new JitsiMeetLogStorage());
  72. Logger.addGlobalTransport(APP.logCollector);
  73. JitsiMeetJS.addGlobalLogTransport(APP.logCollector);
  74. }
  75. /* Init logging BEGIN */
  76. APP.keyboardshortcut = KeyboardShortcut;
  77. APP.tokenData = getTokenData();
  78. /* APP.init END */
  79. APP.API.init(APP.tokenData.externalAPISettings);
  80. /**
  81. * Adjusts the logging levels.
  82. *
  83. * @private
  84. * @returns {void}
  85. */
  86. function configureLoggingLevels() {
  87. // NOTE The library Logger is separated from
  88. // the app loggers, so the levels
  89. // have to be set in two places
  90. // Set default logging level
  91. const defaultLogLevel
  92. = loggingConfig.defaultLogLevel || JitsiMeetJS.logLevels.TRACE;
  93. Logger.setLogLevel(defaultLogLevel);
  94. JitsiMeetJS.setLogLevel(defaultLogLevel);
  95. // NOTE console was used on purpose here to go around the logging
  96. // and always print the default logging level to the console
  97. console.info(`Default logging level set to: ${defaultLogLevel}`);
  98. // Set log level for each logger
  99. if (loggingConfig) {
  100. Object.keys(loggingConfig).forEach(loggerName => {
  101. if (loggerName !== 'defaultLogLevel') {
  102. const level = loggingConfig[loggerName];
  103. Logger.setLogLevelById(level, loggerName);
  104. JitsiMeetJS.setLogLevelById(level, loggerName);
  105. }
  106. });
  107. }
  108. }
  109. APP.translation.init(settings.getLanguage());
  110. }
  111. /**
  112. * Implements React's {@link Component#render()}.
  113. *
  114. * @inheritdoc
  115. * @returns {ReactElement}
  116. */
  117. render() {
  118. return (
  119. <Provider store = { this.props.store }>
  120. <Router
  121. createElement = { this._routerCreateElement }
  122. history = { this.history }>
  123. { this._getRoutes() }
  124. </Router>
  125. </Provider>
  126. );
  127. }
  128. /**
  129. * Navigates to a specific Route (via platform-specific means).
  130. *
  131. * @param {Route} route - The Route to which to navigate.
  132. * @returns {void}
  133. */
  134. _navigate(route) {
  135. let path = route.path;
  136. const store = this.props.store;
  137. // The syntax :room bellow is defined by react-router. It "matches a URL
  138. // segment up to the next /, ?, or #. The matched string is called a
  139. // param."
  140. path
  141. = path.replace(
  142. /:room/g,
  143. store.getState()['features/base/conference'].room);
  144. return store.dispatch(push(path));
  145. }
  146. /**
  147. * Returns routes for application.
  148. *
  149. * @returns {Array}
  150. * @private
  151. */
  152. _getRoutes() {
  153. const routes = RouteRegistry.getRoutes();
  154. return routes.map(this._getRoute);
  155. }
  156. /**
  157. * Method returns route for React Router.
  158. *
  159. * @param {Object} route - Object that describes route.
  160. * @returns {ReactElement}
  161. * @private
  162. */
  163. _getRoute(route) {
  164. const onEnter = route.onEnter || $.noop;
  165. const handler = compose(this._onRouteEnter, onEnter);
  166. return (
  167. <Route
  168. component = { route.component }
  169. key = { route.component }
  170. onEnter = { handler }
  171. path = { route.path } />
  172. );
  173. }
  174. /**
  175. * Invoked by react-router to notify this App that a Route is about to be
  176. * rendered.
  177. *
  178. * @private
  179. * @returns {void}
  180. */
  181. _onRouteEnter() {
  182. // XXX The following is mandatory. Otherwise, moving back & forward
  183. // through the browser's history could leave this App on the Conference
  184. // page without a room name.
  185. // Our Router configuration (at the time of this writing) is such that
  186. // each Route corresponds to a single URL. Hence, entering into a Route
  187. // is like opening a URL.
  188. // XXX In order to unify work with URLs in web and native environments,
  189. // we will construct URL here with correct domain from config.
  190. const currentDomain = getDomain(this.props.store.getState);
  191. const url
  192. = new URL(window.location.pathname, `https://${currentDomain}`)
  193. .toString();
  194. this._openURL(url);
  195. }
  196. /**
  197. * Create a ReactElement from the specified component and props on behalf of
  198. * the associated Router.
  199. *
  200. * @param {Component} component - The component from which the ReactElement
  201. * is to be created.
  202. * @param {Object} props - The read-only React Component props with which
  203. * the ReactElement is to be initialized.
  204. * @private
  205. * @returns {ReactElement}
  206. */
  207. _routerCreateElement(component, props) {
  208. return this._createElement(component, props);
  209. }
  210. }