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.3KB

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