mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
WIP sync client
This commit is contained in:
parent
508cfbc843
commit
f12ed8e0b2
12 changed files with 327 additions and 146 deletions
|
@ -54,6 +54,7 @@ import Collab, {
|
|||
collabAPIAtom,
|
||||
isCollaboratingAtom,
|
||||
isOfflineAtom,
|
||||
syncAPIAtom,
|
||||
} from "./collab/Collab";
|
||||
import {
|
||||
exportToBackend,
|
||||
|
@ -363,11 +364,20 @@ const ExcalidrawWrapper = () => {
|
|||
|
||||
const [, setShareDialogState] = useAtom(shareDialogStateAtom);
|
||||
const [collabAPI] = useAtom(collabAPIAtom);
|
||||
const [syncAPI] = useAtom(syncAPIAtom);
|
||||
const [isCollaborating] = useAtomWithInitialValue(isCollaboratingAtom, () => {
|
||||
return isCollaborationLink(window.location.href);
|
||||
});
|
||||
const collabError = useAtomValue(collabErrorIndicatorAtom);
|
||||
|
||||
useEffect(() => {
|
||||
syncAPI?.reconnect();
|
||||
|
||||
return () => {
|
||||
syncAPI?.disconnect();
|
||||
};
|
||||
}, [syncAPI]);
|
||||
|
||||
useHandleLibrary({
|
||||
excalidrawAPI,
|
||||
adapter: LibraryIndexedDBAdapter,
|
||||
|
@ -671,7 +681,7 @@ const ExcalidrawWrapper = () => {
|
|||
|
||||
// some appState like selections should also be transfered (we could even persist it)
|
||||
if (!elementsChange.isEmpty()) {
|
||||
console.log(elementsChange);
|
||||
syncAPI?.push("durable", [elementsChange]);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -88,7 +88,9 @@ import type {
|
|||
ReconciledExcalidrawElement,
|
||||
RemoteExcalidrawElement,
|
||||
} from "../../packages/excalidraw/data/reconcile";
|
||||
import { ExcalidrawSyncClient } from "../../packages/excalidraw/sync/client";
|
||||
|
||||
export const syncAPIAtom = atom<ExcalidrawSyncClient | null>(null);
|
||||
export const collabAPIAtom = atom<CollabAPI | null>(null);
|
||||
export const isCollaboratingAtom = atom(false);
|
||||
export const isOfflineAtom = atom(false);
|
||||
|
@ -234,6 +236,10 @@ class Collab extends PureComponent<CollabProps, CollabState> {
|
|||
};
|
||||
|
||||
appJotaiStore.set(collabAPIAtom, collabAPI);
|
||||
appJotaiStore.set(
|
||||
syncAPIAtom,
|
||||
new ExcalidrawSyncClient(this.excalidrawAPI),
|
||||
);
|
||||
|
||||
if (import.meta.env.MODE === ENV.TEST || import.meta.env.DEV) {
|
||||
window.collab = window.collab || ({} as Window["collab"]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue