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

OverlayContainer.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { CallOverlay } from '../../base/jwt';
  5. import PageReloadFilmstripOnlyOverlay from './PageReloadFilmstripOnlyOverlay';
  6. import PageReloadOverlay from './PageReloadOverlay';
  7. import SuspendedFilmstripOnlyOverlay from './SuspendedFilmstripOnlyOverlay';
  8. import SuspendedOverlay from './SuspendedOverlay';
  9. import UserMediaPermissionsFilmstripOnlyOverlay
  10. from './UserMediaPermissionsFilmstripOnlyOverlay';
  11. import UserMediaPermissionsOverlay from './UserMediaPermissionsOverlay';
  12. declare var interfaceConfig: Object;
  13. /**
  14. * The lazily-initialized list of overlay React {@link Component} types used The
  15. * user interface is filmstrip-only.
  16. *
  17. * XXX The value is meant to be compile-time defined so it does not contradict
  18. * our coding style to not have global values that are runtime defined and
  19. * merely works around side effects of circular imports.
  20. *
  21. * @type Array
  22. */
  23. let _filmstripOnlyOverlays;
  24. /**
  25. * The lazily-initialized list of overlay React {@link Component} types used The
  26. * user interface is not filmstrip-only.
  27. *
  28. * XXX The value is meant to be compile-time defined so it does not contradict
  29. * our coding style to not have global values that are runtime defined and
  30. * merely works around side effects of circular imports.
  31. *
  32. * @type Array
  33. */
  34. let _nonFilmstripOnlyOverlays;
  35. /**
  36. * The type of the React {@link Component} props of {@code OverlayContainer}.
  37. */
  38. type Props = {
  39. /**
  40. * The React {@link Component} type of overlay to be rendered by the
  41. * associated {@code OverlayContainer}.
  42. */
  43. overlay: ?React$ComponentType<*>
  44. }
  45. /**
  46. * Implements a React {@link Component} that will display the correct overlay
  47. * when needed.
  48. */
  49. class OverlayContainer extends Component<Props> {
  50. /**
  51. * Implements React's {@link Component#render()}.
  52. *
  53. * @inheritdoc
  54. * @public
  55. * @returns {ReactElement|null}
  56. */
  57. render() {
  58. const { overlay } = this.props;
  59. return overlay ? React.createElement(overlay, {}) : null;
  60. }
  61. }
  62. /**
  63. * Returns the list of overlay React {@link Component} types to be rendered by
  64. * {@code OverlayContainer}. The list is lazily initialized the first time it is
  65. * required in order to works around side effects of circular imports.
  66. *
  67. * @param {boolean} filmstripOnly - The indicator which determines whether the
  68. * user interface is filmstrip-only.
  69. * @returns {Array} The list of overlay React {@code Component} types to be
  70. * rendered by {@code OverlayContainer}.
  71. */
  72. function _getOverlays(filmstripOnly) {
  73. let overlays;
  74. if (filmstripOnly) {
  75. if (!(overlays = _filmstripOnlyOverlays)) {
  76. overlays = _filmstripOnlyOverlays = [
  77. PageReloadFilmstripOnlyOverlay,
  78. SuspendedFilmstripOnlyOverlay,
  79. UserMediaPermissionsFilmstripOnlyOverlay
  80. ];
  81. }
  82. } else if (!(overlays = _nonFilmstripOnlyOverlays)) {
  83. overlays = _nonFilmstripOnlyOverlays = [
  84. PageReloadOverlay,
  85. SuspendedOverlay,
  86. UserMediaPermissionsOverlay,
  87. CallOverlay
  88. ];
  89. }
  90. return overlays;
  91. }
  92. /**
  93. * Maps (parts of) the redux state to the associated {@code OverlayContainer}'s
  94. * props.
  95. *
  96. * @param {Object} state - The redux state.
  97. * @private
  98. * @returns {{
  99. * overlay: ?Object
  100. * }}
  101. */
  102. function _mapStateToProps(state) {
  103. // XXX In the future interfaceConfig is expected to not be a global variable
  104. // but a redux state like config. Hence, the variable filmStripOnly
  105. // naturally belongs here in preparation for the future.
  106. const filmstripOnly
  107. = typeof interfaceConfig === 'object' && interfaceConfig.filmStripOnly;
  108. let overlay;
  109. for (const o of _getOverlays(filmstripOnly)) {
  110. // react-i18n / react-redux wrap components and thus we cannot access
  111. // the wrapped component's static methods directly.
  112. const component = o.WrappedComponent || o;
  113. if (component.needsRender(state)) {
  114. overlay = o;
  115. break;
  116. }
  117. }
  118. return {
  119. /**
  120. * The React {@link Component} type of overlay to be rendered by the
  121. * associated {@code OverlayContainer}.
  122. */
  123. overlay
  124. };
  125. }
  126. export default connect(_mapStateToProps)(OverlayContainer);