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 6.2KB

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