您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.web.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 getTokenData from '../../../modules/tokendata/TokenData';
  17. import JitsiMeetLogStorage from '../../../modules/util/JitsiMeetLogStorage';
  18. declare var APP: Object;
  19. declare var interfaceConfig: Object;
  20. declare var loggingConfig: Object;
  21. /**
  22. * Array of rules defining whether we should {@link _interceptComponent} to
  23. * render.
  24. *
  25. * @private
  26. * @param {Object} state - Object containing current Redux state.
  27. * @returns {ReactElement|void}
  28. * @type {Function[]}
  29. */
  30. const _INTERCEPT_COMPONENT_RULES = [
  31. /**
  32. * This rule describes case when user opens application using mobile
  33. * browser. In order to promote the app, we choose to suggest the mobile
  34. * app even if the browser supports the app (e.g. Google Chrome with
  35. * WebRTC support on Android).
  36. *
  37. * @param {Object} state - Redux state of the app.
  38. * @returns {UnsupportedMobileBrowser|void} If the rule is satisfied then
  39. * we should intercept existing component by UnsupportedMobileBrowser.
  40. */
  41. () => {
  42. const OS = Platform.OS;
  43. if (OS === 'android' || OS === 'ios') {
  44. const mobileAppPromo
  45. = typeof interfaceConfig === 'object'
  46. && interfaceConfig.MOBILE_APP_PROMO;
  47. return (
  48. typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
  49. ? UnsupportedMobileBrowser
  50. : NoMobileApp);
  51. }
  52. },
  53. state => {
  54. const { webRTCReady } = state['features/base/lib-jitsi-meet'];
  55. switch (typeof webRTCReady) {
  56. case 'boolean':
  57. if (webRTCReady === false) {
  58. return UnsupportedDesktopBrowser;
  59. }
  60. break;
  61. case 'undefined':
  62. // If webRTCReady is not set, then we cannot use it to take a
  63. // decision.
  64. break;
  65. default:
  66. return PluginRequiredBrowser;
  67. }
  68. }
  69. ];
  70. export { _parseURIString } from './functions.native';
  71. /**
  72. * Determines which route is to be rendered in order to depict a specific Redux
  73. * store.
  74. *
  75. * @param {(Object|Function)} stateOrGetState - Redux state or Regux getState()
  76. * method.
  77. * @returns {Route}
  78. */
  79. export function _getRouteToRender(stateOrGetState: Object | Function) {
  80. const state
  81. = typeof stateOrGetState === 'function'
  82. ? stateOrGetState()
  83. : stateOrGetState;
  84. // If mobile browser page was shown, there is no need to show it again.
  85. const { room } = state['features/base/conference'];
  86. const component = isRoomValid(room) ? Conference : WelcomePage;
  87. const route = RouteRegistry.getRouteByComponent(component);
  88. // Intercepts route components if any of component interceptor rules
  89. // is satisfied.
  90. route.component = _interceptComponent(state, component);
  91. return route;
  92. }
  93. /**
  94. * Temporary solution. Later we'll get rid of global APP and set its properties
  95. * in redux store.
  96. *
  97. * @returns {void}
  98. */
  99. export function init() {
  100. _initLogging();
  101. APP.keyboardshortcut = KeyboardShortcut;
  102. APP.tokenData = getTokenData();
  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(APP.tokenData.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. }