Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/pull/connector/src/ |
Upload File : |
/* eslint-disable @bitrix24/bitrix24-rules/no-native-events-binding */ import { getDateForLog, getFunction, getTimestamp } from '../../util/src/util'; export class SharedConfig { constructor(params = {}) { this.storage = params.storage; this.ttl = 24 * 60 * 60; this.lsKeys = { websocketBlocked: 'bx-pull-websocket-blocked', longPollingBlocked: 'bx-pull-longpolling-blocked', loggingEnabled: 'bx-pull-logging-enabled', }; this.callbacks = { onWebSocketBlockChanged: getFunction(params.onWebSocketBlockChanged), }; if (this.storage) { window.addEventListener('storage', this.onLocalStorageSet.bind(this)); } } onLocalStorageSet(params) { if ( this.storage.compareKey(params.key, this.lsKeys.websocketBlocked) && params.newValue !== params.oldValue ) { this.callbacks.onWebSocketBlockChanged({ isWebSocketBlocked: this.isWebSocketBlocked(), }); } } isWebSocketBlocked(): boolean { if (!this.storage) { return false; } return this.storage.get(this.lsKeys.websocketBlocked, 0) > getTimestamp(); } setWebSocketBlocked(isWebSocketBlocked) { if (!this.storage) { return; } try { this.storage.set(this.lsKeys.websocketBlocked, (isWebSocketBlocked ? getTimestamp() + this.ttl : 0)); } catch (e) { console.error(`${getDateForLog()} Pull: Could not save WS_blocked flag in local storage. Error:`, e); } } isLongPollingBlocked(): boolean { if (!this.storage) { return false; } return this.storage.get(this.lsKeys.longPollingBlocked, 0) > getTimestamp(); } setLongPollingBlocked(isLongPollingBlocked) { if (!this.storage) { return; } try { this.storage.set(this.lsKeys.longPollingBlocked, (isLongPollingBlocked ? getTimestamp() + this.ttl : 0)); } catch (e) { console.error(`${getDateForLog()} Pull: Could not save LP_blocked flag in local storage. Error:`, e); } } }