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

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