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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* global $, APP, AJS */
  2. import Overlay from '../overlay/Overlay';
  3. /**
  4. * An overlay dialog which is shown before the conference is reloaded. Shows
  5. * a warning message and counts down towards the reload.
  6. */
  7. class PageReloadOverlayImpl extends Overlay{
  8. /**
  9. * Creates new <tt>PageReloadOverlayImpl</tt>
  10. * @param {number} timeoutSeconds how long the overlay dialog will be
  11. * displayed, before the conference will be reloaded.
  12. */
  13. constructor(timeoutSeconds) {
  14. super();
  15. /**
  16. * Conference reload counter in seconds.
  17. * @type {number}
  18. */
  19. this.timeLeft = timeoutSeconds;
  20. /**
  21. * Conference reload timeout in seconds.
  22. * @type {number}
  23. */
  24. this.timeout = timeoutSeconds;
  25. }
  26. /**
  27. * Constructs overlay body with the warning message and count down towards
  28. * the conference reload.
  29. * @override
  30. */
  31. _buildOverlayContent() {
  32. return `
  33. <span data-i18n='dialog.serviceUnavailable'
  34. class='overlay_text_small'></span>
  35. <span data-i18n='dialog.conferenceReloadMsg'
  36. class='overlay_text_small'></span>
  37. <div>
  38. <div id='reloadProgressBar' class="aui-progress-indicator">
  39. <span class="aui-progress-indicator-value"></span>
  40. </div>
  41. <span id='reloadSecRemaining' class='overlay_text_small'>
  42. </span>
  43. </div>`;
  44. }
  45. /**
  46. * Updates the progress indicator position and the label with the time left.
  47. */
  48. updateDisplay() {
  49. const timeLeftTxt
  50. = APP.translation.translateString(
  51. "dialog.conferenceReloadTimeLeft",
  52. { seconds: this.timeLeft });
  53. $("#reloadSecRemaining").text(timeLeftTxt);
  54. const ratio = (this.timeout - this.timeLeft) / this.timeout;
  55. AJS.progressBars.update("#reloadProgressBar", ratio);
  56. }
  57. /**
  58. * Starts the reload countdown with the animation.
  59. * @override
  60. */
  61. _onShow() {
  62. // Initialize displays
  63. this.updateDisplay();
  64. var intervalId = window.setInterval(function() {
  65. if (this.timeLeft >= 1) {
  66. this.timeLeft -= 1;
  67. }
  68. this.updateDisplay();
  69. if (this.timeLeft === 0) {
  70. window.clearInterval(intervalId);
  71. APP.ConferenceUrl.reload();
  72. }
  73. }.bind(this), 1000);
  74. console.info(
  75. "The conference will be reloaded after "
  76. + this.timeLeft + " seconds.");
  77. }
  78. }
  79. /**
  80. * Holds the page reload overlay instance.
  81. *
  82. * {@type PageReloadOverlayImpl}
  83. */
  84. let overlay;
  85. export default {
  86. /**
  87. * Checks whether the page reload overlay has been displayed.
  88. * @return {boolean} <tt>true</tt> if the page reload overlay is currently
  89. * visible or <tt>false</tt> otherwise.
  90. */
  91. isVisible() {
  92. return overlay && overlay.isVisible();
  93. },
  94. /**
  95. * Shows the page reload overlay which will do the conference reload after
  96. * the given amount of time.
  97. *
  98. * @param {number} timeoutSeconds how many seconds before the conference
  99. * reload will happen.
  100. */
  101. show(timeoutSeconds) {
  102. if (!overlay) {
  103. overlay = new PageReloadOverlayImpl(timeoutSeconds);
  104. }
  105. overlay.show();
  106. }
  107. };