mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
feat: allow frontend to specify its own eventsource lib
This commit is contained in:
@@ -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}` },
|
||||
});
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user