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.native.js 5.9KB

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