@gotipe/collaboration
v0.1.1
Published
Real-time collaboration for the GoTipe editor: CRDT sync with GoTipe Cloud, awareness and cursors.
Maintainers
Readme
@gotipe/collaboration
Real-time collaboration for the GoTipe editor. Each editor holds a replica of GoTipe's own
CRDT (Rust compiled to WebAssembly); CollaborationProvider carries its operations to a
GoTipe Cloud sync server over a WebSocket and shows who else is in the document. GoTipe
Cloud is a backend you run yourself.
Docs · Website · Repository
Install
npm install @gotipe/collaboration @gotipe/core @gotipe/wasm@gotipe/wasm is an optional peer of @gotipe/core, but collaboration needs it: create the
editor with engine: "wasm". The JS engine has no CRDT.
Usage
import { type CollaborationState, CollaborationProvider } from "@gotipe/collaboration";
import { createEditor } from "@gotipe/core";
import { FullPreset } from "@gotipe/core/presets";
// From GET /v1/documents/{id} of your GoTipe Cloud: { baseline, updates, generation }.
declare const initialState: CollaborationState;
declare const getToken: () => Promise<string>;
const editor = await createEditor({
engine: "wasm",
content: initialState.baseline,
extensions: [FullPreset],
});
const provider = new CollaborationProvider({
documentId: "doc-123",
wsUrl: "wss://sync.example.com/sync",
initialState,
token: getToken,
user: { name: "Alice", color: "#3264ab" },
onError: (error) => console.warn(error.message),
});
provider.connect(editor); // replays the stored updates; connect before mounting
editor.mount(document.querySelector<HTMLElement>("#editor")!);
// When the view closes:
// provider.destroy(); editor.destroy();CollaborationProviderowns the WebSocket, the handshake, saving with acknowledgements, reconnects and awareness (names, colors, carets).defineCollaborationcreates and connects a provider with the editor;getCollaborationProvider(editor)returns it.LocalCollaborationBridgesyncs editors on one page without a server, for demos and tests.applyCollaborationState(editor, state, peerId)replays stored state for a transport of your own.
Comments, suggestions, versions and undo history are not part of the replicated document. See Collaboration provider and Offline and conflicts.
License
MIT — see LICENSE.
