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
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/**
* 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;