Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

OverlayContainer.js 4.2KB

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