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

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