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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 { updateFlags } from '../../base/flags';
  8. import '../../base/jwt';
  9. import { Platform } from '../../base/react';
  10. import {
  11. AspectRatioDetector,
  12. ReducedUIDetector
  13. } from '../../base/responsive-ui';
  14. import { updateSettings } from '../../base/settings';
  15. import '../../google-api';
  16. import '../../mobile/audio-mode';
  17. import '../../mobile/back-button';
  18. import '../../mobile/background';
  19. import '../../mobile/call-integration';
  20. import '../../mobile/external-api';
  21. import '../../mobile/full-screen';
  22. import '../../mobile/permissions';
  23. import '../../mobile/picture-in-picture';
  24. import '../../mobile/proximity';
  25. import '../../mobile/wake-lock';
  26. import '../../mobile/watchos';
  27. import { AbstractApp } from './AbstractApp';
  28. import type { Props as AbstractAppProps } from './AbstractApp';
  29. declare var __DEV__;
  30. const logger = require('jitsi-meet-logger').getLogger(__filename);
  31. /**
  32. * The type of React {@code Component} props of {@link App}.
  33. */
  34. type Props = AbstractAppProps & {
  35. /**
  36. * An object of colors that override the default colors of the app/sdk.
  37. */
  38. colorScheme: ?Object,
  39. /**
  40. * Identifier for this app on the native side.
  41. */
  42. externalAPIScope: string,
  43. /**
  44. * An object with the feature flags.
  45. */
  46. flags: Object,
  47. /**
  48. * An object with user information (display name, email, avatar URL).
  49. */
  50. userInfo: ?Object
  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 these early enough so then we avoid any unnecessary re-renders.
  84. const { dispatch } = this.state.store;
  85. dispatch(setColorScheme(this.props.colorScheme));
  86. dispatch(updateFlags(this.props.flags));
  87. dispatch(updateSettings(this.props.userInfo || {}));
  88. });
  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. /**
  140. * Renders the platform specific dialog container.
  141. *
  142. * @returns {React$Element}
  143. */
  144. _renderDialogContainer() {
  145. return (
  146. <DialogContainer />
  147. );
  148. }
  149. }
  150. /**
  151. * Handles a (possibly unhandled) JavaScript error by preventing React Native
  152. * from converting a fatal error into an unhandled native exception which will
  153. * kill the app.
  154. *
  155. * @param {Error} error - The (possibly unhandled) JavaScript error to handle.
  156. * @param {boolean} fatal - If the specified error is fatal, {@code true};
  157. * otherwise, {@code false}.
  158. * @private
  159. * @returns {void}
  160. */
  161. function _handleException(error, fatal) {
  162. if (fatal) {
  163. // In the Release configuration, React Native will (intentionally) throw
  164. // an unhandled JavascriptException for an unhandled JavaScript error.
  165. // This will effectively kill the app. In accord with the Web, do not
  166. // kill the app.
  167. logger.error(error);
  168. } else {
  169. // Forward to the next globalHandler of ErrorUtils.
  170. const { next } = _handleException;
  171. typeof next === 'function' && next(error, fatal);
  172. }
  173. }