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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // @flow
  2. import React from 'react';
  3. import { Linking } from 'react-native';
  4. import '../../analytics';
  5. import '../../authentication';
  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/callkit';
  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. * Whether the add people feature is enabled.
  33. */
  34. addPeopleEnabled: boolean,
  35. /**
  36. * Whether the dial-out feature is enabled.
  37. */
  38. dialOutEnabled: boolean,
  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. /**
  59. * Initializes a new {@code App} instance.
  60. *
  61. * @param {Props} props - The read-only React {@code Component} props with
  62. * which the new instance is to be initialized.
  63. */
  64. constructor(props: Props) {
  65. super(props);
  66. // Bind event handlers so they are only bound once for every instance.
  67. this._onLinkingURL = this._onLinkingURL.bind(this);
  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. * Subscribe to notifications about activating URLs registered to be handled
  76. * by this app.
  77. *
  78. * @inheritdoc
  79. * @returns {void}
  80. * @see https://facebook.github.io/react-native/docs/linking.html
  81. */
  82. componentDidMount() {
  83. super.componentDidMount();
  84. Linking.addEventListener('url', this._onLinkingURL);
  85. }
  86. /**
  87. * Unsubscribe from notifications about activating URLs registered to be
  88. * handled by this app.
  89. *
  90. * @inheritdoc
  91. * @returns {void}
  92. * @see https://facebook.github.io/react-native/docs/linking.html
  93. */
  94. componentWillUnmount() {
  95. Linking.removeEventListener('url', this._onLinkingURL);
  96. super.componentWillUnmount();
  97. }
  98. /**
  99. * Injects {@link AspectRatioDetector} in order to detect the aspect ratio
  100. * of this {@code App}'s user interface and afford {@link AspectRatioAware}.
  101. *
  102. * @override
  103. */
  104. _createMainElement(component, props) {
  105. return (
  106. <AspectRatioDetector>
  107. <ReducedUIDetector>
  108. { super._createMainElement(component, props) }
  109. </ReducedUIDetector>
  110. </AspectRatioDetector>
  111. );
  112. }
  113. /**
  114. * Attempts to disable the use of React Native
  115. * {@link ExceptionsManager#handleException} on platforms and in
  116. * configurations on/in which the use of the method in questions has been
  117. * determined to be undesirable. For example, React Native will
  118. * (intentionally) throw an unhandled {@code JavascriptException} for an
  119. * unhandled JavaScript error in the Release configuration. This will
  120. * effectively kill the app. In accord with the Web, do not kill the app.
  121. *
  122. * @private
  123. * @returns {void}
  124. */
  125. _maybeDisableExceptionsManager() {
  126. if (__DEV__) {
  127. // As mentioned above, only the Release configuration was observed
  128. // to suffer.
  129. return;
  130. }
  131. if (Platform.OS !== 'android') {
  132. // A solution based on RTCSetFatalHandler was implemented on iOS and
  133. // it is preferred because it is at a later step of the
  134. // error/exception handling and it is specific to fatal
  135. // errors/exceptions which were observed to kill the app. The
  136. // solution implemented bellow was tested on Android only so it is
  137. // considered safest to use it there only.
  138. return;
  139. }
  140. const oldHandler = global.ErrorUtils.getGlobalHandler();
  141. const newHandler = _handleException;
  142. if (!oldHandler || oldHandler !== newHandler) {
  143. newHandler.next = oldHandler;
  144. global.ErrorUtils.setGlobalHandler(newHandler);
  145. }
  146. }
  147. _onLinkingURL: (*) => void;
  148. /**
  149. * Notified by React's Linking API that a specific URL registered to be
  150. * handled by this app was activated.
  151. *
  152. * @param {Object} event - The details of the notification/event.
  153. * @param {string} event.url - The URL registered to be handled by this app
  154. * which was activated.
  155. * @private
  156. * @returns {void}
  157. */
  158. _onLinkingURL({ url }) {
  159. super._openURL(url);
  160. }
  161. /**
  162. * Renders the platform specific dialog container.
  163. *
  164. * @returns {React$Element}
  165. */
  166. _renderDialogContainer() {
  167. return (
  168. <DialogContainer />
  169. );
  170. }
  171. }
  172. /**
  173. * Handles a (possibly unhandled) JavaScript error by preventing React Native
  174. * from converting a fatal error into an unhandled native exception which will
  175. * kill the app.
  176. *
  177. * @param {Error} error - The (possibly unhandled) JavaScript error to handle.
  178. * @param {boolean} fatal - If the specified error is fatal, {@code true};
  179. * otherwise, {@code false}.
  180. * @private
  181. * @returns {void}
  182. */
  183. function _handleException(error, fatal) {
  184. if (fatal) {
  185. // In the Release configuration, React Native will (intentionally) throw
  186. // an unhandled JavascriptException for an unhandled JavaScript error.
  187. // This will effectively kill the app. In accord with the Web, do not
  188. // kill the app.
  189. logger.error(error);
  190. } else {
  191. // Forward to the next globalHandler of ErrorUtils.
  192. const { next } = _handleException;
  193. typeof next === 'function' && next(error, fatal);
  194. }
  195. }