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.

AbstractPageReloadOverlay.js 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { randomInt } from '../../base/util';
  4. import { _reloadNow } from '../actions';
  5. import ReloadButton from './ReloadButton';
  6. declare var AJS: Object;
  7. declare var APP: Object;
  8. const logger = require('jitsi-meet-logger').getLogger(__filename);
  9. /**
  10. * Implements abstract React Component for the page reload overlays.
  11. */
  12. export default class AbstractPageReloadOverlay extends Component {
  13. /**
  14. * AbstractPageReloadOverlay component's property types.
  15. *
  16. * @static
  17. */
  18. static propTypes = {
  19. dispatch: React.PropTypes.func,
  20. /**
  21. * The indicator which determines whether the reload was caused by
  22. * network failure.
  23. *
  24. * @public
  25. * @type {boolean}
  26. */
  27. isNetworkFailure: React.PropTypes.bool,
  28. /**
  29. * The reason for the error that will cause the reload.
  30. * NOTE: Used by PageReloadOverlay only.
  31. *
  32. * @public
  33. * @type {string}
  34. */
  35. reason: React.PropTypes.string,
  36. /**
  37. * The function to translate human-readable text.
  38. *
  39. * @public
  40. * @type {Function}
  41. */
  42. t: React.PropTypes.func
  43. };
  44. _interval: ?number
  45. state: {
  46. /**
  47. * The translation key for the title of the overlay.
  48. *
  49. * @type {string}
  50. */
  51. message: string,
  52. /**
  53. * Current value(time) of the timer.
  54. *
  55. * @type {number}
  56. */
  57. timeLeft: number,
  58. /**
  59. * How long the overlay dialog will be displayed before the
  60. * conference will be reloaded.
  61. *
  62. * @type {number}
  63. */
  64. timeoutSeconds: number,
  65. /**
  66. * The translation key for the title of the overlay.
  67. *
  68. * @type {string}
  69. */
  70. title: string
  71. }
  72. /**
  73. * Initializes a new AbstractPageReloadOverlay instance.
  74. *
  75. * @param {Object} props - The read-only properties with which the new
  76. * instance is to be initialized.
  77. * @public
  78. */
  79. constructor(props: Object) {
  80. super(props);
  81. /**
  82. * How long the overlay dialog will be displayed, before the conference
  83. * will be reloaded.
  84. *
  85. * @type {number}
  86. */
  87. const timeoutSeconds = 10 + randomInt(0, 20);
  88. let message, title;
  89. if (this.props.isNetworkFailure) {
  90. title = 'dialog.conferenceDisconnectTitle';
  91. message = 'dialog.conferenceDisconnectMsg';
  92. } else {
  93. title = 'dialog.conferenceReloadTitle';
  94. message = 'dialog.conferenceReloadMsg';
  95. }
  96. this.state = {
  97. message,
  98. timeLeft: timeoutSeconds,
  99. timeoutSeconds,
  100. title
  101. };
  102. }
  103. /**
  104. * React Component method that executes once component is mounted.
  105. *
  106. * @inheritdoc
  107. * @returns {void}
  108. */
  109. componentDidMount() {
  110. // FIXME (CallStats - issue) This event will not make it to CallStats
  111. // because the log queue is not flushed before "fabric terminated" is
  112. // sent to the backed.
  113. // FIXME: We should dispatch action for this.
  114. APP.conference.logEvent(
  115. 'page.reload',
  116. /* value */ undefined,
  117. /* label */ this.props.reason);
  118. logger.info(
  119. `The conference will be reloaded after ${
  120. this.state.timeoutSeconds} seconds.`);
  121. AJS.progressBars.update('#reloadProgressBar', 0);
  122. this._interval
  123. = setInterval(
  124. () => {
  125. if (this.state.timeLeft === 0) {
  126. if (this._interval) {
  127. clearInterval(this._interval);
  128. this._interval = undefined;
  129. }
  130. this.props.dispatch(_reloadNow());
  131. } else {
  132. this.setState(prevState => {
  133. return {
  134. timeLeft: prevState.timeLeft - 1
  135. };
  136. });
  137. }
  138. },
  139. 1000);
  140. }
  141. /**
  142. * React Component method that executes once component is updated.
  143. *
  144. * @inheritdoc
  145. * @returns {void}
  146. */
  147. componentDidUpdate() {
  148. const { timeLeft, timeoutSeconds } = this.state;
  149. AJS.progressBars.update(
  150. '#reloadProgressBar',
  151. (timeoutSeconds - timeLeft) / timeoutSeconds);
  152. }
  153. /**
  154. * Clears the timer interval.
  155. *
  156. * @inheritdoc
  157. * @returns {void}
  158. */
  159. componentWillUnmount() {
  160. if (this._interval) {
  161. clearInterval(this._interval);
  162. this._interval = undefined;
  163. }
  164. }
  165. /**
  166. * Renders the button for relaod the page if necessary.
  167. *
  168. * @protected
  169. * @returns {ReactElement|null}
  170. */
  171. _renderButton() {
  172. if (this.props.isNetworkFailure) {
  173. return (
  174. <ReloadButton textKey = 'dialog.rejoinNow' />
  175. );
  176. }
  177. return null;
  178. }
  179. /**
  180. * Renders the progress bar.
  181. *
  182. * @protected
  183. * @returns {ReactElement}
  184. */
  185. _renderProgressBar() {
  186. return (
  187. <div
  188. className = 'aui-progress-indicator'
  189. id = 'reloadProgressBar'>
  190. <span className = 'aui-progress-indicator-value' />
  191. </div>
  192. );
  193. }
  194. }