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 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // @flow
  2. import React from 'react';
  3. import '../../analytics';
  4. import '../../authentication';
  5. import { setColorScheme } from '../../base/color-scheme';
  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. * An object of colors that override the default colors of the app/sdk.
  33. */
  34. colorScheme: ?Object,
  35. /**
  36. * Identifier for this app on the native side.
  37. */
  38. externalAPIScope: string,
  39. /**
  40. * Whether Picture-in-Picture is enabled. If {@code true}, a toolbar button
  41. * is rendered in the {@link Conference} view to afford entering
  42. * Picture-in-Picture.
  43. */
  44. pictureInPictureEnabled: boolean,
  45. /**
  46. * Whether the Welcome page is enabled. If {@code true}, the Welcome page is
  47. * rendered when the {@link App} is not at a location (URL) identifying
  48. * a Jitsi Meet conference/room.
  49. */
  50. welcomePageEnabled: boolean
  51. };
  52. /**
  53. * Root app {@code Component} on mobile/React Native.
  54. *
  55. * @extends AbstractApp
  56. */
  57. export class App extends AbstractApp {
  58. _init: Promise<*>;
  59. /**
  60. * Initializes a new {@code App} instance.
  61. *
  62. * @param {Props} props - The read-only React {@code Component} props with
  63. * which the new instance is to be initialized.
  64. */
  65. constructor(props: Props) {
  66. super(props);
  67. // In the Release configuration, React Native will (intentionally) throw
  68. // an unhandled JavascriptException for an unhandled JavaScript error.
  69. // This will effectively kill the app. In accord with the Web, do not
  70. // kill the app.
  71. this._maybeDisableExceptionsManager();
  72. }
  73. /**
  74. * Initializes the color scheme.
  75. *
  76. * @inheritdoc
  77. *
  78. * @returns {void}
  79. */
  80. componentDidMount() {
  81. super.componentDidMount();
  82. this._init.then(() => {
  83. // We set the color scheme early enough so then we avoid any
  84. // unnecessary re-renders.
  85. this.state.store.dispatch(setColorScheme(this.props.colorScheme));
  86. });
  87. }
  88. /**
  89. * Injects {@link AspectRatioDetector} in order to detect the aspect ratio
  90. * of this {@code App}'s user interface and afford {@link AspectRatioAware}.
  91. *
  92. * @override
  93. */
  94. _createMainElement(component, props) {
  95. return (
  96. <AspectRatioDetector>
  97. <ReducedUIDetector>
  98. { super._createMainElement(component, props) }
  99. </ReducedUIDetector>
  100. </AspectRatioDetector>
  101. );
  102. }
  103. /**
  104. * Attempts to disable the use of React Native
  105. * {@link ExceptionsManager#handleException} on platforms and in
  106. * configurations on/in which the use of the method in questions has been
  107. * determined to be undesirable. For example, React Native will
  108. * (intentionally) throw an unhandled {@code JavascriptException} for an
  109. * unhandled JavaScript error in the Release configuration. This will
  110. * effectively kill the app. In accord with the Web, do not kill the app.
  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 app. The
  126. // solution implemented bellow was tested on Android only so it is
  127. // 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. * Renders the platform specific dialog container.
  139. *
  140. * @returns {React$Element}
  141. */
  142. _renderDialogContainer() {
  143. return (
  144. <DialogContainer />
  145. );
  146. }
  147. }
  148. /**
  149. * Handles a (possibly unhandled) JavaScript error by preventing React Native
  150. * from converting a fatal error into an unhandled native exception which will
  151. * kill the app.
  152. *
  153. * @param {Error} error - The (possibly unhandled) JavaScript error to handle.
  154. * @param {boolean} fatal - If the specified error is fatal, {@code true};
  155. * otherwise, {@code false}.
  156. * @private
  157. * @returns {void}
  158. */
  159. function _handleException(error, fatal) {
  160. if (fatal) {
  161. // In the Release configuration, React Native will (intentionally) throw
  162. // an unhandled JavascriptException for an unhandled JavaScript error.
  163. // This will effectively kill the app. In accord with the Web, do not
  164. // kill the app.
  165. logger.error(error);
  166. } else {
  167. // Forward to the next globalHandler of ErrorUtils.
  168. const { next } = _handleException;
  169. typeof next === 'function' && next(error, fatal);
  170. }
  171. }