您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

App.native.js 5.9KB

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