Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AbstractApp.js 2.5KB

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