Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: don't reconnect sse if it is already connected

thecodrr6631c0879946
diff --git a/packages/core/api/index.js b/packages/core/api/index.js
index 22fc027c0..2f6242f6f 100644
--- a/packages/core/api/index.js
+++ b/packages/core/api/index.js
@@ -136,11 +136,22 @@ class Database {
this.evtSource = null;
}
+ /**
+ *
+ * @param {{force: boolean, error: any}} args
+ */
async connectSSE(args) {
await this.sseMutex.runExclusive(async () => {
if (args && !!args.error) return;
- if (!NNEventSource) return;
+ const forceReconnect = args && args.force;
+ if (
+ !NNEventSource ||
+ (!forceReconnect &&
+ this.evtSource &&
+ this.evtSource.readyState === this.evtSource.OPEN)
+ )
+ return;
this.disconnectSSE();
let token = await this.user.tokenManager.getAccessToken();