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

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