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

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