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

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