import * as awarenessProtocol from "y-protocols/awareness"; import * as Y from "yjs"; import { WebrtcProvider } from "./webrtc/WebrtcProvider"; export declare const messageSync = 0; export declare const messageQueryAwareness = 3; export declare const messageAwareness = 1; /** * This class implements a webrtc+broadcast channel for document updates and awareness, * with signed messages which should be verified. * * We use SignedWebrtcProvider to establish a "live connection" between peers, * so that changes by simultaneous editors are synced instantly. * * Ideally, we'd just send these over Matrix as Ephemeral events, * but custom ephemeral events are not supported yet. * * This implementation mimicks the original y-webrtc implementation. However: * - initial document state is not synced via this provider, only incremental updates * * We should probably move to ephemeral messages when that's available. Besides from that, * the following improvements can be made: * - Support a TURN server in case clients can't connect directly over WebRTC * - Do the signalling over Matrix, instead of the original yjs websocket server * - Verify the webrtc connection instead of signing / verifying every message * - It would be better to not depend this class on yjs (remove dependency on Y.Doc and Awareness) * Instead, design it in a way that it's just a different transport for "Matrix events". * This would also fix the following issue: * * Issue (non-breaking): * - The original y-webrtc is designed so that document updates are send to all peers, by all peers. * This means that if A, B, C, and D are connected, when A issues an update and B receives it, * B will issue that same update (because it triggers a y.doc.update) and send it to all peers as well * (even though most peers would have received it already). * What's not cool about our implementation now is that this forward-syncing goes via the Y.Doc, * i.e.: client B will create a new update and sign it itself. Which means that if B is a read-only * client, all other clients will receive "invalid" messages (which could have been prevented if * the message from A was forwarded directly) * * Issue (edge-case): * - if an update is received and validated by B, and A hasn't synced it to Matrix yet, * then B will sync it to Matrix upon restart (when it syncs local changes to Matrix). * This will cause an update originally from A to be sent to Matrix as authored by B */ export declare class SignedWebrtcProvider extends WebrtcProvider { private doc; private roomPassword; private sign; private verify; readonly awareness: awarenessProtocol.Awareness; protected onCustomMessage: (buf: Uint8Array, reply: (message: Uint8Array) => void) => void; protected onPeerConnected: (reply: (message: Uint8Array) => void) => void; /** * Listens to Yjs updates and sends them to remote peers */ private _docUpdateHandler; /** * Listens to Awareness updates and sends them to remote peers */ private _awarenessUpdateHandler; constructor(doc: Y.Doc, roomName: string, roomPassword: string, sign: (obj: any) => Promise, verify: (obj: any) => Promise, opts?: any, awareness?: awarenessProtocol.Awareness); destroy(): void; }