y-openrtc
v3.3.1
Published
A Yjs provider that uses OpenRTC for room membership and peer transport.
Maintainers
Readme
y-openrtc
y-openrtc is a Yjs provider that feels close to y-webrtc, but uses OpenRTC for room membership and peer transport.
Install
pnpm add y-openrtc yjsMinimal usage
import * as Y from 'yjs';
import { OpenRTC } from 'openrtc';
import { YProvider } from 'y-openrtc';
const rtc = OpenRTC({ apiKey: '<your public OpenRTC API key>' });
const room = await rtc.rooms.join('my-room', {
access: 'capability',
membership: 'ephemeral',
});
const doc = new Y.Doc();
const provider = new YProvider('my-room', doc, {
room,
// Keep offline edits across reload (document only; awareness stays live).
persistLocalDoc: true,
});
await provider.localDocReady;Advanced usage
import * as Y from 'yjs';
import { OpenRTC } from 'openrtc';
import { YProvider } from 'y-openrtc';
const room = await rtc.rooms.join('private-room', {
access: 'authenticated',
auth,
});
const doc = new Y.Doc();
const provider = new YProvider('my-room', doc, {
room,
});Transport and strict-mode options
Configure advanced transports on the OpenRTC client, then pass the activated room:
const rtc = OpenRTC({
apiKey: '<your public OpenRTC API key>',
transports: {
iroh: true,
webrtc: true,
moq: { relayUrl: 'https://draft14-relay.example.com/moq' },
},
});
const room = await rtc.rooms.join('private-room', { access: 'capability' });
const provider = new YProvider('private-room', doc, { room });WebRTC and MoQ are custom packet carriers beneath the same Iroh endpoint. Keep
TURN and MoQ credentials server-generated and short lived. Do not commit .env
files or long-lived secrets.
Differences from y-webrtc
signalingandpeerOptsare accepted for compatibility, but ignored.- OpenRTC remains the source of truth for room membership and peer transport.
- Runtime connection events and room-membership changes drive peer attachment; the provider does not poll or own base-connection retries.
- A supplied room owns discovery and dialing. Its ID determines membership; the provider's document label can be different. Provider frames use the room's scoped public connections, with a JSON envelope preserving Yjs bytes. Diagnostic transport connections are never used for document delivery.
- Same-tab sync still prefers
BroadcastChannelwhen available. passwordencrypts provider payloads end-to-end on top of OpenRTC.- Optional
persistLocalDocstores the Yjs document body in IndexedDB so offline edits survive a browser reload. Rehydration feeds the existing sync path; it does not dial, retry, or own peer lifecycle. Awareness is never persisted. - Editor awareness (cursors, selections, display names) is ephemeral display
data carried in the same bounded frames as document sync (64 KiB each; an
oversized presence state is dropped while document sync continues). It is
never application identity: use the room's member roster / authenticated
node for that. Remote peers cannot write or erase the local collaborator's
own awareness state. Remote presence clears when the room owner retires that
peer's connection or roster entry, and when this provider leaves; after
disconnect()thenconnect()the local awareness state is re-announced.
Live test env
The live test at tests/YProvider.live.test.ts reads package-local env values.
Create openrtc/packages/y-openrtc/.env.local with:
OPENRTC_Y_OPENRTC_API_KEY=<your public OpenRTC API key>Then run:
pnpm --dir openrtc/packages/y-openrtc test:liveThe live test only uses the public OpenRTC API key. Server secrets are not needed for this package-local live test and should stay server-side.
It checks document and awareness convergence between isolated browser contexts,
so BroadcastChannel cannot hide a broken network path. The separate static Hub
configuration check runs only when OPENRTC_HUB_API_KEY is supplied.
