您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

App.native.js 5.9KB

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