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.

OverlayContainer.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * Reference to the lazily loaded list of overlays.
  15. */
  16. let _overlays;
  17. /**
  18. * Returns the list of overlays which can be rendered by this container. The
  19. * list is lazily loaded the first time it's required.
  20. *
  21. * @returns {Array} - The list of overlay types which are available.
  22. */
  23. function getOverlays() {
  24. if (typeof _overlays === 'undefined') {
  25. const filmstripOnly
  26. = typeof interfaceConfig === 'object'
  27. && interfaceConfig.filmStripOnly;
  28. if (filmstripOnly) {
  29. _overlays = [
  30. PageReloadFilmstripOnlyOverlay,
  31. SuspendedFilmstripOnlyOverlay,
  32. UserMediaPermissionsFilmstripOnlyOverlay
  33. ];
  34. } else {
  35. _overlays = [
  36. PageReloadOverlay,
  37. SuspendedOverlay,
  38. UserMediaPermissionsOverlay,
  39. CallOverlay
  40. ];
  41. }
  42. }
  43. return _overlays;
  44. }
  45. /**
  46. * Implements a React {@link Component} that will display the correct overlay
  47. * when needed.
  48. */
  49. class OverlayContainer extends Component {
  50. /**
  51. * OverlayContainer component's property types.
  52. *
  53. * @static
  54. */
  55. static propTypes = {
  56. /**
  57. * Type of overlay that should be rendered.
  58. */
  59. overlay: PropTypes.element
  60. };
  61. /**
  62. * Implements React's {@link Component#render()}.
  63. *
  64. * @inheritdoc
  65. * @public
  66. * @returns {ReactElement|null}
  67. */
  68. render() {
  69. const { overlay } = this.props;
  70. return overlay ? React.createElement(overlay, {}) : null;
  71. }
  72. }
  73. /**
  74. * Maps (parts of) the redux state to the associated {@code OverlayContainer}'s
  75. * props.
  76. *
  77. * @param {Object} state - The redux state.
  78. * @private
  79. * @returns {{
  80. * overlay: ?Object
  81. * }}
  82. */
  83. function _mapStateToProps(state) {
  84. let overlay;
  85. for (const o of getOverlays()) {
  86. // react-i18n / react-redux wrap components and thus we cannot access
  87. // the wrapped component's static methods directly.
  88. const component = o.WrappedComponent || o;
  89. if (component.needsRender(state)) {
  90. overlay = o;
  91. break;
  92. }
  93. }
  94. return {
  95. /**
  96. * Type of overlay that should be rendered.
  97. */
  98. overlay
  99. };
  100. }
  101. export default connect(_mapStateToProps)(OverlayContainer);