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

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