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

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