@abraca/dabra 2.90.0 → 2.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -11
- package/src/AbracadabraBaseProvider.ts +0 -963
- package/src/AbracadabraClient.ts +0 -1960
- package/src/AbracadabraProvider.ts +0 -915
- package/src/AbracadabraWS.ts +0 -695
- package/src/BackgroundSyncManager.ts +0 -856
- package/src/BackgroundSyncPersistence.ts +0 -140
- package/src/ChatClient.ts +0 -314
- package/src/CloseEvents.ts +0 -49
- package/src/ContentManager.ts +0 -246
- package/src/CoverReconcile.ts +0 -168
- package/src/CryptoIdentityKeystore.ts +0 -754
- package/src/DeviceRegistrationService.ts +0 -257
- package/src/DocConverters.ts +0 -1859
- package/src/DocKeyManager.ts +0 -163
- package/src/DocTypes.ts +0 -628
- package/src/DocUtils.ts +0 -251
- package/src/DocumentCache.ts +0 -210
- package/src/DocumentManager.ts +0 -410
- package/src/E2EAbracadabraProvider.ts +0 -426
- package/src/E2EOfflineStore.ts +0 -55
- package/src/EncryptedChatClient.ts +0 -173
- package/src/EncryptedY.ts +0 -145
- package/src/EventEmitter.ts +0 -59
- package/src/FileBlobStore.ts +0 -569
- package/src/IdentityDoc.ts +0 -711
- package/src/IncomingMessage.ts +0 -63
- package/src/MessageReceiver.ts +0 -151
- package/src/MessageSender.ts +0 -22
- package/src/MetaManager.ts +0 -194
- package/src/MnemonicKeyDerivation.ts +0 -171
- package/src/NodeConnect.ts +0 -63
- package/src/NodeIdentity.ts +0 -378
- package/src/NotificationsClient.ts +0 -207
- package/src/OfflineStore.ts +0 -294
- package/src/OutgoingMessage.ts +0 -25
- package/src/OutgoingMessages/AuthenticationMessage.ts +0 -23
- package/src/OutgoingMessages/AwarenessMessage.ts +0 -41
- package/src/OutgoingMessages/CloseMessage.ts +0 -17
- package/src/OutgoingMessages/QueryAwarenessMessage.ts +0 -17
- package/src/OutgoingMessages/StatelessMessage.ts +0 -18
- package/src/OutgoingMessages/SubdocMessage.ts +0 -35
- package/src/OutgoingMessages/SyncStepOneMessage.ts +0 -25
- package/src/OutgoingMessages/SyncStepTwoMessage.ts +0 -25
- package/src/OutgoingMessages/UpdateMessage.ts +0 -20
- package/src/QueryClient.ts +0 -209
- package/src/RpcClient.ts +0 -659
- package/src/SchemaTypes.ts +0 -179
- package/src/SearchIndex.ts +0 -250
- package/src/ServerRegistry.ts +0 -220
- package/src/ServerReset.ts +0 -222
- package/src/TokenManager.ts +0 -337
- package/src/TreeManager.ts +0 -894
- package/src/TreeTimestamps.ts +0 -101
- package/src/auth.ts +0 -62
- package/src/awarenessStatesToArray.ts +0 -10
- package/src/index.ts +0 -219
- package/src/messageRecord.ts +0 -121
- package/src/sync/BroadcastChannelSync.ts +0 -235
- package/src/types.ts +0 -790
- package/src/webrtc/AbracadabraWebRTC.ts +0 -683
- package/src/webrtc/DataChannelRouter.ts +0 -179
- package/src/webrtc/DevicePairingChannel.ts +0 -496
- package/src/webrtc/E2EEChannel.ts +0 -195
- package/src/webrtc/FileTransferChannel.ts +0 -367
- package/src/webrtc/ManualSignaling.ts +0 -204
- package/src/webrtc/PeerConnection.ts +0 -133
- package/src/webrtc/SignalingSocket.ts +0 -378
- package/src/webrtc/YjsDataChannel.ts +0 -203
- package/src/webrtc/index.ts +0 -26
- package/src/webrtc/types.ts +0 -177
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import * as Y from "yjs";
|
|
2
|
-
import * as syncProtocol from "y-protocols/sync";
|
|
3
|
-
import {
|
|
4
|
-
encodeAwarenessUpdate,
|
|
5
|
-
applyAwarenessUpdate,
|
|
6
|
-
type Awareness,
|
|
7
|
-
} from "y-protocols/awareness";
|
|
8
|
-
import * as encoding from "lib0/encoding";
|
|
9
|
-
import * as decoding from "lib0/decoding";
|
|
10
|
-
import EventEmitter from "../EventEmitter.ts";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Cross-tab Y.js document and awareness sync via the BroadcastChannel API.
|
|
14
|
-
*
|
|
15
|
-
* Opens a BroadcastChannel per document, relays Y.js updates and awareness
|
|
16
|
-
* state between tabs on the same origin. No server, no WebRTC — just same-device
|
|
17
|
-
* multi-tab sync. Same-origin means same trust boundary, so no encryption needed.
|
|
18
|
-
*
|
|
19
|
-
* Uses the same y-protocols/sync encoding as `YjsDataChannel` for consistency.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
const CHANNEL_PREFIX = "abra:sync:";
|
|
23
|
-
|
|
24
|
-
/** Message type discriminators (first byte). */
|
|
25
|
-
const MSG = {
|
|
26
|
-
SYNC: 0x00,
|
|
27
|
-
UPDATE: 0x01,
|
|
28
|
-
AWARENESS: 0x02,
|
|
29
|
-
/** Request all tabs to respond with SyncStep1. */
|
|
30
|
-
QUERY_PEERS: 0x03,
|
|
31
|
-
} as const;
|
|
32
|
-
|
|
33
|
-
export class BroadcastChannelSync extends EventEmitter {
|
|
34
|
-
private channel: BroadcastChannel | null = null;
|
|
35
|
-
private docUpdateHandler: ((update: Uint8Array, origin: any) => void) | null =
|
|
36
|
-
null;
|
|
37
|
-
private awarenessUpdateHandler:
|
|
38
|
-
| ((
|
|
39
|
-
changes: { added: number[]; updated: number[]; removed: number[] },
|
|
40
|
-
origin: any,
|
|
41
|
-
) => void)
|
|
42
|
-
| null = null;
|
|
43
|
-
private destroyed = false;
|
|
44
|
-
|
|
45
|
-
constructor(
|
|
46
|
-
private readonly document: Y.Doc,
|
|
47
|
-
private readonly awareness: Awareness | null,
|
|
48
|
-
private readonly channelName: string,
|
|
49
|
-
) {
|
|
50
|
-
super();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Convenience factory using standard channel naming. */
|
|
54
|
-
static forDoc(
|
|
55
|
-
document: Y.Doc,
|
|
56
|
-
docId: string,
|
|
57
|
-
awareness?: Awareness | null,
|
|
58
|
-
): BroadcastChannelSync {
|
|
59
|
-
return new BroadcastChannelSync(
|
|
60
|
-
document,
|
|
61
|
-
awareness ?? null,
|
|
62
|
-
`${CHANNEL_PREFIX}${docId}`,
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Start syncing. Opens the BroadcastChannel and initiates a sync handshake. */
|
|
67
|
-
connect(): void {
|
|
68
|
-
if (this.destroyed || this.channel) return;
|
|
69
|
-
|
|
70
|
-
if (typeof globalThis.BroadcastChannel === "undefined") {
|
|
71
|
-
// Environment doesn't support BroadcastChannel (e.g. some Node.js builds).
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
this.channel = new BroadcastChannel(this.channelName);
|
|
76
|
-
this.channel.onmessage = (event) => this.handleMessage(event.data);
|
|
77
|
-
|
|
78
|
-
// Listen for local doc updates → broadcast to other tabs.
|
|
79
|
-
this.docUpdateHandler = (update: Uint8Array, origin: any) => {
|
|
80
|
-
if (origin === this) return; // Don't echo.
|
|
81
|
-
this.broadcastUpdate(update);
|
|
82
|
-
};
|
|
83
|
-
this.document.on("update", this.docUpdateHandler);
|
|
84
|
-
|
|
85
|
-
// Listen for local awareness changes → broadcast to other tabs.
|
|
86
|
-
if (this.awareness) {
|
|
87
|
-
this.awarenessUpdateHandler = (
|
|
88
|
-
{
|
|
89
|
-
added,
|
|
90
|
-
updated,
|
|
91
|
-
removed,
|
|
92
|
-
}: { added: number[]; updated: number[]; removed: number[] },
|
|
93
|
-
_origin: any,
|
|
94
|
-
) => {
|
|
95
|
-
const changedClients = added.concat(updated).concat(removed);
|
|
96
|
-
const update = encodeAwarenessUpdate(this.awareness!, changedClients);
|
|
97
|
-
this.broadcastAwareness(update);
|
|
98
|
-
};
|
|
99
|
-
this.awareness.on("update", this.awarenessUpdateHandler);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Announce presence — other tabs reply with SyncStep1.
|
|
103
|
-
this.broadcastQueryPeers();
|
|
104
|
-
|
|
105
|
-
// Send our SyncStep1 to trigger state exchange.
|
|
106
|
-
this.sendSyncStep1();
|
|
107
|
-
|
|
108
|
-
this.emit("connected");
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** Stop syncing and close the BroadcastChannel. */
|
|
112
|
-
disconnect(): void {
|
|
113
|
-
if (this.docUpdateHandler) {
|
|
114
|
-
this.document.off("update", this.docUpdateHandler);
|
|
115
|
-
this.docUpdateHandler = null;
|
|
116
|
-
}
|
|
117
|
-
if (this.awarenessUpdateHandler && this.awareness) {
|
|
118
|
-
this.awareness.off("update", this.awarenessUpdateHandler);
|
|
119
|
-
this.awarenessUpdateHandler = null;
|
|
120
|
-
}
|
|
121
|
-
if (this.channel) {
|
|
122
|
-
this.channel.close();
|
|
123
|
-
this.channel = null;
|
|
124
|
-
}
|
|
125
|
-
this.emit("disconnected");
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** Disconnect and prevent reconnection. */
|
|
129
|
-
destroy(): void {
|
|
130
|
-
this.disconnect();
|
|
131
|
-
this.destroyed = true;
|
|
132
|
-
this.removeAllListeners();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// ── Outgoing ────────────────────────────────────────────────────────────
|
|
136
|
-
|
|
137
|
-
private broadcastUpdate(update: Uint8Array): void {
|
|
138
|
-
if (!this.channel) return;
|
|
139
|
-
const encoder = encoding.createEncoder();
|
|
140
|
-
encoding.writeVarUint(encoder, MSG.UPDATE);
|
|
141
|
-
encoding.writeVarUint8Array(encoder, update);
|
|
142
|
-
this.channel.postMessage(encoding.toUint8Array(encoder));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
private broadcastAwareness(update: Uint8Array): void {
|
|
146
|
-
if (!this.channel) return;
|
|
147
|
-
const encoder = encoding.createEncoder();
|
|
148
|
-
encoding.writeVarUint(encoder, MSG.AWARENESS);
|
|
149
|
-
encoding.writeVarUint8Array(encoder, update);
|
|
150
|
-
this.channel.postMessage(encoding.toUint8Array(encoder));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
private sendSyncStep1(): void {
|
|
154
|
-
if (!this.channel) return;
|
|
155
|
-
const encoder = encoding.createEncoder();
|
|
156
|
-
encoding.writeVarUint(encoder, MSG.SYNC);
|
|
157
|
-
syncProtocol.writeSyncStep1(encoder, this.document);
|
|
158
|
-
this.channel.postMessage(encoding.toUint8Array(encoder));
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
private broadcastQueryPeers(): void {
|
|
162
|
-
if (!this.channel) return;
|
|
163
|
-
const encoder = encoding.createEncoder();
|
|
164
|
-
encoding.writeVarUint(encoder, MSG.QUERY_PEERS);
|
|
165
|
-
this.channel.postMessage(encoding.toUint8Array(encoder));
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// ── Incoming ────────────────────────────────────────────────────────────
|
|
169
|
-
|
|
170
|
-
private handleMessage(data: any): void {
|
|
171
|
-
if (!(data instanceof ArrayBuffer || data instanceof Uint8Array)) return;
|
|
172
|
-
const buf = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
|
|
173
|
-
const decoder = decoding.createDecoder(buf);
|
|
174
|
-
const msgType = decoding.readVarUint(decoder);
|
|
175
|
-
|
|
176
|
-
switch (msgType) {
|
|
177
|
-
case MSG.SYNC:
|
|
178
|
-
this.handleSyncMessage(decoder);
|
|
179
|
-
break;
|
|
180
|
-
case MSG.UPDATE:
|
|
181
|
-
this.handleUpdateMessage(decoder);
|
|
182
|
-
break;
|
|
183
|
-
case MSG.AWARENESS:
|
|
184
|
-
this.handleAwarenessMessage(decoder);
|
|
185
|
-
break;
|
|
186
|
-
case MSG.QUERY_PEERS:
|
|
187
|
-
// Another tab joined — respond with our SyncStep1.
|
|
188
|
-
this.sendSyncStep1();
|
|
189
|
-
if (this.awareness) {
|
|
190
|
-
const update = encodeAwarenessUpdate(
|
|
191
|
-
this.awareness,
|
|
192
|
-
Array.from(this.awareness.getStates().keys()),
|
|
193
|
-
);
|
|
194
|
-
this.broadcastAwareness(update);
|
|
195
|
-
}
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
private handleSyncMessage(decoder: decoding.Decoder): void {
|
|
201
|
-
const encoder = encoding.createEncoder();
|
|
202
|
-
const syncMessageType = syncProtocol.readSyncMessage(
|
|
203
|
-
decoder,
|
|
204
|
-
encoder,
|
|
205
|
-
this.document,
|
|
206
|
-
this,
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
// If the sync protocol generated a response (SyncStep2), broadcast it.
|
|
210
|
-
if (encoding.length(encoder) > 0) {
|
|
211
|
-
const responseEncoder = encoding.createEncoder();
|
|
212
|
-
encoding.writeVarUint(responseEncoder, MSG.SYNC);
|
|
213
|
-
encoding.writeUint8Array(
|
|
214
|
-
responseEncoder,
|
|
215
|
-
encoding.toUint8Array(encoder),
|
|
216
|
-
);
|
|
217
|
-
this.channel?.postMessage(encoding.toUint8Array(responseEncoder));
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (syncMessageType === syncProtocol.messageYjsSyncStep2) {
|
|
221
|
-
this.emit("synced");
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
private handleUpdateMessage(decoder: decoding.Decoder): void {
|
|
226
|
-
const update = decoding.readVarUint8Array(decoder);
|
|
227
|
-
Y.applyUpdate(this.document, update, this);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
private handleAwarenessMessage(decoder: decoding.Decoder): void {
|
|
231
|
-
if (!this.awareness) return;
|
|
232
|
-
const update = decoding.readVarUint8Array(decoder);
|
|
233
|
-
applyAwarenessUpdate(this.awareness, update, this);
|
|
234
|
-
}
|
|
235
|
-
}
|