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

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