mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Fix auto-reconnection & slider value sync
This commit is contained in:
parent
f6061f5ec6
commit
9f8c87ae8c
4 changed files with 13 additions and 33 deletions
|
@ -865,6 +865,8 @@ const ExcalidrawWrapper = () => {
|
||||||
currentVersion.current = value;
|
currentVersion.current = value;
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
|
const latestVersion = acknowledgedIncrements.length - 1;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{ height: "100%" }}
|
style={{ height: "100%" }}
|
||||||
|
@ -882,8 +884,12 @@ const ExcalidrawWrapper = () => {
|
||||||
}}
|
}}
|
||||||
step={1}
|
step={1}
|
||||||
min={0}
|
min={0}
|
||||||
max={acknowledgedIncrements.length}
|
max={latestVersion}
|
||||||
value={nextVersion === -1 ? acknowledgedIncrements.length : nextVersion}
|
value={
|
||||||
|
nextVersion === -1 || nextVersion === latestVersion
|
||||||
|
? latestVersion
|
||||||
|
: nextVersion
|
||||||
|
}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
// CFDO: should be disabled when offline! (later we could have speculative changes in the versioning log as well)
|
// CFDO: should be disabled when offline! (later we could have speculative changes in the versioning log as well)
|
||||||
// CFDO: in safari the whole canvas gets selected when dragging
|
// CFDO: in safari the whole canvas gets selected when dragging
|
||||||
|
|
|
@ -37,7 +37,7 @@ export class DurableIncrementsRepository implements IncrementsRepository {
|
||||||
try {
|
try {
|
||||||
const payload = JSON.stringify(increment);
|
const payload = JSON.stringify(increment);
|
||||||
const payloadSize = new TextEncoder().encode(payload).byteLength;
|
const payloadSize = new TextEncoder().encode(payload).byteLength;
|
||||||
const chunkVersion = this.getLastVersion() + 1;
|
const nextVersion = this.getLastVersion() + 1;
|
||||||
const chunksCount = Math.ceil(
|
const chunksCount = Math.ceil(
|
||||||
payloadSize / DurableIncrementsRepository.MAX_PAYLOAD_SIZE,
|
payloadSize / DurableIncrementsRepository.MAX_PAYLOAD_SIZE,
|
||||||
);
|
);
|
||||||
|
@ -51,7 +51,7 @@ export class DurableIncrementsRepository implements IncrementsRepository {
|
||||||
this.storage.sql.exec(
|
this.storage.sql.exec(
|
||||||
`INSERT INTO increments (id, version, position, payload) VALUES (?, ?, ?, ?);`,
|
`INSERT INTO increments (id, version, position, payload) VALUES (?, ?, ?, ?);`,
|
||||||
increment.id,
|
increment.id,
|
||||||
chunkVersion,
|
nextVersion,
|
||||||
position,
|
position,
|
||||||
chunkedPayload,
|
chunkedPayload,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
import throttle from "lodash.throttle";
|
import throttle from "lodash.throttle";
|
||||||
import ReconnectingWebSocket, {
|
import ReconnectingWebSocket, { type Event } from "reconnecting-websocket";
|
||||||
type Event,
|
|
||||||
type CloseEvent,
|
|
||||||
} from "reconnecting-websocket";
|
|
||||||
import { Utils } from "./utils";
|
import { Utils } from "./utils";
|
||||||
import {
|
import {
|
||||||
SyncQueue,
|
SyncQueue,
|
||||||
|
@ -42,8 +39,6 @@ class SocketClient {
|
||||||
// Chrome throws "Uncaught InvalidAccessError" with message:
|
// Chrome throws "Uncaught InvalidAccessError" with message:
|
||||||
// "The close code must be either 1000, or between 3000 and 4999. 1009 is neither."
|
// "The close code must be either 1000, or between 3000 and 4999. 1009 is neither."
|
||||||
// therefore using custom codes instead.
|
// therefore using custom codes instead.
|
||||||
private static readonly NO_STATUS_RECEIVED_ERROR_CODE = 3005;
|
|
||||||
private static readonly ABNORMAL_CLOSURE_ERROR_CODE = 3006;
|
|
||||||
private static readonly MESSAGE_IS_TOO_LARGE_ERROR_CODE = 3009;
|
private static readonly MESSAGE_IS_TOO_LARGE_ERROR_CODE = 3009;
|
||||||
|
|
||||||
private isOffline = true;
|
private isOffline = true;
|
||||||
|
@ -100,8 +95,6 @@ class SocketClient {
|
||||||
);
|
);
|
||||||
this.socket.addEventListener("message", this.onMessage);
|
this.socket.addEventListener("message", this.onMessage);
|
||||||
this.socket.addEventListener("open", this.onOpen);
|
this.socket.addEventListener("open", this.onOpen);
|
||||||
this.socket.addEventListener("close", this.onClose);
|
|
||||||
this.socket.addEventListener("error", this.onError);
|
|
||||||
},
|
},
|
||||||
1000,
|
1000,
|
||||||
{ leading: true, trailing: false },
|
{ leading: true, trailing: false },
|
||||||
|
@ -127,8 +120,6 @@ class SocketClient {
|
||||||
);
|
);
|
||||||
this.socket?.removeEventListener("message", this.onMessage);
|
this.socket?.removeEventListener("message", this.onMessage);
|
||||||
this.socket?.removeEventListener("open", this.onOpen);
|
this.socket?.removeEventListener("open", this.onOpen);
|
||||||
this.socket?.removeEventListener("close", this.onClose);
|
|
||||||
this.socket?.removeEventListener("error", this.onError);
|
|
||||||
|
|
||||||
let remappedCode = code;
|
let remappedCode = code;
|
||||||
|
|
||||||
|
@ -198,24 +189,6 @@ class SocketClient {
|
||||||
this.isOffline = false;
|
this.isOffline = false;
|
||||||
this.handlers.onOpen(event);
|
this.handlers.onOpen(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
private onClose = (event: CloseEvent) => {
|
|
||||||
this.disconnect(
|
|
||||||
event.code || SocketClient.NO_STATUS_RECEIVED_ERROR_CODE,
|
|
||||||
event.reason || "Connection closed without a reason",
|
|
||||||
);
|
|
||||||
this.connect();
|
|
||||||
};
|
|
||||||
|
|
||||||
private onError = (event: Event) => {
|
|
||||||
this.disconnect(
|
|
||||||
event.type === "error"
|
|
||||||
? SocketClient.ABNORMAL_CLOSURE_ERROR_CODE
|
|
||||||
: SocketClient.NO_STATUS_RECEIVED_ERROR_CODE,
|
|
||||||
`Received "${event.type}" on the sync connection`,
|
|
||||||
);
|
|
||||||
this.connect();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AcknowledgedIncrement {
|
interface AcknowledgedIncrement {
|
||||||
|
@ -288,6 +261,7 @@ export class SyncClient {
|
||||||
return new SyncClient(api, repository, queue, {
|
return new SyncClient(api, repository, queue, {
|
||||||
host: SyncClient.HOST_URL,
|
host: SyncClient.HOST_URL,
|
||||||
roomId: SyncClient.ROOM_ID,
|
roomId: SyncClient.ROOM_ID,
|
||||||
|
// CFDO: temporary, so that all increments are loaded and applied on init
|
||||||
lastAcknowledgedVersion: 0,
|
lastAcknowledgedVersion: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,7 +196,7 @@ export class ExcalidrawSyncServer {
|
||||||
return this.send(client, {
|
return this.send(client, {
|
||||||
type: "rejected",
|
type: "rejected",
|
||||||
payload: {
|
payload: {
|
||||||
message: error ? error.message : "Coudn't persist the increment",
|
message: error ? error.message : "Coudn't persist the increment.",
|
||||||
increments: [increment],
|
increments: [increment],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue