mirror of
https://github.com/irislib/iris-messenger.git
synced 2024-10-18 06:03:22 +00:00
dont add same listener many times
This commit is contained in:
parent
1d6b7d2ead
commit
f374051446
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user