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

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