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

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