您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AbstractApp.ts 2.5KB

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