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

App.native.js 6.3KB

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