Skip to content

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

core: fix SSE not connecting

Abdullah Atta1658ad8d1865
diff --git a/packages/core/src/api/index.ts b/packages/core/src/api/index.ts
index 685f514a1..d4a2f34e8 100644
--- a/packages/core/src/api/index.ts
+++ b/packages/core/src/api/index.ts
@@ -173,7 +173,6 @@ class Database {
};
options!: Options;
- EventSource?: EventSourceConstructor;
eventSource?: EventSource | null;
tokenManager = new TokenManager(this.kv);
@@ -348,8 +347,9 @@ class Database {
this.eventManager.publish(EVENTS.databaseSyncRequested, true, false);
const forceReconnect = args && args.force;
+ const EventSource = this.options.eventsource;
if (
- !this.EventSource ||
+ !EventSource ||
(!forceReconnect &&
this.eventSource &&
this.eventSource.readyState === this.eventSource.OPEN)
@@ -360,7 +360,7 @@ class Database {
const token = await this.tokenManager.getAccessToken();
if (!token) return;
- this.eventSource = new this.EventSource(`${Hosts.SSE_HOST}/sse`, {
+ this.eventSource = new EventSource(`${Hosts.SSE_HOST}/sse`, {
headers: { Authorization: `Bearer ${token}` }
});