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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. * App component's property types.
  26. */
  27. type Props = AbstractAppProps & {
  28. /**
  29. * Whether the add people feature is enabled or not.
  30. */
  31. addPeopleEnabled: boolean,
  32. /**
  33. * Whether the dial-out feature is enabled or not.
  34. */
  35. dialOutEnabled: boolean,
  36. /**
  37. * Whether Picture-in-Picture is enabled. If {@code true}, a toolbar
  38. * button 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
  44. * page is rendered when the {@link App} is not at a location (URL)
  45. * identifying a Jitsi Meet conference/room.
  46. */
  47. welcomePageEnabled: boolean
  48. };
  49. /**
  50. * Root application component.
  51. *
  52. * @extends AbstractApp
  53. */
  54. export class App extends AbstractApp {
  55. /**
  56. * Initializes a new App instance.
  57. *
  58. * @param {Object} props - The read-only React Component props with which
  59. * 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 application. In accord with the Web,
  68. // do not kill the application.
  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 JavascriptException for an
  116. * unhandled JavaScript error in the Release configuration. This will
  117. * effectively kill the application. In accord with the Web, do not kill the
  118. * application.
  119. *
  120. * @private
  121. * @returns {void}
  122. */
  123. _maybeDisableExceptionsManager() {
  124. if (__DEV__) {
  125. // As mentioned above, only the Release configuration was observed
  126. // to suffer.
  127. return;
  128. }
  129. if (Platform.OS !== 'android') {
  130. // A solution based on RTCSetFatalHandler was implemented on iOS and
  131. // it is preferred because it is at a later step of the
  132. // error/exception handling and it is specific to fatal
  133. // errors/exceptions which were observed to kill the application.
  134. // The solution implemented bellow was tested on Android only so it
  135. // is considered safest to use it there only.
  136. return;
  137. }
  138. const oldHandler = global.ErrorUtils.getGlobalHandler();
  139. const newHandler = _handleException;
  140. if (!oldHandler || oldHandler !== newHandler) {
  141. newHandler.next = oldHandler;
  142. global.ErrorUtils.setGlobalHandler(newHandler);
  143. }
  144. }
  145. _onLinkingURL: (*) => void;
  146. /**
  147. * Notified by React's Linking API that a specific URL registered to be
  148. * handled by this App was activated.
  149. *
  150. * @param {Object} event - The details of the notification/event.
  151. * @param {string} event.url - The URL registered to be handled by this App
  152. * which was activated.
  153. * @private
  154. * @returns {void}
  155. */
  156. _onLinkingURL({ url }) {
  157. super._openURL(url);
  158. }
  159. }
  160. /**
  161. * Handles a (possibly unhandled) JavaScript error by preventing React Native
  162. * from converting a fatal error into an unhandled native exception which will
  163. * kill the application.
  164. *
  165. * @param {Error} error - The (possibly unhandled) JavaScript error to handle.
  166. * @param {boolean} fatal - True if the specified error is fatal; otherwise,
  167. * false.
  168. * @private
  169. * @returns {void}
  170. */
  171. function _handleException(error, fatal) {
  172. if (fatal) {
  173. // In the Release configuration, React Native will (intentionally) throw
  174. // an unhandled JavascriptException for an unhandled JavaScript error.
  175. // This will effectively kill the application. In accord with the Web,
  176. // do not kill the application.
  177. console.error(error);
  178. } else {
  179. // Forward to the next globalHandler of ErrorUtils.
  180. const next = _handleException.next;
  181. typeof next === 'function' && next(error, fatal);
  182. }
  183. }