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

App.native.js 5.2KB

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