您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AbstractApp.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 '../../base/lastn'; // Register lastN middleware
  8. import '../../rejoin'; // Enable rejoin analytics
  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. { this._createExtraPlatformSpecificElement() }
  78. </Fragment>
  79. );
  80. }
  81. /**
  82. * Renders platform specific extra elements to be added alongside with the main element, if need be.
  83. *
  84. * NOTE: Overridden by child components.
  85. *
  86. * @returns {React$Element}
  87. */
  88. _createExtraPlatformSpecificElement() {
  89. return null;
  90. }
  91. _createMainElement: (React$Element<*>, Object) => ?React$Element<*>;
  92. /**
  93. * Gets the default URL to be opened when this {@code App} mounts.
  94. *
  95. * @protected
  96. * @returns {string} The default URL to be opened when this {@code App}
  97. * mounts.
  98. */
  99. _getDefaultURL() {
  100. return getDefaultURL(this.state.store);
  101. }
  102. /**
  103. * Navigates this {@code AbstractApp} to (i.e. Opens) a specific URL.
  104. *
  105. * @param {Object|string} url - The URL to navigate this {@code AbstractApp}
  106. * to (i.e. The URL to open).
  107. * @protected
  108. * @returns {void}
  109. */
  110. _openURL(url) {
  111. this.state.store.dispatch(appNavigate(toURLString(url)));
  112. }
  113. }