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

App.native.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // @flow
  2. import React from 'react';
  3. import '../../analytics';
  4. import '../../authentication';
  5. import { setColorScheme } from '../../base/color-scheme';
  6. import { DialogContainer } from '../../base/dialog';
  7. import { updateFlags } from '../../base/flags';
  8. import '../../base/jwt';
  9. import { Platform } from '../../base/react';
  10. import {
  11. AspectRatioDetector,
  12. ReducedUIDetector
  13. } from '../../base/responsive-ui';
  14. import '../../google-api';
  15. import '../../mobile/audio-mode';
  16. import '../../mobile/background';
  17. import '../../mobile/call-integration';
  18. import '../../mobile/external-api';
  19. import '../../mobile/full-screen';
  20. import '../../mobile/permissions';
  21. import '../../mobile/picture-in-picture';
  22. import '../../mobile/proximity';
  23. import '../../mobile/wake-lock';
  24. import '../../mobile/watchos';
  25. import { AbstractApp } from './AbstractApp';
  26. import type { Props as AbstractAppProps } from './AbstractApp';
  27. declare var __DEV__;
  28. const logger = require('jitsi-meet-logger').getLogger(__filename);
  29. /**
  30. * The type of React {@code Component} props of {@link App}.
  31. */
  32. type Props = AbstractAppProps & {
  33. /**
  34. * An object of colors that override the default colors of the app/sdk.
  35. */
  36. colorScheme: ?Object,
  37. /**
  38. * Identifier for this app on the native side.
  39. */
  40. externalAPIScope: string,
  41. /**
  42. * An object with the feature flags.
  43. */
  44. flags: Object
  45. };
  46. /**
  47. * Root app {@code Component} on mobile/React Native.
  48. *
  49. * @extends AbstractApp
  50. */
  51. export class App extends AbstractApp {
  52. _init: Promise<*>;
  53. /**
  54. * Initializes a new {@code App} instance.
  55. *
  56. * @param {Props} props - The read-only React {@code Component} props with
  57. * which the new instance is to be initialized.
  58. */
  59. constructor(props: Props) {
  60. super(props);
  61. // In the Release configuration, React Native will (intentionally) throw
  62. // an unhandled JavascriptException for an unhandled JavaScript error.
  63. // This will effectively kill the app. In accord with the Web, do not
  64. // kill the app.
  65. this._maybeDisableExceptionsManager();
  66. }
  67. /**
  68. * Initializes the color scheme.
  69. *
  70. * @inheritdoc
  71. *
  72. * @returns {void}
  73. */
  74. componentDidMount() {
  75. super.componentDidMount();
  76. this._init.then(() => {
  77. // We set the color scheme early enough so then we avoid any
  78. // unnecessary re-renders.
  79. this.state.store.dispatch(setColorScheme(this.props.colorScheme));
  80. // Ditto for feature flags.
  81. this.state.store.dispatch(updateFlags(this.props.flags));
  82. });
  83. }
  84. /**
  85. * Injects {@link AspectRatioDetector} in order to detect the aspect ratio
  86. * of this {@code App}'s user interface and afford {@link AspectRatioAware}.
  87. *
  88. * @override
  89. */
  90. _createMainElement(component, props) {
  91. return (
  92. <AspectRatioDetector>
  93. <ReducedUIDetector>
  94. { super._createMainElement(component, props) }
  95. </ReducedUIDetector>
  96. </AspectRatioDetector>
  97. );
  98. }
  99. /**
  100. * Attempts to disable the use of React Native
  101. * {@link ExceptionsManager#handleException} on platforms and in
  102. * configurations on/in which the use of the method in questions has been
  103. * determined to be undesirable. For example, React Native will
  104. * (intentionally) throw an unhandled {@code JavascriptException} for an
  105. * unhandled JavaScript error in the Release configuration. This will
  106. * effectively kill the app. In accord with the Web, do not kill the app.
  107. *
  108. * @private
  109. * @returns {void}
  110. */
  111. _maybeDisableExceptionsManager() {
  112. if (__DEV__) {
  113. // As mentioned above, only the Release configuration was observed
  114. // to suffer.
  115. return;
  116. }
  117. if (Platform.OS !== 'android') {
  118. // A solution based on RTCSetFatalHandler was implemented on iOS and
  119. // it is preferred because it is at a later step of the
  120. // error/exception handling and it is specific to fatal
  121. // errors/exceptions which were observed to kill the app. The
  122. // solution implemented bellow was tested on Android only so it is
  123. // considered safest to use it there only.
  124. return;
  125. }
  126. const oldHandler = global.ErrorUtils.getGlobalHandler();
  127. const newHandler = _handleException;
  128. if (!oldHandler || oldHandler !== newHandler) {
  129. newHandler.next = oldHandler;
  130. global.ErrorUtils.setGlobalHandler(newHandler);
  131. }
  132. }
  133. /**
  134. * Renders the platform specific dialog container.
  135. *
  136. * @returns {React$Element}
  137. */
  138. _renderDialogContainer() {
  139. return (
  140. <DialogContainer />
  141. );
  142. }
  143. }
  144. /**
  145. * Handles a (possibly unhandled) JavaScript error by preventing React Native
  146. * from converting a fatal error into an unhandled native exception which will
  147. * kill the app.
  148. *
  149. * @param {Error} error - The (possibly unhandled) JavaScript error to handle.
  150. * @param {boolean} fatal - If the specified error is fatal, {@code true};
  151. * otherwise, {@code false}.
  152. * @private
  153. * @returns {void}
  154. */
  155. function _handleException(error, fatal) {
  156. if (fatal) {
  157. // In the Release configuration, React Native will (intentionally) throw
  158. // an unhandled JavascriptException for an unhandled JavaScript error.
  159. // This will effectively kill the app. In accord with the Web, do not
  160. // kill the app.
  161. logger.error(error);
  162. } else {
  163. // Forward to the next globalHandler of ErrorUtils.
  164. const { next } = _handleException;
  165. typeof next === 'function' && next(error, fatal);
  166. }
  167. }