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

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