Migrating
Both directions, because a page that only explains how to arrive is a page you should not trust.
Coming from a y-websocket deployment
The protocol is the same one, so your client does not change. The endpoint does, and a token comes with it:
const provider = new WebsocketProvider(
- 'wss://collab.your-own-host.example',
+ 'wss://quoincloud.com/api/collab',
'design-notes',
doc,
+ { params: { token: await mintToken('design-notes') } },
);Keep your room names as they are. Rooms are namespaced by project on the server, so your notes and another customer's notes are two documents, and your client never sees the rewritten name.
Bringing your documents with you
A room here starts empty, and the first client to connect with a document fills it. So moving existing documents in is a loop that opens each one, waits for it to sync, and closes it. Nothing else is needed, and there is no import endpoint to learn.
import * as Y from 'yjs';
import { WebsocketProvider } from 'y-websocket';
const ENDPOINT = 'wss://quoincloud.com/api/collab';
for (const { room, state } of everythingYouAlreadyHave()) {
const doc = new Y.Doc();
Y.applyUpdate(doc, state);
const provider = new WebsocketProvider(ENDPOINT, room, doc, {
params: { token: await mintToken(room) },
WebSocketPolyfill: WebSocket,
disableBc: true,
});
await new Promise((done) => provider.once('synced', done));
provider.destroy();
}Run it once, with your own signing secret, before you point any browser at the new endpoint. disableBc matters in a script that opens many documents in one process: without it, y-websocket syncs instances to each other in the background, which is not what you are trying to test here. The project's Rooms tab lists what arrived, with sizes, which is the check worth doing before you cut over.
Leaving
Each document exports from its project's Rooms tab as the Yjs state a server would hold. It is an ordinary update, so reading it needs Yjs and nothing else:
import * as Y from 'yjs';
const state = new Uint8Array(await (await fetch(exportUrl)).arrayBuffer());
const doc = new Y.Doc();
Y.applyUpdate(doc, state);
doc.getText('quoin').toString();Then point your provider at whatever is serving you next, which running it yourself covers. The move out is the move in with the arrow reversed, which is the point.