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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. * The indicator which determines whether filmstrip-only mode is
  104. * enabled.
  105. *
  106. * @type {boolean}
  107. */
  108. filmstripOnly:
  109. typeof interfaceConfig === 'object'
  110. && interfaceConfig.filmStripOnly
  111. };
  112. }
  113. /**
  114. * React Component method that executes once component is updated.
  115. *
  116. * @inheritdoc
  117. * @returns {void}
  118. * @protected
  119. */
  120. componentDidUpdate() {
  121. if (typeof APP === 'object') {
  122. APP.UI.overlayVisible
  123. = (this.props._connectionEstablished
  124. && this.props._haveToReload)
  125. || this.props._suspendDetected
  126. || this.props._isMediaPermissionPromptVisible;
  127. }
  128. }
  129. /**
  130. * Implements React's {@link Component#render()}.
  131. *
  132. * @inheritdoc
  133. * @returns {ReactElement|null}
  134. * @public
  135. */
  136. render() {
  137. const { filmstripOnly } = this.state;
  138. let overlayComponent, props;
  139. if (this.props._connectionEstablished && this.props._haveToReload) {
  140. overlayComponent
  141. = filmstripOnly
  142. ? PageReloadFilmstripOnlyOverlay
  143. : PageReloadOverlay;
  144. props = {
  145. isNetworkFailure: this.props._isNetworkFailure,
  146. reason: this.props._reason
  147. };
  148. } else if (this.props._suspendDetected) {
  149. overlayComponent
  150. = filmstripOnly
  151. ? SuspendedFilmstripOnlyOverlay
  152. : SuspendedOverlay;
  153. } else if (this.props._isMediaPermissionPromptVisible) {
  154. overlayComponent
  155. = filmstripOnly
  156. ? UserMediaPermissionsFilmstripOnlyOverlay
  157. : UserMediaPermissionsOverlay;
  158. props = {
  159. browser: this.props._browser
  160. };
  161. }
  162. return (
  163. overlayComponent
  164. ? React.createElement(overlayComponent, props)
  165. : null);
  166. }
  167. }
  168. /**
  169. * Maps (parts of) the Redux state to the associated OverlayContainer's props.
  170. *
  171. * @param {Object} state - The Redux state.
  172. * @returns {{
  173. * _browser: string,
  174. * _connectionEstablished: bool,
  175. * _haveToReload: bool,
  176. * _isNetworkFailure: bool,
  177. * _isMediaPermissionPromptVisible: bool,
  178. * _reason: string,
  179. * _suspendDetected: bool
  180. * }}
  181. * @private
  182. */
  183. function _mapStateToProps(state) {
  184. const stateFeaturesOverlay = state['features/overlay'];
  185. return {
  186. /**
  187. * The browser which is used currently.
  188. *
  189. * NOTE: Used by UserMediaPermissionsOverlay only.
  190. *
  191. * @private
  192. * @type {string}
  193. */
  194. _browser: stateFeaturesOverlay.browser,
  195. /**
  196. * The indicator which determines whether the status of the
  197. * JitsiConnection object has been "established" or not.
  198. *
  199. * NOTE: Used by PageReloadOverlay only.
  200. *
  201. * @private
  202. * @type {boolean}
  203. */
  204. _connectionEstablished: stateFeaturesOverlay.connectionEstablished,
  205. /**
  206. * The indicator which determines whether a critical error for reload
  207. * has been received.
  208. *
  209. * NOTE: Used by PageReloadOverlay only.
  210. *
  211. * @private
  212. * @type {boolean}
  213. */
  214. _haveToReload: stateFeaturesOverlay.haveToReload,
  215. /**
  216. * The indicator which determines whether the GUM permissions prompt is
  217. * displayed or not.
  218. *
  219. * NOTE: Used by UserMediaPermissionsOverlay only.
  220. *
  221. * @private
  222. * @type {boolean}
  223. */
  224. _isMediaPermissionPromptVisible:
  225. stateFeaturesOverlay.isMediaPermissionPromptVisible,
  226. /**
  227. * The indicator which determines whether the reload was caused by
  228. * network failure.
  229. *
  230. * NOTE: Used by PageReloadOverlay only.
  231. *
  232. * @private
  233. * @type {boolean}
  234. */
  235. _isNetworkFailure: stateFeaturesOverlay.isNetworkFailure,
  236. /**
  237. * The reason for the error that will cause the reload.
  238. *
  239. * NOTE: Used by PageReloadOverlay only.
  240. *
  241. * @private
  242. * @type {string}
  243. */
  244. _reason: stateFeaturesOverlay.reason,
  245. /**
  246. * The indicator which determines whether the GUM permissions prompt is
  247. * displayed or not.
  248. *
  249. * NOTE: Used by SuspendedOverlay only.
  250. *
  251. * @private
  252. * @type {string}
  253. */
  254. _suspendDetected: stateFeaturesOverlay.suspendDetected
  255. };
  256. }
  257. export default connect(_mapStateToProps)(OverlayContainer);