let audio = { audioLoop: null, init: function() { if (ua.audioInstance) return; ua.audioInstance = document.createElement('audio'); }, addTrack: function(track) { if (ua.audioInstance) this.stop(); this.init(); ua.audioInstance.src = this.getTrackPath(track); }, addStream: function(stream) { if (ua.audioInstance) this.stop(); this.init(); ua.audioInstance.srcObject = stream; }, play: function(loop = false) { if (!ua.audioInstance) return; ua.audioInstance.volume = Softphone.getVolume(); ua.audioInstance.play(); if (loop) { this.audioLoop = setInterval(function() { ua.audioInstance.play(); }, 2000); } }, stop: function() { if (!ua.audioInstance) return; if (this.audioLoop) clearInterval(this.audioLoop); ua.audioInstance.pause(); ua.audioInstance = null; }, isPlaying: function() { if (!ua.audioInstance.paused) return true; }, getTrackPath: function(track) { return `/static/audio/${track}.wav`; } }