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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* global $, APP, AJS */
  2. const logger = require("jitsi-meet-logger").getLogger(__filename);
  3. import Overlay from '../overlay/Overlay';
  4. /**
  5. * An overlay dialog which is shown before the conference is reloaded. Shows
  6. * a warning message and counts down towards the reload.
  7. */
  8. class PageReloadOverlayImpl extends Overlay{
  9. /**
  10. * Creates new <tt>PageReloadOverlayImpl</tt>
  11. * @param {number} timeoutSeconds how long the overlay dialog will be
  12. * displayed, before the conference will be reloaded.
  13. * @param {boolean} isDisconnect indicates if this reload screen is created
  14. * to indicate a disconnect
  15. * @param {boolean} isNetworkFailure <tt>true</tt> indicates that it's
  16. * caused by network related failure or <tt>false</tt> when it's
  17. * the infrastructure.
  18. */
  19. constructor(timeoutSeconds, isNetworkFailure) {
  20. super();
  21. /**
  22. * Conference reload counter in seconds.
  23. * @type {number}
  24. */
  25. this.timeLeft = timeoutSeconds;
  26. /**
  27. * Conference reload timeout in seconds.
  28. * @type {number}
  29. */
  30. this.timeout = timeoutSeconds;
  31. /**
  32. * Indicates that a network related failure is the reason for the
  33. * reload.
  34. * @type {boolean}
  35. */
  36. this.isNetworkFailure = isNetworkFailure;
  37. }
  38. /**
  39. * Constructs overlay body with the warning message and count down towards
  40. * the conference reload.
  41. * @override
  42. */
  43. _buildOverlayContent() {
  44. let title = (this.isNetworkFailure)
  45. ? "dialog.conferenceDisconnectTitle"
  46. : "dialog.conferenceReloadTitle";
  47. let message = (this.isNetworkFailure)
  48. ? "dialog.conferenceDisconnectMsg"
  49. : "dialog.conferenceReloadMsg";
  50. let button = (this.isNetworkFailure)
  51. ? `<button id="reconnectNow" data-i18n="dialog.reconnectNow"
  52. class="button-control button-control_primary
  53. button-control_center"></button>`
  54. : "";
  55. $(document).on('click', '#reconnectNow', () => {
  56. APP.ConferenceUrl.reload();
  57. });
  58. return `<div class="inlay">
  59. <span data-i18n=${title}
  60. class='reload_overlay_title'></span>
  61. <span data-i18n=${message}
  62. class='reload_overlay_msg'></span>
  63. <div>
  64. <div id='reloadProgressBar'
  65. class="aui-progress-indicator">
  66. <span class="aui-progress-indicator-value"></span>
  67. </div>
  68. <span id='reloadSecRemaining'
  69. data-i18n="dialog.conferenceReloadTimeLeft"
  70. class='reload_overlay_msg'>
  71. </span>
  72. </div>
  73. ${button}
  74. </div>`;
  75. }
  76. /**
  77. * Updates the progress indicator position and the label with the time left.
  78. */
  79. updateDisplay() {
  80. APP.translation.translateElement(
  81. $("#reloadSecRemaining"), { seconds: this.timeLeft });
  82. const ratio = (this.timeout - this.timeLeft) / this.timeout;
  83. AJS.progressBars.update("#reloadProgressBar", ratio);
  84. }
  85. /**
  86. * Starts the reload countdown with the animation.
  87. * @override
  88. */
  89. _onShow() {
  90. // Initialize displays
  91. this.updateDisplay();
  92. var intervalId = window.setInterval(function() {
  93. if (this.timeLeft >= 1) {
  94. this.timeLeft -= 1;
  95. }
  96. this.updateDisplay();
  97. if (this.timeLeft === 0) {
  98. window.clearInterval(intervalId);
  99. APP.ConferenceUrl.reload();
  100. }
  101. }.bind(this), 1000);
  102. logger.info(
  103. "The conference will be reloaded after "
  104. + this.timeLeft + " seconds.");
  105. }
  106. }
  107. /**
  108. * Holds the page reload overlay instance.
  109. *
  110. * {@type PageReloadOverlayImpl}
  111. */
  112. let overlay;
  113. export default {
  114. /**
  115. * Checks whether the page reload overlay has been displayed.
  116. * @return {boolean} <tt>true</tt> if the page reload overlay is currently
  117. * visible or <tt>false</tt> otherwise.
  118. */
  119. isVisible() {
  120. return overlay && overlay.isVisible();
  121. },
  122. /**
  123. * Shows the page reload overlay which will do the conference reload after
  124. * the given amount of time.
  125. *
  126. * @param {number} timeoutSeconds how many seconds before the conference
  127. * reload will happen.
  128. * @param {boolean} isNetworkFailure <tt>true</tt> indicates that it's
  129. * caused by network related failure or <tt>false</tt> when it's
  130. * the infrastructure.
  131. * @param {string} reason a label string identifying the reason for the page
  132. * reload which will be included in details of the log event
  133. */
  134. show(timeoutSeconds, isNetworkFailure, reason) {
  135. if (!overlay) {
  136. overlay
  137. = new PageReloadOverlayImpl(timeoutSeconds, isNetworkFailure);
  138. }
  139. // Log the page reload event
  140. if (!this.isVisible()) {
  141. // FIXME (CallStats - issue) this event will not make it to
  142. // the CallStats, because the log queue is not flushed, before
  143. // "fabric terminated" is sent to the backed
  144. APP.conference.logEvent(
  145. 'page.reload', undefined /* value */, reason /* label */);
  146. }
  147. // If it's a network failure we enable the light overlay.
  148. overlay.show(isNetworkFailure);
  149. }
  150. };