Source
xxxxxxxxxx
* Will play in loop for seconds given, since this call. If "0" given - will just not play. If "-1" is given - file will
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/**
* Timeout controlled player.
*
* It plays, meanwhile decrementing timeout. Pausing and playing is done by control of 'volume' and 'muted' properties.
* It holds infinite loop, so it allows us easily adjust timeout during playback.
*/
function ZBX_NotificationsAudio() {
try {
this.audio = new Audio();
this.audio.volume = 0;
this.audio.muted = true;
this.audio.autoplay = true;
this.audio.loop = true;
this.audio.onloadeddata = this.handleOnloadeddata.bind(this);
this.audio.load();
}
catch(e) {
console.warn('Cannot support notification audio for this device.');
}
this.wave = '';
this.ms_timeout = 0;
this.is_playing = false;
this.message_timeout = 0;
this.callback = null;
this.resetPromise();
this.listen();
}
/**
* Starts main loop.
*
* @return int Interval ID.
*/
ZBX_NotificationsAudio.prototype.listen = function() {
var ms_step = 10;
if (!this.audio) {
return;
}
function resolveAudioState() {
if (this.play_once_on_ready) {
return this.once();