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

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