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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. * The deferred for the initialisation {{promise, resolve, reject}}.
  27. */
  28. _init: {
  29. promise: Promise<any>;
  30. };
  31. /**
  32. * Initializes the app.
  33. *
  34. * @inheritdoc
  35. */
  36. async componentDidMount() {
  37. await super.componentDidMount();
  38. // If a URL was explicitly specified to this React Component, then
  39. // open it; otherwise, use a default.
  40. this._openURL(toURLString(this.props.url) || this._getDefaultURL());
  41. }
  42. /**
  43. * Implements React Component's componentDidUpdate.
  44. *
  45. * @inheritdoc
  46. */
  47. async componentDidUpdate(prevProps: IProps) {
  48. const previousUrl = toURLString(prevProps.url);
  49. const currentUrl = toURLString(this.props.url);
  50. const previousTimestamp = prevProps.timestamp;
  51. const currentTimestamp = this.props.timestamp;
  52. await this._init.promise;
  53. // Deal with URL changes.
  54. if (previousUrl !== currentUrl
  55. // XXX Refer to the implementation of loadURLObject: in
  56. // ios/sdk/src/JitsiMeetView.m for further information.
  57. || previousTimestamp !== currentTimestamp) {
  58. this._openURL(currentUrl || this._getDefaultURL());
  59. }
  60. }
  61. /**
  62. * Gets the default URL to be opened when this {@code App} mounts.
  63. *
  64. * @protected
  65. * @returns {string} The default URL to be opened when this {@code App}
  66. * mounts.
  67. */
  68. _getDefaultURL() {
  69. // @ts-ignore
  70. return getDefaultURL(this.state.store);
  71. }
  72. /**
  73. * Navigates this {@code AbstractApp} to (i.e. Opens) a specific URL.
  74. *
  75. * @param {Object|string} url - The URL to navigate this {@code AbstractApp}
  76. * to (i.e. The URL to open).
  77. * @protected
  78. * @returns {void}
  79. */
  80. _openURL(url: string | Object) {
  81. this.state.store?.dispatch(appNavigate(toURLString(url)));
  82. }
  83. }