@open-secure-viewer/collab
v0.1.0
Published
Real-time collaborative editing for Open Secure Viewer — Yjs CRDT over WebSocket with shared annotations + presence cursors.
Downloads
90
Maintainers
Readme
@open-secure-viewer/collab
Real-time collaborative editing for Open Secure Viewer.
- Yjs CRDT over WebSocket — automatic conflict resolution, no custom merge code
- Presence cursors + page indicators via the y-websocket awareness channel
- Per-user annotation ownership — only the original author can edit / delete
- Reconnect with exponential backoff — survives transient network failures
- Framework-agnostic — pairs with any OsvViewer host (React, Vue, Svelte, vanilla)
Install
npm install @open-secure-viewer/collab @open-secure-viewer/core yjs y-websocketUsage
import { OsvViewer } from '@open-secure-viewer/core';
import { CollabClient } from '@open-secure-viewer/collab';
const container = document.getElementById('viewer')!;
const viewer = new OsvViewer({ container, wasmUrl: '/pdfium.wasm' });
await viewer.load('/document.pdf');
const collab = new CollabClient({
serverUrl: 'wss://collab.example.com',
documentId: 'doc-123',
user: { id: 'u-1', name: 'Alice', color: '#4CAF50' },
token: jwtToken, // forwarded as WS sub-protocol
});
collab.attach(viewer, container).connect();
collab.on('synced', () => console.log('initial sync done'));
collab.on('peerJoin', u => console.log('joined:', u.name));
collab.on('presenceChange', list => console.log('users now:', list.length));See examples/collab-demo for a runnable end-to-end setup with a reference Node.js server and React UI.
License
Apache-2.0
