dont add same listener many times

This commit is contained in:
Martti Malmi 2023-08-25 16:43:09 +03:00
parent 1d6b7d2ead
commit f374051446

View File

@ -7,6 +7,8 @@ import { UniqueIds } from '@/utils/UniqueIds.ts';
let relayPoolInstance: RelayPool | null = null;
let isListenerAdded = false;
const getRelayPool = () => {
if (relayPoolInstance) {
return relayPoolInstance;
@ -31,12 +33,15 @@ const getRelayPool = () => {
}
};
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
reconnect();
}
});
document.addEventListener('online', reconnect);
if (!isListenerAdded) {
isListenerAdded = true;
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
reconnect();
}
});
document.addEventListener('online', reconnect);
}
relayPoolInstance = new RelayPool(Relays.enabledRelays(), {
useEventCache: false,