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.3KB

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