mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
core: revert "make sync hub connection more reliable"
This commit is contained in:
@@ -135,6 +135,7 @@ class Sync {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.withHubProtocol(new MessagePackHubProtocol({ ignoreUndefined: true }))
|
.withHubProtocol(new MessagePackHubProtocol({ ignoreUndefined: true }))
|
||||||
|
.withAutomaticReconnect()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
EV.subscribe(EVENTS.userLoggedOut, async () => {
|
EV.subscribe(EVENTS.userLoggedOut, async () => {
|
||||||
@@ -142,10 +143,6 @@ class Sync {
|
|||||||
this.autoSync.stop();
|
this.autoSync.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.connection.onclose((error) => {
|
|
||||||
this.logger.error(error || new Error("Connection closed."));
|
|
||||||
});
|
|
||||||
|
|
||||||
this.connection.on("SyncItem", async (syncStatus) => {
|
this.connection.on("SyncItem", async (syncStatus) => {
|
||||||
await this.onSyncItem(syncStatus);
|
await this.onSyncItem(syncStatus);
|
||||||
sendSyncProgressEvent(
|
sendSyncProgressEvent(
|
||||||
@@ -170,6 +167,11 @@ class Sync {
|
|||||||
async start(full, force, serverLastSynced) {
|
async start(full, force, serverLastSynced) {
|
||||||
this.logger.info("Starting sync", { full, force, serverLastSynced });
|
this.logger.info("Starting sync", { full, force, serverLastSynced });
|
||||||
|
|
||||||
|
this.connection.onclose((error) => {
|
||||||
|
this.logger.error(error || new Error("Connection closed."));
|
||||||
|
throw new Error("Connection closed.");
|
||||||
|
});
|
||||||
|
|
||||||
const { lastSynced, oldLastSynced } = await this.init(force);
|
const { lastSynced, oldLastSynced } = await this.init(force);
|
||||||
this.logger.info("Initialized sync", { lastSynced, oldLastSynced });
|
this.logger.info("Initialized sync", { lastSynced, oldLastSynced });
|
||||||
|
|
||||||
@@ -403,15 +405,12 @@ class Sync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async checkConnection() {
|
async checkConnection() {
|
||||||
const CONNECTED_STATES = [
|
|
||||||
signalr.HubConnectionState.Connected,
|
|
||||||
signalr.HubConnectionState.Connecting,
|
|
||||||
signalr.HubConnectionState.Reconnecting,
|
|
||||||
signalr.HubConnectionState.Disconnecting
|
|
||||||
];
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!CONNECTED_STATES.includes(this.connection.state)) {
|
if (this.connection.state !== signalr.HubConnectionState.Connected) {
|
||||||
|
if (this.connection.state !== signalr.HubConnectionState.Disconnected) {
|
||||||
|
await this.connection.stop();
|
||||||
|
}
|
||||||
|
|
||||||
await promiseTimeout(15000, this.connection.start());
|
await promiseTimeout(15000, this.connection.start());
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user