/* global $, APP */ import UIEvents from "../../../service/UI/UIEvents"; /** * Store the current ring overlay instance. * Note: We want to have only 1 instance at a time. */ let overlay = null; /** * Handler for UIEvents.LARGE_VIDEO_AVATAR_VISIBLE event. * @param {boolean} shown indicates whether the avatar on the large video is * currently displayed or not. */ function onAvatarVisible(shown) { overlay._changeBackground(shown); } /** * Shows ring overlay */ class RingOverlay { /** * * @param callee The callee (Object) as defined by the JWT support. * @param {boolean} disableRinging if true the ringing sound wont be played. */ constructor(callee, disableRinging) { this._containerId = 'ringOverlay'; this._audioContainerId = 'ringOverlayRinging'; this.isRinging = true; this.callee = callee; this.disableRinging = disableRinging; this.render(); if (!disableRinging) this._initAudio(); this._timeout = setTimeout( () => { this.destroy(); this.render(); }, 30000); } /** * Initializes the audio element and setups the interval for playing it. */ _initAudio() { this.audio = document.getElementById(this._audioContainerId); this.audio.play(); this.interval = setInterval(() => this.audio.play(), 5000); } /** * Chagnes the background of the ring overlay. * @param {boolean} solid - if true the new background will be the solid * one, otherwise the background will be default one. * NOTE: The method just toggles solidBG css class. */ _changeBackground(solid) { const container = $("#" + this._containerId); if (solid) { container.addClass("solidBG"); } else { container.removeClass("solidBG"); } } /** * Builds and appends the ring overlay to the html document */ _getHtmlStr(callee) { let callingLabel = this.isRinging ? "
Calling...
" : ""; let callerStateLabel = this.isRinging ? "" : " isn't available"; let audioHTML = this.disableRinging ? "" : ""; return `${callee.name}${callerStateLabel}