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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. */
  14. constructor(timeoutSeconds) {
  15. super();
  16. /**
  17. * Conference reload counter in seconds.
  18. * @type {number}
  19. */
  20. this.timeLeft = timeoutSeconds;
  21. /**
  22. * Conference reload timeout in seconds.
  23. * @type {number}
  24. */
  25. this.timeout = timeoutSeconds;
  26. }
  27. /**
  28. * Constructs overlay body with the warning message and count down towards
  29. * the conference reload.
  30. * @override
  31. */
  32. _buildOverlayContent() {
  33. return `<div class="inlay">
  34. <span data-i18n='dialog.conferenceReloadTitle'
  35. class='reload_overlay_title'></span>
  36. <span data-i18n='dialog.conferenceReloadMsg'
  37. class='reload_overlay_msg'></span>
  38. <div>
  39. <div id='reloadProgressBar'
  40. class="aui-progress-indicator">
  41. <span class="aui-progress-indicator-value"></span>
  42. </div>
  43. <span id='reloadSecRemaining'
  44. data-i18n="dialog.conferenceReloadTimeLeft"
  45. class='reload_overlay_msg'>
  46. </span>
  47. </div>
  48. </div>`;
  49. }
  50. /**
  51. * Updates the progress indicator position and the label with the time left.
  52. */
  53. updateDisplay() {
  54. APP.translation.translateElement(
  55. $("#reloadSecRemaining"), { seconds: this.timeLeft });
  56. const ratio = (this.timeout - this.timeLeft) / this.timeout;
  57. AJS.progressBars.update("#reloadProgressBar", ratio);
  58. }
  59. /**
  60. * Starts the reload countdown with the animation.
  61. * @override
  62. */
  63. _onShow() {
  64. // Initialize displays
  65. this.updateDisplay();
  66. var intervalId = window.setInterval(function() {
  67. if (this.timeLeft >= 1) {
  68. this.timeLeft -= 1;
  69. }
  70. this.updateDisplay();
  71. if (this.timeLeft === 0) {
  72. window.clearInterval(intervalId);
  73. APP.ConferenceUrl.reload();
  74. }
  75. }.bind(this), 1000);
  76. logger.info(
  77. "The conference will be reloaded after "
  78. + this.timeLeft + " seconds.");
  79. }
  80. }
  81. /**
  82. * Holds the page reload overlay instance.
  83. *
  84. * {@type PageReloadOverlayImpl}
  85. */
  86. let overlay;
  87. export default {
  88. /**
  89. * Checks whether the page reload overlay has been displayed.
  90. * @return {boolean} <tt>true</tt> if the page reload overlay is currently
  91. * visible or <tt>false</tt> otherwise.
  92. */
  93. isVisible() {
  94. return overlay && overlay.isVisible();
  95. },
  96. /**
  97. * Shows the page reload overlay which will do the conference reload after
  98. * the given amount of time.
  99. *
  100. * @param {number} timeoutSeconds how many seconds before the conference
  101. * reload will happen.
  102. */
  103. show(timeoutSeconds) {
  104. if (!overlay) {
  105. overlay = new PageReloadOverlayImpl(timeoutSeconds);
  106. }
  107. // Log the page reload event
  108. if (!this.isVisible()) {
  109. // FIXME (CallStats - issue) this event will not make it to
  110. // the CallStats, because the log queue is not flushed, before
  111. // "fabric terminated" is sent to the backed
  112. APP.conference.logEvent('page.reload');
  113. }
  114. overlay.show();
  115. }
  116. };