Yjs is a Javascript implementation of Conflict-Free Replicated Datatypes (CRDTs). It allows sharing of distributed data-structures whose replicas can be updated independently, without coordination. A synchronization process runs in the background so that the different replicas reach the same state eventually.
As Yjs itself is network agnostic, a so-called Yjs provider must be used to ensure the communication required by the synchronization of replicas. The DoDWAN Yjs WebSocket Provider is designed to use DoDWAN as a means to exchange synchronization information between Yjs replicas in an opportunistic network.
The DoDWAN Yjs WebSocket Provider is notified of update events (issued by Yjs) and neighbor discovery events (issued by the NAPI WebSocket NAPI client).
When a modification occurs on the Yjs document, the update is broadcast to the neighbors so that replicas hosted on these neighbors are immediately synchronized. Moreover, a delta-state-based synchronization takes place whenever a neighbor is discovered.
On the server side, only NAPI (dodwan-napi plugin) and its websocket implementation (dodwan-napi-ws plugin) are required. So the right DoDWAN launch command is the following:
dodwan_plugins=dodwan-napi,dodwan-napi-ws dodwan.sh start
The DoDWAN Yjs provider can be used more or less the same way as the other providers (y-websocket, y-webrtc). Note however that no awareness information is provided.
Use the following dependency in your package.json to retreive the Javascript implementation
"@casa/yjs-ws-provider": "http://casa-irisa.univ-ubs.fr/download/nodejs/casa-yjs-ws-provider-1.0.0.tgz"
The following code shows how a Yjs data structure (a text) can be shared.
import * as Y from 'yjs'
import { DodwanProvider } from '@casa/yjs-ws-provider'
const ydoc = new Y.Doc()
const provider = new DodwanProvider("ws://localhost:8025", 'demo', ydoc)
const ytext = ydoc.getText('sampleText')
// Edit the text as you wish.
// Contributions by other DoDWAN peers will be automatically merged
ytext.add(0, "hello everybody")
ytext.del(5, 3)