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.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // @flow
  2. import React, { Fragment } from 'react';
  3. import { BaseApp } from '../../base/app';
  4. import { toURLString } from '../../base/util';
  5. import '../../follow-me';
  6. import { OverlayContainer } from '../../overlay';
  7. import { appNavigate } from '../actions';
  8. import { getDefaultURL } from '../functions';
  9. /**
  10. * The type of React {@code Component} props of {@link AbstractApp}.
  11. */
  12. export type Props = {
  13. /**
  14. * XXX Refer to the implementation of loadURLObject: in
  15. * ios/sdk/src/JitsiMeetView.m for further information.
  16. */
  17. timestamp: any,
  18. /**
  19. * The URL, if any, with which the app was launched.
  20. */
  21. url: Object | string
  22. };
  23. /**
  24. * Base (abstract) class for main App component.
  25. *
  26. * @abstract
  27. */
  28. export class AbstractApp extends BaseApp<Props, *> {
  29. _init: Promise<*>;
  30. /**
  31. * Initializes the app.
  32. *
  33. * @inheritdoc
  34. */
  35. componentDidMount() {
  36. super.componentDidMount();
  37. this._init.then(() => {
  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. /**
  44. * Implements React Component's componentDidUpdate.
  45. *
  46. * @inheritdoc
  47. */
  48. componentDidUpdate(prevProps: Props) {
  49. const previousUrl = toURLString(prevProps.url);
  50. const currentUrl = toURLString(this.props.url);
  51. const previousTimestamp = prevProps.timestamp;
  52. const currentTimestamp = this.props.timestamp;
  53. this._init.then(() => {
  54. // Deal with URL changes.
  55. if (previousUrl !== currentUrl
  56. // XXX Refer to the implementation of loadURLObject: in
  57. // ios/sdk/src/JitsiMeetView.m for further information.
  58. || previousTimestamp !== currentTimestamp) {
  59. this._openURL(currentUrl || this._getDefaultURL());
  60. }
  61. });
  62. }
  63. /**
  64. * Creates an extra {@link ReactElement}s to be added (unconditionaly)
  65. * alongside the main element.
  66. *
  67. * @abstract
  68. * @protected
  69. * @returns {ReactElement}
  70. */
  71. _createExtraElement() {
  72. return (
  73. <Fragment>
  74. <OverlayContainer />
  75. </Fragment>
  76. );
  77. }
  78. _createMainElement: (React$Element<*>, Object) => ?React$Element<*>;
  79. /**
  80. * Gets the default URL to be opened when this {@code App} mounts.
  81. *
  82. * @protected
  83. * @returns {string} The default URL to be opened when this {@code App}
  84. * mounts.
  85. */
  86. _getDefaultURL() {
  87. return getDefaultURL(this.state.store);
  88. }
  89. /**
  90. * Navigates this {@code AbstractApp} to (i.e. Opens) a specific URL.
  91. *
  92. * @param {Object|string} url - The URL to navigate this {@code AbstractApp}
  93. * to (i.e. The URL to open).
  94. * @protected
  95. * @returns {void}
  96. */
  97. _openURL(url) {
  98. this.state.store.dispatch(appNavigate(toURLString(url)));
  99. }
  100. }