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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* global $ */
  2. /**
  3. * Shows ring overlay
  4. */
  5. class RingOverlay {
  6. /**
  7. * @param callee instance of User class from TokenData.js
  8. */
  9. constructor(callee) {
  10. this.callee = callee;
  11. this._buildHtml();
  12. this.audio = $("#ring_overlay_ringing");
  13. this.audio[0].play();
  14. this._setAudioTimeout();
  15. }
  16. /**
  17. * Builds and appends the ring overlay to the html document
  18. */
  19. _buildHtml() {
  20. $("body").append("<div class='overlay_container' >" +
  21. "<div class='overlay' /><div class='overlay_content'>" +
  22. "<img class='overlay_avatar' src='" +
  23. this.callee.getAvatarUrl() + "' />" +
  24. "<span data-i18n='calling' data-i18n-options='" +
  25. JSON.stringify({name: this.callee.getName()}) +
  26. "' class='overlay_text'>Calling " +
  27. this.callee.getName() + "...</span></div>" +
  28. "<audio id='ring_overlay_ringing' src='/sounds/ring.ogg' /></div>");
  29. }
  30. /**
  31. * Sets the interval that is going to play the ringing sound.
  32. */
  33. _setAudioTimeout() {
  34. this.interval = setInterval( () => {
  35. this.audio[0].play();
  36. }, 5000);
  37. }
  38. /**
  39. * Destroys and clears all the objects (html elements and audio interval)
  40. * related to the ring overlay.
  41. */
  42. destroy() {
  43. if(this.interval)
  44. clearInterval(this.interval);
  45. $(".overlay_container").remove();
  46. }
  47. }
  48. /**
  49. * Store the current ring overlay instance.
  50. * Note: We want to have only 1 instance at a time.
  51. */
  52. let overlay = null;
  53. export default {
  54. /**
  55. * Shows the ring overlay for the passed callee.
  56. * @param callee {class User} the callee. Instance of User class from
  57. * TokenData.js
  58. */
  59. show(callee) {
  60. if(overlay) {
  61. this.hide();
  62. }
  63. overlay = new RingOverlay(callee);
  64. },
  65. /**
  66. * Hides the ring overlay. Destroys all the elements related to the ring
  67. * overlay.
  68. */
  69. hide() {
  70. if(!overlay)
  71. return false;
  72. overlay.destroy();
  73. overlay = null;
  74. return true;
  75. }
  76. };