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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 film strip 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 filmStripOnlyMode = this.state.filmStripOnly;
  133. let overlayComponent, props;
  134. if (this.props._connectionEstablished && this.props._haveToReload) {
  135. overlayComponent = filmStripOnlyMode
  136. ? PageReloadFilmStripOnlyOverlay : PageReloadOverlay;
  137. props = {
  138. isNetworkFailure: this.props._isNetworkFailure,
  139. reason: this.props._reason
  140. };
  141. } else if (this.props._suspendDetected) {
  142. overlayComponent = filmStripOnlyMode
  143. ? SuspendedFilmStripOnlyOverlay : SuspendedOverlay;
  144. } else if (this.props._isMediaPermissionPromptVisible) {
  145. overlayComponent = filmStripOnlyMode
  146. ? UserMediaPermissionsFilmStripOnlyOverlay
  147. : UserMediaPermissionsOverlay;
  148. props = { browser: this.props._browser };
  149. }
  150. if (overlayComponent) {
  151. return React.createElement(overlayComponent, props);
  152. }
  153. return null;
  154. }
  155. }
  156. /**
  157. * Maps (parts of) the Redux state to the associated OverlayContainer's props.
  158. *
  159. * @param {Object} state - The Redux state.
  160. * @returns {{
  161. * _browser: string,
  162. * _connectionEstablished: bool,
  163. * _haveToReload: bool,
  164. * _isNetworkFailure: bool,
  165. * _isMediaPermissionPromptVisible: bool,
  166. * _reason: string,
  167. * _suspendDetected: bool
  168. * }}
  169. * @private
  170. */
  171. function _mapStateToProps(state) {
  172. const stateFeaturesOverlay = state['features/overlay'];
  173. return {
  174. /**
  175. * The browser which is used currently.
  176. *
  177. * NOTE: Used by UserMediaPermissionsOverlay only.
  178. *
  179. * @private
  180. * @type {string}
  181. */
  182. _browser: stateFeaturesOverlay.browser,
  183. /**
  184. * The indicator which determines whether the status of the
  185. * JitsiConnection object has been "established" or not.
  186. *
  187. * NOTE: Used by PageReloadOverlay only.
  188. *
  189. * @private
  190. * @type {boolean}
  191. */
  192. _connectionEstablished: stateFeaturesOverlay.connectionEstablished,
  193. /**
  194. * The indicator which determines whether a critical error for reload
  195. * has been received.
  196. *
  197. * NOTE: Used by PageReloadOverlay only.
  198. *
  199. * @private
  200. * @type {boolean}
  201. */
  202. _haveToReload: stateFeaturesOverlay.haveToReload,
  203. /**
  204. * The indicator which determines whether the GUM permissions prompt is
  205. * displayed or not.
  206. *
  207. * NOTE: Used by UserMediaPermissionsOverlay only.
  208. *
  209. * @private
  210. * @type {boolean}
  211. */
  212. _isMediaPermissionPromptVisible:
  213. stateFeaturesOverlay.isMediaPermissionPromptVisible,
  214. /**
  215. * The indicator which determines whether the reload was caused by
  216. * network failure.
  217. *
  218. * NOTE: Used by PageReloadOverlay only.
  219. *
  220. * @private
  221. * @type {boolean}
  222. */
  223. _isNetworkFailure: stateFeaturesOverlay.isNetworkFailure,
  224. /**
  225. * The reason for the error that will cause the reload.
  226. *
  227. * NOTE: Used by PageReloadOverlay only.
  228. *
  229. * @private
  230. * @type {string}
  231. */
  232. _reason: stateFeaturesOverlay.reason,
  233. /**
  234. * The indicator which determines whether the GUM permissions prompt is
  235. * displayed or not.
  236. *
  237. * NOTE: Used by SuspendedOverlay only.
  238. *
  239. * @private
  240. * @type {string}
  241. */
  242. _suspendDetected: stateFeaturesOverlay.suspendDetected
  243. };
  244. }
  245. export default connect(_mapStateToProps)(OverlayContainer);