Skip to content

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

feat: allow frontend to specify its own eventsource lib

thecodrr24c28483c173
diff --git a/packages/core/api/index.js b/packages/core/api/index.js
index 1cbafadf2..c5afaf6a9 100644
--- a/packages/core/api/index.js
+++ b/packages/core/api/index.js
@@ -12,12 +12,21 @@ import Backup from "../database/backup";
import Conflicts from "./sync/conflicts";
import EventManager from "../utils/event-manager";
import Session from "./session";
-import { EventSourcePolyfill } from "event-source-polyfill";
import { HOST } from "../utils/constants";
+/**
+ * @type {EventSource}
+ */
+var NNEventSource;
class Database {
- constructor(context) {
+ /**
+ *
+ * @param {any} context
+ * @param {EventSource} eventsource
+ */
+ constructor(context, eventsource) {
this.context = new Storage(context);
+ NNEventSource = eventsource;
this._syncInterval = 0;
}
@@ -67,6 +76,7 @@ class Database {
}
async _onUserStateChanged(user) {
+ if (!NNEventSource) return;
if (this.evtSource) {
this.evtSource.close();
}
@@ -76,7 +86,7 @@ class Database {
user = await this.user.get();
}
- this.evtSource = new EventSourcePolyfill(`${HOST}/events`, {
+ this.evtSource = new NNEventSource(`${HOST}/events`, {
headers: { Authorization: `Bearer ${user.accessToken}` },
});
diff --git a/packages/core/package.json b/packages/core/package.json
index 5305cdee6..8c75a5ef5 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -20,7 +20,6 @@
"test": "jest"
},
"dependencies": {
- "event-source-polyfill": "^1.0.16",
"fast-sort": "^2.0.1",
"fuzzysearch": "^1.0.3",
"no-internet": "^1.5.2",
diff --git a/packages/core/yarn.lock b/packages/core/yarn.lock
index bfa5d495a..70c4de445 100644
--- a/packages/core/yarn.lock
+++ b/packages/core/yarn.lock
@@ -2327,11 +2327,6 @@ esutils@^2.0.2:
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==
-event-source-polyfill@^1.0.16:
- version "1.0.17"
- resolved "https://registry.yarnpkg.com/event-source-polyfill/-/event-source-polyfill-1.0.17.tgz#850a5103c8fbc5c2c0640ca8e545224e3be9614d"
- integrity sha512-eLZQQpKZahOH5sFaqfrbLNXJKz+JawiDQVrl6lZmQHHSamIn5PlNV3HXAY9+ZRaQC5YTIBRDd8jeTxjuEveJnQ==
-
exec-sh@^0.3.2:
version "0.3.4"
resolved "https://registry.yarnpkg.com/exec-sh/-/exec-sh-0.3.4.tgz#3a018ceb526cc6f6df2bb504b2bfe8e3a4934ec5"