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.

PageReloadOverlay.js 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /* global APP, AJS */
  2. import React, { Component } from 'react';
  3. import { randomInt } from '../../base/util/randomUtil';
  4. import AbstractOverlay from './AbstractOverlay';
  5. const logger = require('jitsi-meet-logger').getLogger(__filename);
  6. /**
  7. * Implements a React Component for the reload timer. Starts counter from
  8. * props.start, adds props.step to the current value on every props.interval
  9. * seconds until the current value reaches props.end. Also displays progress
  10. * bar.
  11. */
  12. class ReloadTimer extends Component {
  13. /**
  14. * ReloadTimer component's property types.
  15. *
  16. * @static
  17. */
  18. static propTypes = {
  19. /**
  20. * The end of the timer. When this.state.current reaches this
  21. * value the timer will stop and call onFinish function.
  22. * @public
  23. * @type {number}
  24. */
  25. end: React.PropTypes.number,
  26. /**
  27. * The interval in sec for adding this.state.step to this.state.current
  28. * @public
  29. * @type {number}
  30. */
  31. interval: React.PropTypes.number,
  32. /**
  33. * The function that will be executed when timer finish (when
  34. * this.state.current === this.props.end)
  35. */
  36. onFinish: React.PropTypes.func,
  37. /**
  38. * The start of the timer. The initial value for this.state.current.
  39. * @public
  40. * @type {number}
  41. */
  42. start: React.PropTypes.number,
  43. /**
  44. * The value which will be added to this.state.current on every step.
  45. * @public
  46. * @type {number}
  47. */
  48. step: React.PropTypes.number
  49. }
  50. /**
  51. * Initializes a new ReloadTimer instance.
  52. *
  53. * @param {Object} props - The read-only properties with which the new
  54. * instance is to be initialized.
  55. * @public
  56. */
  57. constructor(props) {
  58. super(props);
  59. this.state = {
  60. current: this.props.start,
  61. time: Math.abs(this.props.end - this.props.start)
  62. };
  63. }
  64. /**
  65. * React Component method that executes once component is mounted.
  66. *
  67. * @inheritdoc
  68. * @returns {void}
  69. * @protected
  70. */
  71. componentDidMount() {
  72. AJS.progressBars.update('#reloadProgressBar', 0);
  73. const intervalId = setInterval(() => {
  74. if (this.state.current === this.props.end) {
  75. clearInterval(intervalId);
  76. this.props.onFinish();
  77. return;
  78. }
  79. this.setState((prevState, props) => {
  80. return { current: prevState.current + props.step };
  81. });
  82. }, Math.abs(this.props.interval) * 1000);
  83. }
  84. /**
  85. * React Component method that executes once component is updated.
  86. *
  87. * @inheritdoc
  88. * @returns {void}
  89. * @protected
  90. */
  91. componentDidUpdate() {
  92. AJS.progressBars.update('#reloadProgressBar',
  93. Math.abs(this.state.current - this.props.start) / this.state.time);
  94. }
  95. /**
  96. * Implements React's {@link Component#render()}.
  97. *
  98. * @inheritdoc
  99. * @returns {ReactElement|null}
  100. * @public
  101. */
  102. render() {
  103. return (
  104. <div>
  105. <div
  106. className = 'aui-progress-indicator'
  107. id = 'reloadProgressBar'>
  108. <span className = 'aui-progress-indicator-value' />
  109. </div>
  110. <span
  111. className = 'reload_overlay_text'
  112. id = 'reloadSeconds'>
  113. { this.state.current }
  114. <span data-i18n = 'dialog.conferenceReloadTimeLeft' />
  115. </span>
  116. </div>
  117. );
  118. }
  119. }
  120. /**
  121. * Implements a React Component for page reload overlay. Shown before
  122. * the conference is reloaded. Shows a warning message and counts down towards
  123. * the reload.
  124. */
  125. export default class PageReloadOverlay extends AbstractOverlay {
  126. /**
  127. * PageReloadOverlay component's property types.
  128. *
  129. * @static
  130. */
  131. static propTypes = {
  132. /**
  133. * The indicator which determines whether the reload was caused by
  134. * network failure.
  135. * @public
  136. * @type {boolean}
  137. */
  138. isNetworkFailure: React.PropTypes.bool,
  139. /**
  140. * The reason for the error that will cause the reload.
  141. * NOTE: Used by PageReloadOverlay only.
  142. * @public
  143. * @type {string}
  144. */
  145. reason: React.PropTypes.string
  146. }
  147. /**
  148. * Initializes a new PageReloadOverlay instance.
  149. *
  150. * @param {Object} props - The read-only properties with which the new
  151. * instance is to be initialized.
  152. * @public
  153. */
  154. constructor(props) {
  155. super(props);
  156. /**
  157. * How long the overlay dialog will be
  158. * displayed, before the conference will be reloaded.
  159. * @type {number}
  160. */
  161. const timeoutSeconds = 10 + randomInt(0, 20);
  162. let isLightOverlay, message, title;
  163. if (this.props.isNetworkFailure) {
  164. title = 'dialog.conferenceDisconnectTitle';
  165. message = 'dialog.conferenceDisconnectMsg';
  166. isLightOverlay = true;
  167. } else {
  168. title = 'dialog.conferenceReloadTitle';
  169. message = 'dialog.conferenceReloadMsg';
  170. isLightOverlay = false;
  171. }
  172. this.state = {
  173. ...this.state,
  174. /**
  175. * Indicates the css style of the overlay. if true - lighter and
  176. * darker otherwise.
  177. * @type {boolean}
  178. */
  179. isLightOverlay,
  180. /**
  181. * The translation key for the title of the overlay
  182. * @type {string}
  183. */
  184. message,
  185. /**
  186. * How long the overlay dialog will be
  187. * displayed, before the conference will be reloaded.
  188. * @type {number}
  189. */
  190. timeoutSeconds,
  191. /**
  192. * The translation key for the title of the overlay
  193. * @type {string}
  194. */
  195. title
  196. };
  197. }
  198. /**
  199. * Renders the button for relaod the page if necessary.
  200. *
  201. * @returns {ReactElement|null}
  202. * @private
  203. */
  204. _renderButton() {
  205. if (this.props.isNetworkFailure) {
  206. const cName = 'button-control button-control_primary '
  207. + 'button-control_center';
  208. /* eslint-disable react/jsx-handler-names */
  209. return (
  210. <button
  211. className = { cName }
  212. data-i18n = 'dialog.reconnectNow'
  213. id = 'reconnectNow'
  214. onClick = { this._reconnectNow } />
  215. );
  216. }
  217. return null;
  218. }
  219. /**
  220. * Constructs overlay body with the warning message and count down towards
  221. * the conference reload.
  222. *
  223. * @returns {ReactElement|null}
  224. * @override
  225. * @protected
  226. */
  227. _renderOverlayContent() {
  228. /* eslint-disable react/jsx-handler-names */
  229. return (
  230. <div className = 'inlay'>
  231. <span
  232. className = 'reload_overlay_title'
  233. data-i18n = { this.state.title } />
  234. <span
  235. className = 'reload_overlay_text'
  236. data-i18n = { this.state.message } />
  237. <ReloadTimer
  238. end = { 0 }
  239. interval = { 1 }
  240. onFinish = { this._reconnectNow }
  241. start = { this.state.timeoutSeconds }
  242. step = { -1 } />
  243. { this._renderButton() }
  244. </div>
  245. );
  246. }
  247. /**
  248. * This method is executed when comonent is mounted.
  249. *
  250. * @inheritdoc
  251. * @returns {void}
  252. */
  253. componentDidMount() {
  254. super.componentDidMount();
  255. // FIXME (CallStats - issue) this event will not make it to
  256. // the CallStats, because the log queue is not flushed, before
  257. // "fabric terminated" is sent to the backed
  258. // FIXME: We should dispatch action for this
  259. APP.conference.logEvent('page.reload', undefined /* value */,
  260. this.props.reason /* label */);
  261. logger.info(`The conference will be reloaded after
  262. ${this.state.timeoutSeconds} seconds.`);
  263. }
  264. }