您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AbstractPageReloadOverlay.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* @flow */
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import { randomInt } from '../../base/util';
  5. import { _reloadNow } from '../actions';
  6. import ReloadButton from './ReloadButton';
  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: 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: 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: PropTypes.string,
  36. /**
  37. * The function to translate human-readable text.
  38. *
  39. * @public
  40. * @type {Function}
  41. */
  42. t: 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. 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. this.props.dispatch(_reloadNow());
  130. } else {
  131. this.setState(prevState => {
  132. return {
  133. timeLeft: prevState.timeLeft - 1
  134. };
  135. });
  136. }
  137. },
  138. 1000);
  139. }
  140. /**
  141. * Clears the timer interval.
  142. *
  143. * @inheritdoc
  144. * @returns {void}
  145. */
  146. componentWillUnmount() {
  147. if (this._interval) {
  148. clearInterval(this._interval);
  149. this._interval = undefined;
  150. }
  151. }
  152. /**
  153. * Renders the button for relaod the page if necessary.
  154. *
  155. * @protected
  156. * @returns {ReactElement|null}
  157. */
  158. _renderButton() {
  159. if (this.props.isNetworkFailure) {
  160. return (
  161. <ReloadButton textKey = 'dialog.rejoinNow' />
  162. );
  163. }
  164. return null;
  165. }
  166. /**
  167. * Renders the progress bar.
  168. *
  169. * @protected
  170. * @returns {ReactElement}
  171. */
  172. _renderProgressBar() {
  173. const { timeoutSeconds, timeLeft } = this.state;
  174. const timeRemaining = timeoutSeconds - timeLeft;
  175. const percentageComplete = Math.floor(
  176. (timeRemaining / timeoutSeconds) * 100);
  177. return (
  178. <div
  179. className = 'progress-indicator'
  180. id = 'reloadProgressBar'>
  181. <div
  182. className = 'progress-indicator-fill'
  183. style = {{
  184. width: `${percentageComplete}%`
  185. }} />
  186. </div>
  187. );
  188. }
  189. }