Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

App.native.js 6.1KB

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