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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import React, { Component } from 'react';
  2. import { translate } from '../../base/i18n';
  3. import { randomInt } from '../../base/util';
  4. import OverlayFrame from './OverlayFrame';
  5. import { reconnectNow } from '../functions';
  6. import ReloadTimer from './ReloadTimer';
  7. declare var APP: Object;
  8. const logger = require('jitsi-meet-logger').getLogger(__filename);
  9. /**
  10. * Implements a React Component for page reload overlay. Shown before the
  11. * conference is reloaded. Shows a warning message and counts down towards the
  12. * reload.
  13. */
  14. class PageReloadOverlay extends Component {
  15. /**
  16. * PageReloadOverlay component's property types.
  17. *
  18. * @static
  19. */
  20. static propTypes = {
  21. /**
  22. * The indicator which determines whether the reload was caused by
  23. * network failure.
  24. * @public
  25. * @type {boolean}
  26. */
  27. isNetworkFailure: React.PropTypes.bool,
  28. /**
  29. * The reason for the error that will cause the reload.
  30. * @public
  31. * @type {string}
  32. */
  33. reason: React.PropTypes.string,
  34. /**
  35. * The function to translate human-readable text.
  36. *
  37. * @public
  38. * @type {Function}
  39. */
  40. t: React.PropTypes.func
  41. }
  42. /**
  43. * Initializes a new PageReloadOverlay instance.
  44. *
  45. * @param {Object} props - The read-only properties with which the new
  46. * instance is to be initialized.
  47. * @public
  48. */
  49. constructor(props) {
  50. super(props);
  51. /**
  52. * How long the overlay dialog will be displayed, before the conference
  53. * will be reloaded.
  54. * @type {number}
  55. */
  56. const timeoutSeconds = 10 + randomInt(0, 20);
  57. let isLightOverlay, message, title;
  58. if (this.props.isNetworkFailure) {
  59. title = 'dialog.conferenceDisconnectTitle';
  60. message = 'dialog.conferenceDisconnectMsg';
  61. isLightOverlay = true;
  62. } else {
  63. title = 'dialog.conferenceReloadTitle';
  64. message = 'dialog.conferenceReloadMsg';
  65. isLightOverlay = false;
  66. }
  67. this.state = {
  68. /**
  69. * Indicates the css style of the overlay. If true, then lighter;
  70. * darker, otherwise.
  71. *
  72. * @type {boolean}
  73. */
  74. isLightOverlay,
  75. /**
  76. * The translation key for the title of the overlay.
  77. *
  78. * @type {string}
  79. */
  80. message,
  81. /**
  82. * How long the overlay dialog will be displayed before the
  83. * conference will be reloaded.
  84. *
  85. * @type {number}
  86. */
  87. timeoutSeconds,
  88. /**
  89. * The translation key for the title of the overlay.
  90. *
  91. * @type {string}
  92. */
  93. title
  94. };
  95. }
  96. /**
  97. * This method is executed when comonent is mounted.
  98. *
  99. * @inheritdoc
  100. * @returns {void}
  101. */
  102. componentDidMount() {
  103. // FIXME (CallStats - issue) This event will not make it to CallStats
  104. // because the log queue is not flushed before "fabric terminated" is
  105. // sent to the backed.
  106. // FIXME: We should dispatch action for this.
  107. APP.conference.logEvent(
  108. 'page.reload',
  109. /* value */ undefined,
  110. /* label */ this.props.reason);
  111. logger.info(
  112. 'The conference will be reloaded after '
  113. + `${this.state.timeoutSeconds} seconds.`);
  114. }
  115. /**
  116. * Renders the button for relaod the page if necessary.
  117. *
  118. * @returns {ReactElement|null}
  119. * @private
  120. */
  121. _renderButton() {
  122. if (this.props.isNetworkFailure) {
  123. const className
  124. = 'button-control button-control_primary button-control_center';
  125. const { t } = this.props;
  126. /* eslint-disable react/jsx-handler-names */
  127. return (
  128. <button
  129. className = { className }
  130. id = 'reconnectNow'
  131. onClick = { reconnectNow }>
  132. { t('dialog.reconnectNow') }
  133. </button>
  134. );
  135. /* eslint-enable react/jsx-handler-names */
  136. }
  137. return null;
  138. }
  139. /**
  140. * Implements React's {@link Component#render()}.
  141. *
  142. * @inheritdoc
  143. * @returns {ReactElement|null}
  144. */
  145. render() {
  146. const { t } = this.props;
  147. /* eslint-disable react/jsx-handler-names */
  148. return (
  149. <OverlayFrame isLightOverlay = { this.state.isLightOverlay }>
  150. <div className = 'inlay'>
  151. <span
  152. className = 'reload_overlay_title'>
  153. { t(this.state.title) }
  154. </span>
  155. <span
  156. className = 'reload_overlay_text'>
  157. { t(this.state.message) }
  158. </span>
  159. <ReloadTimer
  160. end = { 0 }
  161. interval = { 1 }
  162. onFinish = { reconnectNow }
  163. start = { this.state.timeoutSeconds }
  164. step = { -1 } />
  165. { this._renderButton() }
  166. </div>
  167. </OverlayFrame>
  168. );
  169. /* eslint-enable react/jsx-handler-names */
  170. }
  171. }
  172. export default translate(PageReloadOverlay);