15
6
Fork
You've already forked y-webxdc
2
webxdc yjs provider
  • TypeScript 97.5%
  • JavaScript 2.5%
faassen 00b4f488ee
All checks were successful
Check / check (push) Successful in 5m45s
Merge pull request 'refactor: protocol should also be a class, not an interface' ( #27 ) from protocol-class into main
Reviewed-on: #27
Reviewed-by: hpk <hpk@noreply.codeberg.org>
2026年07月10日 18:02:40 +02:00
.forgejo/workflows tooling: release script, release preparations 2026年07月08日 15:09:25 +02:00
doc Revert "removed screenshots, published 1.0.5" 2023年09月29日 17:24:44 +02:00
src refactor: protocol should also be a class, not an interface 2026年07月10日 17:47:34 +02:00
tests refactor: protocol should also be a class, not an interface 2026年07月10日 17:47:34 +02:00
.gitignore docs: API doc generation 2026年06月30日 13:31:51 +02:00
.prettierignore forgejo actions for checking & publishing API docs. 2026年07月07日 13:48:07 +02:00
CHANGELOG.md Release v1.3.0 2026年07月09日 14:03:58 +02:00
eslint.config.js forgejo actions for checking & publishing API docs. 2026年07月07日 13:48:07 +02:00
LICENSE packaging: add in a missing LICENSE file. 2026年06月23日 19:03:33 +02:00
package.json Release v1.3.0 2026年07月09日 14:03:58 +02:00
pnpm-lock.yaml tooling: release script, release preparations 2026年07月08日 15:09:25 +02:00
pnpm-workspace.yaml comments: fix typo 2026年06月26日 16:41:15 +02:00
README.md forgejo actions for checking & publishing API docs. 2026年07月07日 13:48:07 +02:00
RELEASING.md docs: well that dry-run command didn't work, so replace it with this one 2026年07月09日 14:06:51 +02:00
tsconfig.build.json feat: protocols 2026年07月10日 13:46:04 +02:00
tsconfig.json types: it now typechecks and we can make it strict. 2026年06月25日 21:10:40 +02:00
typedoc.json tooling: release script, release preparations 2026年07月08日 15:09:25 +02:00
vitest.config.ts types: it now typechecks and we can make it strict. 2026年06月25日 21:10:40 +02:00

y-webxdc

Check API docs Repository

Webxdc applications can be shared in chat with messengers like Delta Chat and Cheogram.

Webxdc applications can support collaborative editing: multiple users, each running their own application instance (a "chat peer") over a shared chat channel all editing the same document, or interacting with the same database.

Synchronizing arbitrary application state is an advanced computer science problem. One popular solution is the conflict-free replicated data type, or CRDT for short.

Yjs is a JavaScript library that implements CRDT for JavaScript data structures such as text, arrays and maps.

This library, y-webxdc, provides an integration of Yjs with Webxdc. It tries to make building collaborative live editing more approachable for Webxdc. It ensures that updates to your application's state are distributed to other chat peers of that same application in a shared chat channel.

What does y-webxdc provide?

  • You use Yjs shared data types for your application state, and WebxdcProvider in this lib makes it work with Webxdc.

  • Receiving updates to application state from chat peers.

  • Autosave: automatically send application state changes periodically to chat peers.

  • Manual save: call syncToChatPeers() to cause an immediate save (it's fine to mix manual with autosave).

  • Control which metadata is shown in a chat by setting document, summary and chat-message information (see the screenshots below).

  • Reliably save any pending application state changes when the app window closes, on all webxdc-supporting platforms.

Technical Limitations

Since Webxdc is inherently an unreliable channel messages can get lost. To force consistency over unreliable message delivery, the entire application state is sent every update. Incoming state is merged into the local state using yjs.

This may lead to issues if the application state gets large.Yjs provides more sophisticated mechanisms to send updates, but those provide challenges over a lossy broadcast network that this library has not solved as of yet.

Setup

Install

npm i y-webxdc

API docs

For a complete overview of the API, see API docs.

Client code

import * as Y from "yjs";
import { WebxdcProvider } from "y-webxdc";
// provided by messengers or webxdc-dev tool
// see https://docs.webxdc.org/spec.html
const webxdc = window.webxdc;
const ydoc = new Y.Doc();
const yarray = ydoc.get("array", Y.Array);
const provider = new WebxdcProvider({
 webxdc,
 ydoc,
 getEditInfo: () => {
 const document = "webxdc yjs provider";
 const summary = `Last edit: ${webxdc.selfName}`;
 const startinfo = `${webxdc.selfName} editing ${document}`;
 return { document, summary, startinfo };
 },
});

See the following example for the meaning of document, summary and startinfo as returned by the getEditInfo callback passed into the provider.

Example

The webxdc editor uses y-webxdc to implement a collaborative editor.

Editor running Delta Chat desktop

Showing edit information in chat

Development

This project is written in TypeScript and uses pnpm. Install dependencies with:

pnpm install

Test

Run the test suite (vitest):

pnpm test

Build

Compile src/ to dist/ (JavaScript plus type declarations):

pnpm build

Type check

Check types without emitting any output:

pnpm typecheck

Code Style

Linting with eslint and formatting with prettier:

pnpm lint
pnpm lint:fix
pnpm format

pnpm lint:fix applies eslint fixes; pnpm format reformats with prettier.

Check everything

pnpm check runs the formatting check, the type checker, the linter and the tests together:

pnpm check