Source
/*
** 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/>.
**/
/**
* Amount of seconds for keep-alive interval.
*/
ZBX_BrowserTab.keep_alive_interval = 30;
/**
* This object is representing a browser tab. Implements singleton pattern. It ensures there are only non-crashed tabs
* in store.
*
* @param {ZBX_LocalStorage} store A localStorage wrapper.
*/
function ZBX_BrowserTab(store) {
if (ZBX_BrowserTab.instance) {
return ZBX_BrowserTab.instance;
}
if (!(store instanceof ZBX_LocalStorage)) {
throw 'Unmatched signature!';
}
ZBX_BrowserTab.instance = this;
this.uid = (Math.random() % 9e6).toString(36).substr(2);
this.store = store;
var ctx_lastseen = this.store.readKey('tabs.lastseen', {});
ctx_lastseen[this.uid] = Math.floor(+new Date / 1000);
this.lastseen = ctx_lastseen;
this.on_focus_cbs = [];
this.on_blur_cbs = [];
this.on_unload_cbs = [];
this.on_crashed_cbs = [];
this.bindEventHandlers();
this.pushLastseen();
}
/**
* @param {object} lastseen
*/
ZBX_BrowserTab.prototype.handlePushedLastseen = function(lastseen) {
this.lastseen = lastseen;
};
/**
* Checks and updates current lastseen object.