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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. import PropTypes from 'prop-types';
  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. * Implements a React Component that will display the correct overlay when
  15. * needed.
  16. */
  17. class OverlayContainer extends Component {
  18. /**
  19. * OverlayContainer component's property types.
  20. *
  21. * @static
  22. */
  23. static propTypes = {
  24. /**
  25. * The browser which is used currently.
  26. *
  27. * NOTE: Used by UserMediaPermissionsOverlay only.
  28. *
  29. * @private
  30. * @type {string}
  31. */
  32. _browser: PropTypes.string,
  33. /**
  34. * The indicator which determines whether the {@link CallOverlay} is
  35. * displayed/visible.
  36. *
  37. * @private
  38. * @type {boolean}
  39. */
  40. _callOverlayVisible: PropTypes.bool,
  41. /**
  42. * The indicator which determines whether the status of the
  43. * JitsiConnection object has been "established" or not.
  44. *
  45. * NOTE: Used by PageReloadOverlay only.
  46. *
  47. * @private
  48. * @type {boolean}
  49. */
  50. _connectionEstablished: PropTypes.bool,
  51. /**
  52. * The indicator which determines whether a critical error for reload
  53. * has been received.
  54. *
  55. * NOTE: Used by PageReloadOverlay only.
  56. *
  57. * @private
  58. * @type {boolean}
  59. */
  60. _haveToReload: PropTypes.bool,
  61. /**
  62. * The indicator which determines whether the GUM permissions prompt is
  63. * displayed or not.
  64. *
  65. * NOTE: Used by UserMediaPermissionsOverlay only.
  66. *
  67. * @private
  68. * @type {boolean}
  69. */
  70. _isMediaPermissionPromptVisible: PropTypes.bool,
  71. /**
  72. * The indicator which determines whether the reload was caused by
  73. * network failure.
  74. *
  75. * NOTE: Used by PageReloadOverlay only.
  76. *
  77. * @private
  78. * @type {boolean}
  79. */
  80. _isNetworkFailure: PropTypes.bool,
  81. /**
  82. * The reason for the error that will cause the reload.
  83. *
  84. * NOTE: Used by PageReloadOverlay only.
  85. *
  86. * @private
  87. * @type {string}
  88. */
  89. _reason: PropTypes.string,
  90. /**
  91. * The indicator which determines whether the GUM permissions prompt is
  92. * displayed or not.
  93. *
  94. * NOTE: Used by SuspendedOverlay only.
  95. *
  96. * @private
  97. * @type {string}
  98. */
  99. _suspendDetected: PropTypes.bool
  100. };
  101. /**
  102. * Initializes a new ReloadTimer instance.
  103. *
  104. * @param {Object} props - The read-only properties with which the new
  105. * instance is to be initialized.
  106. * @public
  107. */
  108. constructor(props) {
  109. super(props);
  110. this.state = {
  111. /**
  112. * The indicator which determines whether filmstrip-only mode is
  113. * enabled.
  114. *
  115. * @type {boolean}
  116. */
  117. filmstripOnly:
  118. typeof interfaceConfig === 'object'
  119. && interfaceConfig.filmStripOnly
  120. };
  121. }
  122. /**
  123. * Implements React's {@link Component#render()}.
  124. *
  125. * @inheritdoc
  126. * @returns {ReactElement|null}
  127. * @public
  128. */
  129. render() {
  130. const { filmstripOnly } = this.state;
  131. let overlayComponent, props;
  132. if (this.props._connectionEstablished && this.props._haveToReload) {
  133. overlayComponent
  134. = filmstripOnly
  135. ? PageReloadFilmstripOnlyOverlay
  136. : PageReloadOverlay;
  137. props = {
  138. isNetworkFailure: this.props._isNetworkFailure,
  139. reason: this.props._reason
  140. };
  141. } else if (this.props._suspendDetected) {
  142. overlayComponent
  143. = filmstripOnly
  144. ? SuspendedFilmstripOnlyOverlay
  145. : SuspendedOverlay;
  146. } else if (this.props._isMediaPermissionPromptVisible) {
  147. overlayComponent
  148. = filmstripOnly
  149. ? UserMediaPermissionsFilmstripOnlyOverlay
  150. : UserMediaPermissionsOverlay;
  151. props = {
  152. browser: this.props._browser
  153. };
  154. } else if (this.props._callOverlayVisible) {
  155. overlayComponent = CallOverlay;
  156. }
  157. return (
  158. overlayComponent
  159. ? React.createElement(overlayComponent, props)
  160. : null);
  161. }
  162. }
  163. /**
  164. * Maps (parts of) the redux state to the associated OverlayContainer's props.
  165. *
  166. * @param {Object} state - The redux state.
  167. * @returns {{
  168. * _browser: string,
  169. * _callOverlayVisible: boolean,
  170. * _connectionEstablished: boolean,
  171. * _haveToReload: boolean,
  172. * _isNetworkFailure: boolean,
  173. * _isMediaPermissionPromptVisible: boolean,
  174. * _reason: string,
  175. * _suspendDetected: boolean
  176. * }}
  177. * @private
  178. */
  179. function _mapStateToProps(state) {
  180. const stateFeaturesOverlay = state['features/overlay'];
  181. return {
  182. /**
  183. * The browser which is used currently.
  184. *
  185. * NOTE: Used by {@link UserMediaPermissionsOverlay} only.
  186. *
  187. * @private
  188. * @type {string}
  189. */
  190. _browser: stateFeaturesOverlay.browser,
  191. /**
  192. * The indicator which determines whether the {@link CallOverlay} is
  193. * displayed/visible.
  194. *
  195. * @private
  196. * @type {boolean}
  197. */
  198. _callOverlayVisible:
  199. Boolean(state['features/base/jwt'].callOverlayVisible),
  200. /**
  201. * The indicator which determines whether the status of the
  202. * JitsiConnection object has been "established" or not.
  203. *
  204. * NOTE: Used by {@link PageReloadOverlay} only.
  205. *
  206. * @private
  207. * @type {boolean}
  208. */
  209. _connectionEstablished: stateFeaturesOverlay.connectionEstablished,
  210. /**
  211. * The indicator which determines whether a critical error for reload
  212. * has been received.
  213. *
  214. * NOTE: Used by {@link PageReloadOverlay} only.
  215. *
  216. * @private
  217. * @type {boolean}
  218. */
  219. _haveToReload: stateFeaturesOverlay.haveToReload,
  220. /**
  221. * The indicator which determines whether the GUM permissions prompt is
  222. * displayed or not.
  223. *
  224. * NOTE: Used by {@link UserMediaPermissionsOverlay} only.
  225. *
  226. * @private
  227. * @type {boolean}
  228. */
  229. _isMediaPermissionPromptVisible:
  230. stateFeaturesOverlay.isMediaPermissionPromptVisible,
  231. /**
  232. * The indicator which determines whether the reload was caused by
  233. * network failure.
  234. *
  235. * NOTE: Used by {@link PageReloadOverlay} only.
  236. *
  237. * @private
  238. * @type {boolean}
  239. */
  240. _isNetworkFailure: stateFeaturesOverlay.isNetworkFailure,
  241. /**
  242. * The reason for the error that will cause the reload.
  243. *
  244. * NOTE: Used by {@link PageReloadOverlay} only.
  245. *
  246. * @private
  247. * @type {string}
  248. */
  249. _reason: stateFeaturesOverlay.reason,
  250. /**
  251. * The indicator which determines whether the GUM permissions prompt is
  252. * displayed or not.
  253. *
  254. * NOTE: Used by {@link SuspendedOverlay} only.
  255. *
  256. * @private
  257. * @type {string}
  258. */
  259. _suspendDetected: stateFeaturesOverlay.suspendDetected
  260. };
  261. }
  262. export default connect(_mapStateToProps)(OverlayContainer);