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 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * OverlayContainer component's property types.
  37. */
  38. type Props = {
  39. /**
  40. * Type of overlay that should be rendered.
  41. * XXX: We are using 'any' here because overlays are usually wrapped in
  42. * functions, so a 'Node' won't do.
  43. */
  44. overlay: any
  45. }
  46. /**
  47. * Implements a React {@link Component} that will display the correct overlay
  48. * when needed.
  49. */
  50. class OverlayContainer extends Component<Props> {
  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);