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

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