Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AbstractPageReloadOverlay.js 5.5KB

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