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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. * Whether Picture-in-Picture is enabled. If {@code true}, a toolbar button
  37. * is rendered in the {@link Conference} view to afford entering
  38. * Picture-in-Picture.
  39. */
  40. pictureInPictureEnabled: boolean,
  41. /**
  42. * Whether the Welcome page is enabled. If {@code true}, the Welcome page is
  43. * rendered when the {@link App} is not at a location (URL) identifying
  44. * a Jitsi Meet conference/room.
  45. */
  46. welcomePageEnabled: boolean
  47. };
  48. /**
  49. * Root app {@code Component} on mobile/React Native.
  50. *
  51. * @extends AbstractApp
  52. */
  53. export class App extends AbstractApp {
  54. _init: Promise<*>;
  55. /**
  56. * Initializes a new {@code App} instance.
  57. *
  58. * @param {Props} props - The read-only React {@code Component} props with
  59. * which the new instance is to be initialized.
  60. */
  61. constructor(props: Props) {
  62. super(props);
  63. // In the Release configuration, React Native will (intentionally) throw
  64. // an unhandled JavascriptException for an unhandled JavaScript error.
  65. // This will effectively kill the app. In accord with the Web, do not
  66. // kill the app.
  67. this._maybeDisableExceptionsManager();
  68. }
  69. /**
  70. * Initializes the color scheme.
  71. *
  72. * @inheritdoc
  73. *
  74. * @returns {void}
  75. */
  76. componentDidMount() {
  77. super.componentDidMount();
  78. this._init.then(() => {
  79. // We set the color scheme early enough so then we avoid any
  80. // unnecessary re-renders.
  81. this.state.store.dispatch(setColorScheme(this.props.colorScheme));
  82. });
  83. }
  84. /**
  85. * Injects {@link AspectRatioDetector} in order to detect the aspect ratio
  86. * of this {@code App}'s user interface and afford {@link AspectRatioAware}.
  87. *
  88. * @override
  89. */
  90. _createMainElement(component, props) {
  91. return (
  92. <AspectRatioDetector>
  93. <ReducedUIDetector>
  94. { super._createMainElement(component, props) }
  95. </ReducedUIDetector>
  96. </AspectRatioDetector>
  97. );
  98. }
  99. /**
  100. * Attempts to disable the use of React Native
  101. * {@link ExceptionsManager#handleException} on platforms and in
  102. * configurations on/in which the use of the method in questions has been
  103. * determined to be undesirable. For example, React Native will
  104. * (intentionally) throw an unhandled {@code JavascriptException} for an
  105. * unhandled JavaScript error in the Release configuration. This will
  106. * effectively kill the app. In accord with the Web, do not kill the app.
  107. *
  108. * @private
  109. * @returns {void}
  110. */
  111. _maybeDisableExceptionsManager() {
  112. if (__DEV__) {
  113. // As mentioned above, only the Release configuration was observed
  114. // to suffer.
  115. return;
  116. }
  117. if (Platform.OS !== 'android') {
  118. // A solution based on RTCSetFatalHandler was implemented on iOS and
  119. // it is preferred because it is at a later step of the
  120. // error/exception handling and it is specific to fatal
  121. // errors/exceptions which were observed to kill the app. The
  122. // solution implemented bellow was tested on Android only so it is
  123. // considered safest to use it there only.
  124. return;
  125. }
  126. const oldHandler = global.ErrorUtils.getGlobalHandler();
  127. const newHandler = _handleException;
  128. if (!oldHandler || oldHandler !== newHandler) {
  129. newHandler.next = oldHandler;
  130. global.ErrorUtils.setGlobalHandler(newHandler);
  131. }
  132. }
  133. /**
  134. * Renders the platform specific dialog container.
  135. *
  136. * @returns {React$Element}
  137. */
  138. _renderDialogContainer() {
  139. return (
  140. <DialogContainer />
  141. );
  142. }
  143. }
  144. /**
  145. * Handles a (possibly unhandled) JavaScript error by preventing React Native
  146. * from converting a fatal error into an unhandled native exception which will
  147. * kill the app.
  148. *
  149. * @param {Error} error - The (possibly unhandled) JavaScript error to handle.
  150. * @param {boolean} fatal - If the specified error is fatal, {@code true};
  151. * otherwise, {@code false}.
  152. * @private
  153. * @returns {void}
  154. */
  155. function _handleException(error, fatal) {
  156. if (fatal) {
  157. // In the Release configuration, React Native will (intentionally) throw
  158. // an unhandled JavascriptException for an unhandled JavaScript error.
  159. // This will effectively kill the app. In accord with the Web, do not
  160. // kill the app.
  161. logger.error(error);
  162. } else {
  163. // Forward to the next globalHandler of ErrorUtils.
  164. const { next } = _handleException;
  165. typeof next === 'function' && next(error, fatal);
  166. }
  167. }