Source
* Synchronization tick. It checks if any of keys have been written outside the window object where this instance runs.
/*
** 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/>.
**/
ZBX_LocalStorage.defines = {
PREFIX_SEPARATOR: ':',
KEEP_ALIVE_INTERVAL: 30,
SYNC_INTERVAL_MS: 500,
KEY_SESSIONS: 'sessions',
KEY_LAST_WRITE: 'key_last_write'
};
/**
* Local storage wrapper. Implements singleton.
*
* @param {string} version Mandatory parameter.
* @param {string} prefix Used to distinct keys between sessions within same domain.
*/
function ZBX_LocalStorage(version, prefix) {
if (!version || !prefix) {
throw 'Local storage instantiation must be versioned, and prefixed.';
}
if (ZBX_LocalStorage.instance) {
return ZBX_LocalStorage.instance;
}
ZBX_LocalStorage.sessionid = prefix;
ZBX_LocalStorage.prefix = prefix + ZBX_LocalStorage.defines.PREFIX_SEPARATOR;
ZBX_LocalStorage.instance = this;
ZBX_LocalStorage.signature = (Math.random() % 9e6).toString(36).substr(2);
this.abs_to_rel_keymap = {};
this.key_last_write = {};
this.rel_keys = {};
this.abs_keys = {};
this.addKey('version');
this.addKey('tabs.lastseen');
this.addKey('notifications.list');
this.addKey('notifications.active_tabid');
this.addKey('notifications.user_settings');
this.addKey('notifications.alarm_state');
this.addKey('dashboard.copied_widget');
this.addKey('web.notifications.pos');
if (this.readKey('version') != version) {
this.truncate();
this.writeKey('version', version);
}
this.register();