Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

App.native.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 { AspectRatioDetector } from '../../base/aspect-ratio';
  8. import { Platform } from '../../base/react';
  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. * Overrides the super method to inject {@link AspectRatioDetector} as
  80. * the top most component.
  81. *
  82. * @override
  83. */
  84. _createElement(component, props) {
  85. return (
  86. <AspectRatioDetector>
  87. {super._createElement(component, props)}
  88. </AspectRatioDetector>);
  89. }
  90. /**
  91. * Attempts to disable the use of React Native
  92. * {@link ExceptionsManager#handleException} on platforms and in
  93. * configurations on/in which the use of the method in questions has been
  94. * determined to be undesirable. For example, React Native will
  95. * (intentionally) throw an unhandled JavascriptException for an
  96. * unhandled JavaScript error in the Release configuration. This will
  97. * effectively kill the application. In accord with the Web, do not kill the
  98. * application.
  99. *
  100. * @private
  101. * @returns {void}
  102. */
  103. _maybeDisableExceptionsManager() {
  104. if (__DEV__) {
  105. // As mentioned above, only the Release configuration was observed
  106. // to suffer.
  107. return;
  108. }
  109. if (Platform.OS !== 'android') {
  110. // A solution based on RTCSetFatalHandler was implemented on iOS and
  111. // it is preferred because it is at a later step of the
  112. // error/exception handling and it is specific to fatal
  113. // errors/exceptions which were observed to kill the application.
  114. // The solution implemented bellow was tested on Android only so it
  115. // is considered safest to use it there only.
  116. return;
  117. }
  118. const oldHandler = global.ErrorUtils.getGlobalHandler();
  119. const newHandler = _handleException;
  120. if (!oldHandler || oldHandler !== newHandler) {
  121. newHandler.next = oldHandler;
  122. global.ErrorUtils.setGlobalHandler(newHandler);
  123. }
  124. }
  125. /**
  126. * Notified by React's Linking API that a specific URL registered to be
  127. * handled by this App was activated.
  128. *
  129. * @param {Object} event - The details of the notification/event.
  130. * @param {string} event.url - The URL registered to be handled by this App
  131. * which was activated.
  132. * @private
  133. * @returns {void}
  134. */
  135. _onLinkingURL({ url }) {
  136. this._openURL(url);
  137. }
  138. }
  139. /**
  140. * Handles a (possibly unhandled) JavaScript error by preventing React Native
  141. * from converting a fatal error into an unhandled native exception which will
  142. * kill the application.
  143. *
  144. * @param {Error} error - The (possibly unhandled) JavaScript error to handle.
  145. * @param {boolean} fatal - True if the specified error is fatal; otherwise,
  146. * false.
  147. * @private
  148. * @returns {void}
  149. */
  150. function _handleException(error, fatal) {
  151. if (fatal) {
  152. // In the Release configuration, React Native will (intentionally) throw
  153. // an unhandled JavascriptException for an unhandled JavaScript error.
  154. // This will effectively kill the application. In accord with the Web,
  155. // do not kill the application.
  156. console.error(error);
  157. } else {
  158. // Forward to the next globalHandler of ErrorUtils.
  159. const next = _handleException.next;
  160. typeof next === 'function' && next(error, fatal);
  161. }
  162. }