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

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