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

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