Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

App.native.js 7.0KB

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