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

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