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.

AbstractApp.ts 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import BaseApp from '../../base/app/components/BaseApp';
  2. import { toURLString } from '../../base/util/uri';
  3. import { appNavigate } from '../actions';
  4. import { getDefaultURL } from '../functions';
  5. /**
  6. * The type of React {@code Component} props of {@link AbstractApp}.
  7. */
  8. export interface IProps {
  9. /**
  10. * XXX Refer to the implementation of loadURLObject: in
  11. * ios/sdk/src/JitsiMeetView.m for further information.
  12. */
  13. timestamp: number;
  14. /**
  15. * The URL, if any, with which the app was launched.
  16. */
  17. url: Object | string;
  18. }
  19. /**
  20. * Base (abstract) class for main App component.
  21. *
  22. * @abstract
  23. */
  24. export class AbstractApp<P extends IProps = IProps> extends BaseApp<P> {
  25. /**
  26. * Initializes the app.
  27. *
  28. * @inheritdoc
  29. */
  30. async componentDidMount() {
  31. await super.componentDidMount();
  32. // If a URL was explicitly specified to this React Component, then
  33. // open it; otherwise, use a default.
  34. this._openURL(toURLString(this.props.url) || this._getDefaultURL());
  35. }
  36. /**
  37. * Implements React Component's componentDidUpdate.
  38. *
  39. * @inheritdoc
  40. */
  41. async componentDidUpdate(prevProps: IProps) {
  42. const previousUrl = toURLString(prevProps.url);
  43. const currentUrl = toURLString(this.props.url);
  44. const previousTimestamp = prevProps.timestamp;
  45. const currentTimestamp = this.props.timestamp;
  46. await this._init.promise;
  47. // Deal with URL changes.
  48. if (previousUrl !== currentUrl
  49. // XXX Refer to the implementation of loadURLObject: in
  50. // ios/sdk/src/JitsiMeetView.m for further information.
  51. || previousTimestamp !== currentTimestamp) {
  52. this._openURL(currentUrl || this._getDefaultURL());
  53. }
  54. }
  55. /**
  56. * Gets the default URL to be opened when this {@code App} mounts.
  57. *
  58. * @protected
  59. * @returns {string} The default URL to be opened when this {@code App}
  60. * mounts.
  61. */
  62. _getDefaultURL() {
  63. // @ts-ignore
  64. return getDefaultURL(this.state.store);
  65. }
  66. /**
  67. * Navigates this {@code AbstractApp} to (i.e. Opens) a specific URL.
  68. *
  69. * @param {Object|string} url - The URL to navigate this {@code AbstractApp}
  70. * to (i.e. The URL to open).
  71. * @protected
  72. * @returns {void}
  73. */
  74. _openURL(url: string | Object) {
  75. this.state.store?.dispatch(appNavigate(toURLString(url)));
  76. }
  77. }