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.

functions.web.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* @flow */
  2. import Logger from 'jitsi-meet-logger';
  3. import { isRoomValid } from '../base/conference';
  4. import JitsiMeetJS from '../base/lib-jitsi-meet';
  5. import { Platform, RouteRegistry } from '../base/react';
  6. import { Conference } from '../conference';
  7. import {
  8. NoMobileApp,
  9. PluginRequiredBrowser,
  10. UnsupportedDesktopBrowser,
  11. UnsupportedMobileBrowser
  12. } from '../unsupported-browser';
  13. import { WelcomePage } from '../welcome';
  14. import KeyboardShortcut
  15. from '../../../modules/keyboardshortcut/keyboardshortcut';
  16. import JitsiMeetLogStorage from '../../../modules/util/JitsiMeetLogStorage';
  17. declare var APP: Object;
  18. declare var interfaceConfig: Object;
  19. declare var loggingConfig: Object;
  20. /**
  21. * Array of rules defining whether we should {@link _interceptComponent} to
  22. * render.
  23. *
  24. * @private
  25. * @param {Object} state - Object containing current Redux state.
  26. * @returns {ReactElement|void}
  27. * @type {Function[]}
  28. */
  29. const _INTERCEPT_COMPONENT_RULES = [
  30. /**
  31. * This rule describes case when user opens application using mobile
  32. * browser. In order to promote the app, we choose to suggest the mobile
  33. * app even if the browser supports the app (e.g. Google Chrome with
  34. * WebRTC support on Android).
  35. *
  36. * @param {Object} state - Redux state of the app.
  37. * @returns {UnsupportedMobileBrowser|void} If the rule is satisfied then
  38. * we should intercept existing component by UnsupportedMobileBrowser.
  39. */
  40. () => {
  41. const OS = Platform.OS;
  42. if (OS === 'android' || OS === 'ios') {
  43. const mobileAppPromo
  44. = typeof interfaceConfig === 'object'
  45. && interfaceConfig.MOBILE_APP_PROMO;
  46. return (
  47. typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
  48. ? UnsupportedMobileBrowser
  49. : NoMobileApp);
  50. }
  51. },
  52. state => {
  53. const { webRTCReady } = state['features/base/lib-jitsi-meet'];
  54. switch (typeof webRTCReady) {
  55. case 'boolean':
  56. if (webRTCReady === false) {
  57. return UnsupportedDesktopBrowser;
  58. }
  59. break;
  60. case 'undefined':
  61. // If webRTCReady is not set, then we cannot use it to take a
  62. // decision.
  63. break;
  64. default:
  65. return PluginRequiredBrowser;
  66. }
  67. }
  68. ];
  69. export { _parseURIString } from './functions.native';
  70. /**
  71. * Determines which route is to be rendered in order to depict a specific Redux
  72. * store.
  73. *
  74. * @param {(Object|Function)} stateOrGetState - Redux state or Regux getState()
  75. * method.
  76. * @returns {Route}
  77. */
  78. export function _getRouteToRender(stateOrGetState: Object | Function) {
  79. const state
  80. = typeof stateOrGetState === 'function'
  81. ? stateOrGetState()
  82. : stateOrGetState;
  83. // If mobile browser page was shown, there is no need to show it again.
  84. const { room } = state['features/base/conference'];
  85. const component = isRoomValid(room) ? Conference : WelcomePage;
  86. const route = RouteRegistry.getRouteByComponent(component);
  87. // Intercepts route components if any of component interceptor rules
  88. // is satisfied.
  89. route.component = _interceptComponent(state, component);
  90. return route;
  91. }
  92. /**
  93. * Temporary solution. Later we'll get rid of global APP and set its properties
  94. * in redux store.
  95. *
  96. * @param {Object} state - Snapshot of current state of redux store.
  97. * @returns {void}
  98. */
  99. export function init(state: Object) {
  100. _initLogging();
  101. APP.keyboardshortcut = KeyboardShortcut;
  102. const { jwt } = state['features/jwt'];
  103. // Force enable the API if jwt token is passed because most probably
  104. // jitsi meet is displayed inside of wrapper that will need to communicate
  105. // with jitsi meet.
  106. APP.API.init(jwt ? { forceEnable: true } : undefined);
  107. APP.translation.init();
  108. }
  109. /**
  110. * Initializes logging in the app.
  111. *
  112. * @private
  113. * @returns {void}
  114. */
  115. function _initLogging() {
  116. // Create the LogCollector and register it as the global log transport. It
  117. // is done early to capture as much logs as possible. Captured logs will be
  118. // cached, before the JitsiMeetLogStorage gets ready (statistics module is
  119. // initialized).
  120. if (!APP.logCollector && !loggingConfig.disableLogCollector) {
  121. APP.logCollector = new Logger.LogCollector(new JitsiMeetLogStorage());
  122. Logger.addGlobalTransport(APP.logCollector);
  123. JitsiMeetJS.addGlobalLogTransport(APP.logCollector);
  124. }
  125. }
  126. /**
  127. * Intercepts route components based on a {@link _INTERCEPT_COMPONENT_RULES}.
  128. *
  129. * @param {Object|Function} stateOrGetState - Either Redux state object or
  130. * getState() function.
  131. * @param {ReactElement} component - Current route component to render.
  132. * @private
  133. * @returns {ReactElement} If any of the pre-defined rules is satisfied, returns
  134. * intercepted component.
  135. */
  136. function _interceptComponent(
  137. stateOrGetState: Object,
  138. component: ReactElement<*>) {
  139. let result;
  140. const state
  141. = typeof stateOrGetState === 'function'
  142. ? stateOrGetState()
  143. : stateOrGetState;
  144. for (const rule of _INTERCEPT_COMPONENT_RULES) {
  145. result = rule(state);
  146. if (result) {
  147. break;
  148. }
  149. }
  150. return result || component;
  151. }