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

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