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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* global __DEV__ */
  2. import PropTypes from 'prop-types';
  3. import { Linking } from 'react-native';
  4. import '../../analytics';
  5. import '../../authentication';
  6. import { Platform } from '../../base/react';
  7. import '../../mobile/audio-mode';
  8. import '../../mobile/background';
  9. import '../../mobile/callkit';
  10. import '../../mobile/external-api';
  11. import '../../mobile/full-screen';
  12. import '../../mobile/permissions';
  13. import '../../mobile/proximity';
  14. import '../../mobile/wake-lock';
  15. import { AbstractApp } from './AbstractApp';
  16. /**
  17. * Root application component.
  18. *
  19. * @extends AbstractApp
  20. */
  21. export class App extends AbstractApp {
  22. /**
  23. * App component's property types.
  24. *
  25. * @static
  26. */
  27. static propTypes = {
  28. ...AbstractApp.propTypes,
  29. /**
  30. * Whether the Welcome page is enabled. If {@code true}, the Welcome
  31. * page is rendered when the {@link App} is not at a location (URL)
  32. * identifying a Jitsi Meet conference/room.
  33. */
  34. welcomePageEnabled: PropTypes.bool
  35. };
  36. /**
  37. * Initializes a new App instance.
  38. *
  39. * @param {Object} props - The read-only React Component props with which
  40. * the new instance is to be initialized.
  41. */
  42. constructor(props) {
  43. super(props);
  44. // Bind event handlers so they are only bound once for every instance.
  45. this._onLinkingURL = this._onLinkingURL.bind(this);
  46. // In the Release configuration, React Native will (intentionally) throw
  47. // an unhandled JavascriptException for an unhandled JavaScript error.
  48. // This will effectively kill the application. In accord with the Web,
  49. // do not kill the application.
  50. this._maybeDisableExceptionsManager();
  51. }
  52. /**
  53. * Subscribe to notifications about activating URLs registered to be handled
  54. * by this app.
  55. *
  56. * @inheritdoc
  57. * @returns {void}
  58. * @see https://facebook.github.io/react-native/docs/linking.html
  59. */
  60. componentWillMount() {
  61. super.componentWillMount();
  62. Linking.addEventListener('url', this._onLinkingURL);
  63. }
  64. /**
  65. * Unsubscribe from notifications about activating URLs registered to be
  66. * handled by this app.
  67. *
  68. * @inheritdoc
  69. * @returns {void}
  70. * @see https://facebook.github.io/react-native/docs/linking.html
  71. */
  72. componentWillUnmount() {
  73. Linking.removeEventListener('url', this._onLinkingURL);
  74. super.componentWillUnmount();
  75. }
  76. /**
  77. * Attempts to disable the use of React Native
  78. * {@link ExceptionsManager#handleException} on platforms and in
  79. * configurations on/in which the use of the method in questions has been
  80. * determined to be undesirable. For example, React Native will
  81. * (intentionally) throw an unhandled JavascriptException for an
  82. * unhandled JavaScript error in the Release configuration. This will
  83. * effectively kill the application. In accord with the Web, do not kill the
  84. * application.
  85. *
  86. * @private
  87. * @returns {void}
  88. */
  89. _maybeDisableExceptionsManager() {
  90. if (__DEV__) {
  91. // As mentioned above, only the Release configuration was observed
  92. // to suffer.
  93. return;
  94. }
  95. if (Platform.OS !== 'android') {
  96. // A solution based on RTCSetFatalHandler was implemented on iOS and
  97. // it is preferred because it is at a later step of the
  98. // error/exception handling and it is specific to fatal
  99. // errors/exceptions which were observed to kill the application.
  100. // The solution implemented bellow was tested on Android only so it
  101. // is considered safest to use it there only.
  102. return;
  103. }
  104. const oldHandler = global.ErrorUtils.getGlobalHandler();
  105. const newHandler = _handleException;
  106. if (!oldHandler || oldHandler !== newHandler) {
  107. newHandler.next = oldHandler;
  108. global.ErrorUtils.setGlobalHandler(newHandler);
  109. }
  110. }
  111. /**
  112. * Notified by React's Linking API that a specific URL registered to be
  113. * handled by this App was activated.
  114. *
  115. * @param {Object} event - The details of the notification/event.
  116. * @param {string} event.url - The URL registered to be handled by this App
  117. * which was activated.
  118. * @private
  119. * @returns {void}
  120. */
  121. _onLinkingURL({ url }) {
  122. this._openURL(url);
  123. }
  124. }
  125. /**
  126. * Handles a (possibly unhandled) JavaScript error by preventing React Native
  127. * from converting a fatal error into an unhandled native exception which will
  128. * kill the application.
  129. *
  130. * @param {Error} error - The (possibly unhandled) JavaScript error to handle.
  131. * @param {boolean} fatal - True if the specified error is fatal; otherwise,
  132. * false.
  133. * @private
  134. * @returns {void}
  135. */
  136. function _handleException(error, fatal) {
  137. if (fatal) {
  138. // In the Release configuration, React Native will (intentionally) throw
  139. // an unhandled JavascriptException for an unhandled JavaScript error.
  140. // This will effectively kill the application. In accord with the Web,
  141. // do not kill the application.
  142. console.error(error);
  143. } else {
  144. // Forward to the next globalHandler of ErrorUtils.
  145. const next = _handleException.next;
  146. typeof next === 'function' && next(error, fatal);
  147. }
  148. }