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

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