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

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