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.

index.native.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // @flow
  2. // FIXME The bundler-related (and the browser-related) polyfills were born at
  3. // the very early days of prototyping the execution of lib-jitsi-meet on
  4. // react-native. Today, the feature base/lib-jitsi-meet should not be
  5. // responsible for such polyfills because it is not the only feature relying on
  6. // them. Additionally, the polyfills are usually necessary earlier than the
  7. // execution of base/lib-jitsi-meet (which is understandable given that the
  8. // polyfills are globals). The remaining problem to be solved here is where to
  9. // collect the polyfills' files.
  10. import './features/base/lib-jitsi-meet/native/polyfills-bundler';
  11. // FIXME: Remove once react-native-webrtc and react-native-prompt import
  12. // PropTypes from 'prop-types' instead of 'react'.
  13. import './features/base/react/prop-types-polyfill';
  14. import React, { Component } from 'react';
  15. import { AppRegistry, Linking, NativeModules } from 'react-native';
  16. import { App } from './features/app';
  17. import { equals } from './features/base/redux';
  18. import { IncomingCallApp } from './features/mobile/incoming-call';
  19. /**
  20. * The type of the React {@code Component} props of {@link Root}.
  21. */
  22. type Props = {
  23. /**
  24. * The URL, if any, with which the app was launched.
  25. */
  26. url: Object | string
  27. };
  28. /**
  29. * The type of the React {@code Component} state of {@link Root}.
  30. */
  31. type State = {
  32. /**
  33. * The URL, if any, with which the app was launched.
  34. */
  35. url: ?Object | string
  36. };
  37. /**
  38. * React Native doesn't support specifying props to the main/root component (in
  39. * the JS/JSX source code). So create a wrapper React Component (class) around
  40. * features/app's App instead.
  41. *
  42. * @extends Component
  43. */
  44. class Root extends Component<Props, State> {
  45. /**
  46. * Initializes a new {@code Root} instance.
  47. *
  48. * @param {Props} props - The read-only properties with which the new
  49. * instance is to be initialized.
  50. */
  51. constructor(props) {
  52. super(props);
  53. this.state = {
  54. url: this.props.url
  55. };
  56. // Handle the URL, if any, with which the app was launched. But props
  57. // have precedence.
  58. if (typeof this.props.url === 'undefined') {
  59. this._getInitialURL()
  60. .then(url => {
  61. if (typeof this.state.url === 'undefined') {
  62. this.setState({ url });
  63. }
  64. })
  65. .catch(err => {
  66. console.error('Failed to get initial URL', err);
  67. if (typeof this.state.url === 'undefined') {
  68. // Start with an empty URL if getting the initial URL
  69. // fails; otherwise, nothing will be rendered.
  70. this.setState({ url: null });
  71. }
  72. });
  73. }
  74. }
  75. /**
  76. * Gets the initial URL the app was launched with. This can be a universal
  77. * (or deep) link, or a CallKit intent in iOS. Since the native
  78. * {@code Linking} module doesn't provide a way to access intents in iOS,
  79. * those are handled with the {@code LaunchOptions} module, which
  80. * essentially provides a replacement which takes that into consideration.
  81. *
  82. * @private
  83. * @returns {Promise} - A promise which will be fulfilled with the URL that
  84. * the app was launched with.
  85. */
  86. _getInitialURL() {
  87. if (NativeModules.LaunchOptions) {
  88. return NativeModules.LaunchOptions.getInitialURL();
  89. }
  90. return Linking.getInitialURL();
  91. }
  92. /**
  93. * Implements React's {@link Component#componentWillReceiveProps()}.
  94. *
  95. * New props can be set from the native side by setting the appProperties
  96. * property (on iOS) or calling setAppProperties (on Android).
  97. *
  98. * @inheritdoc
  99. */
  100. componentWillReceiveProps({ url }) {
  101. equals(this.props.url, url) || this.setState({ url: url || null });
  102. }
  103. /**
  104. * Implements React's {@link Component#render()}.
  105. *
  106. * @inheritdoc
  107. * @returns {ReactElement}
  108. */
  109. render() {
  110. const { url } = this.state;
  111. // XXX We don't render the App component until we get the initial URL.
  112. // Either it's null or some other non-null defined value.
  113. if (typeof url === 'undefined') {
  114. return null;
  115. }
  116. const {
  117. // The following props are forked in state:
  118. url: _, // eslint-disable-line no-unused-vars
  119. // The remaining props are passed through to App.
  120. ...props
  121. } = this.props;
  122. return (
  123. <App
  124. { ...props }
  125. url = { url } />
  126. );
  127. }
  128. }
  129. // Register the main/root Component of JitsiMeetView.
  130. AppRegistry.registerComponent('App', () => Root);
  131. // Register the main/root Component of IncomingCallView.
  132. AppRegistry.registerComponent('IncomingCallApp', () => IncomingCallApp);