@edv4h/usketch-plugin-sync-ywebsocket 1.1.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/LICENSE +21 -0
- package/README.md +157 -0
- package/dist/divergence-tracker.d.ts +40 -0
- package/dist/divergence-tracker.d.ts.map +1 -0
- package/dist/divergence-tracker.js +134 -0
- package/dist/divergence-tracker.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +18 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +54 -0
- package/dist/plugin.js.map +1 -0
- package/dist/sync-status-tracker.d.ts +112 -0
- package/dist/sync-status-tracker.d.ts.map +1 -0
- package/dist/sync-status-tracker.js +163 -0
- package/dist/sync-status-tracker.js.map +1 -0
- package/dist/types.d.ts +91 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/unconfirmed-overlay.d.ts +21 -0
- package/dist/unconfirmed-overlay.d.ts.map +1 -0
- package/dist/unconfirmed-overlay.js +61 -0
- package/dist/unconfirmed-overlay.js.map +1 -0
- package/dist/yws-sync.d.ts +4 -0
- package/dist/yws-sync.d.ts.map +1 -0
- package/dist/yws-sync.js +492 -0
- package/dist/yws-sync.js.map +1 -0
- package/package.json +52 -0
package/dist/yws-sync.js
ADDED
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import { Awareness } from "y-protocols/awareness";
|
|
2
|
+
import { WebsocketProvider } from "y-websocket";
|
|
3
|
+
import * as Y from "yjs";
|
|
4
|
+
import { SyncStatusTracker } from "./sync-status-tracker.js";
|
|
5
|
+
function toPlainObject(shape) {
|
|
6
|
+
return JSON.parse(JSON.stringify(shape));
|
|
7
|
+
}
|
|
8
|
+
export function createYwebsocketSync(store, options) {
|
|
9
|
+
const { url, roomName, shapesMapKey = "shapes", resolveParams, onCloseCode, idleTimeoutMs = 0, autoConnect = true, doc: providedDoc, WebSocketPolyfill, } = options;
|
|
10
|
+
const doc = providedDoc ?? new Y.Doc();
|
|
11
|
+
const ownsDoc = providedDoc === undefined;
|
|
12
|
+
const shapesMap = doc.getMap(shapesMapKey);
|
|
13
|
+
const status = new SyncStatusTracker();
|
|
14
|
+
let destroyed = false;
|
|
15
|
+
let isSyncing = false;
|
|
16
|
+
let attempt = 0;
|
|
17
|
+
let currentState = null;
|
|
18
|
+
let lastCloseCode;
|
|
19
|
+
let lastCloseReason;
|
|
20
|
+
// `paused` is set by `disconnect()` and cleared by `resume()` / destroy, so an
|
|
21
|
+
// in-flight `connect()` (mid-`await resolveParams`) bails out instead of
|
|
22
|
+
// creating a socket after a user-initiated disconnect.
|
|
23
|
+
let paused = false;
|
|
24
|
+
// Generation counter to cancel stale async `connect()` runs. Each `connect()`
|
|
25
|
+
// captures its generation and re-checks after every await boundary; any
|
|
26
|
+
// disconnect/destroy increments the counter and invalidates pending runs.
|
|
27
|
+
let connectGeneration = 0;
|
|
28
|
+
// A long-lived Awareness bound to `doc`. Created up-front so `wsProvider.awareness`
|
|
29
|
+
// is always valid (WsProviderHandle consumers, e.g. presence-cursor, destructure
|
|
30
|
+
// it at plugin-creation time). The same instance is passed into every
|
|
31
|
+
// WebsocketProvider so remote awareness updates keep flowing through reconnects.
|
|
32
|
+
const sharedAwareness = new Awareness(doc);
|
|
33
|
+
// WsProviderHandle event listener sets — persist across reconnects.
|
|
34
|
+
const statusListeners = new Set();
|
|
35
|
+
const broadcastListeners = new Set();
|
|
36
|
+
// Latest socket-level status. Read by the local mutation handler to decide
|
|
37
|
+
// whether a freshly-added shape should be treated as already "confirmed"
|
|
38
|
+
// (the socket is open so y-websocket immediately broadcasts the update) or
|
|
39
|
+
// as "pending" (offline → diverges until a re-sync).
|
|
40
|
+
let currentWsStatus = "disconnected";
|
|
41
|
+
function notifyStatus(next) {
|
|
42
|
+
currentWsStatus = next;
|
|
43
|
+
// "connected" at the transport level only means the socket is open — the
|
|
44
|
+
// first Yjs sync has not necessarily completed. Map to "syncing" until the
|
|
45
|
+
// provider's `sync` event fires; `onSync` will flip the tracker to "synced".
|
|
46
|
+
status.update({
|
|
47
|
+
state: next === "connected"
|
|
48
|
+
? "syncing"
|
|
49
|
+
: next === "connecting"
|
|
50
|
+
? "connecting"
|
|
51
|
+
: next === "disconnected"
|
|
52
|
+
? "disconnected"
|
|
53
|
+
: "error",
|
|
54
|
+
error: next === "failed" ? "connection failed" : null,
|
|
55
|
+
});
|
|
56
|
+
for (const listener of statusListeners) {
|
|
57
|
+
listener(next);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// ── Store ↔ Y.Doc binding ──────────────────────────────────────────────────
|
|
61
|
+
// These observers are set up once; they keep working across provider reconnects
|
|
62
|
+
// because they bind to `doc` / `shapesMap` rather than the provider.
|
|
63
|
+
const unsubMutation = store.onMutation((event) => {
|
|
64
|
+
if (isSyncing || destroyed)
|
|
65
|
+
return;
|
|
66
|
+
const payload = event.payload;
|
|
67
|
+
if (!payload?.id)
|
|
68
|
+
return;
|
|
69
|
+
// Batch the divergence note + the shapeCount/lastSyncedAt update so
|
|
70
|
+
// subscribers see exactly one snapshot change per local mutation.
|
|
71
|
+
status.batch(() => {
|
|
72
|
+
isSyncing = true;
|
|
73
|
+
try {
|
|
74
|
+
switch (event.type) {
|
|
75
|
+
case "shape:added":
|
|
76
|
+
case "shape:updated": {
|
|
77
|
+
const shape = store.getShape(payload.id);
|
|
78
|
+
if (shape) {
|
|
79
|
+
const isNew = !shapesMap.has(payload.id);
|
|
80
|
+
shapesMap.set(payload.id, toPlainObject(shape));
|
|
81
|
+
if (isNew && event.type === "shape:added") {
|
|
82
|
+
// Socket open → y-websocket immediately broadcasts this
|
|
83
|
+
// shape to the server, so it's effectively confirmed. We
|
|
84
|
+
// only flag local adds as "unconfirmed" while the
|
|
85
|
+
// connection is down, so the warning shows up exactly
|
|
86
|
+
// for offline edits / orphaned IndexedDB state.
|
|
87
|
+
const isOnline = currentWsStatus === "connected";
|
|
88
|
+
status.noteShapeAdded(payload.id, isOnline ? "remote" : "local");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
case "shape:removed": {
|
|
94
|
+
shapesMap.delete(payload.id);
|
|
95
|
+
status.noteShapeRemoved(payload.id);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
isSyncing = false;
|
|
102
|
+
}
|
|
103
|
+
// Keep the status snapshot in sync with the authoritative Y.Map size so
|
|
104
|
+
// consumers (DebugHUD etc.) see up-to-date counts after local edits too.
|
|
105
|
+
status.update({ shapeCount: shapesMap.size, lastSyncedAt: Date.now() });
|
|
106
|
+
});
|
|
107
|
+
resetIdleTimer();
|
|
108
|
+
});
|
|
109
|
+
const shapesObserver = (events) => {
|
|
110
|
+
if (isSyncing || destroyed)
|
|
111
|
+
return;
|
|
112
|
+
// `transaction.local === true` means this Y.Doc edit originated from
|
|
113
|
+
// our own client — the store mutation handler above has already noted
|
|
114
|
+
// the addition (as "remote" if the socket was open, "local" otherwise).
|
|
115
|
+
// `false` means the change came from the server / another peer, so it
|
|
116
|
+
// must be marked as confirmed here when we forward it to the store.
|
|
117
|
+
const isLocalTxn = events.transaction.local;
|
|
118
|
+
// Batch all per-key notes plus the trailing `update(...)` so we fire
|
|
119
|
+
// exactly one notification per Yjs transaction.
|
|
120
|
+
status.batch(() => {
|
|
121
|
+
isSyncing = true;
|
|
122
|
+
try {
|
|
123
|
+
for (const [key, change] of events.changes.keys) {
|
|
124
|
+
switch (change.action) {
|
|
125
|
+
case "add":
|
|
126
|
+
case "update": {
|
|
127
|
+
const value = shapesMap.get(key);
|
|
128
|
+
if (value) {
|
|
129
|
+
const shape = value;
|
|
130
|
+
const existing = store.getShape(key);
|
|
131
|
+
if (existing) {
|
|
132
|
+
store.updateShape(key, shape);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
store.addShape(shape);
|
|
136
|
+
if (!isLocalTxn) {
|
|
137
|
+
// Remote add → confirmed by server.
|
|
138
|
+
status.noteShapeAdded(key, "remote");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
case "delete": {
|
|
145
|
+
if (store.getShape(key)) {
|
|
146
|
+
store.deleteShape(key);
|
|
147
|
+
}
|
|
148
|
+
status.noteShapeRemoved(key);
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
isSyncing = false;
|
|
156
|
+
}
|
|
157
|
+
status.update({ shapeCount: shapesMap.size, lastSyncedAt: Date.now() });
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
shapesMap.observe(shapesObserver);
|
|
161
|
+
// ── Initial load: existing Y.Doc → store (pre-connection, e.g. from a persisted doc) ──
|
|
162
|
+
function applyInitialLoad() {
|
|
163
|
+
if (shapesMap.size === 0)
|
|
164
|
+
return;
|
|
165
|
+
const idsNeedingZIndex = [];
|
|
166
|
+
const loadedIds = [];
|
|
167
|
+
isSyncing = true;
|
|
168
|
+
try {
|
|
169
|
+
for (const [id, value] of shapesMap.entries()) {
|
|
170
|
+
const shape = value;
|
|
171
|
+
if (!store.getShape(id)) {
|
|
172
|
+
store.addShape(shape);
|
|
173
|
+
}
|
|
174
|
+
// Track legacy shapes that were persisted before z-order was introduced.
|
|
175
|
+
if (typeof shape.zIndex !== "string") {
|
|
176
|
+
idsNeedingZIndex.push(id);
|
|
177
|
+
}
|
|
178
|
+
loadedIds.push(id);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
isSyncing = false;
|
|
183
|
+
}
|
|
184
|
+
// Pre-connection load (typically from IndexedDB). These haven't been
|
|
185
|
+
// confirmed by the current server session yet — they'll be promoted to
|
|
186
|
+
// "confirmed" by `setConfirmedFromServer` when the first sync event
|
|
187
|
+
// fires. Use the bulk API so initial-load shapes don't trigger O(n²)
|
|
188
|
+
// recompute cycles.
|
|
189
|
+
if (loadedIds.length > 0) {
|
|
190
|
+
status.noteShapesLoaded(loadedIds, "local");
|
|
191
|
+
}
|
|
192
|
+
// Backfill zIndex into Y.Map for any shape that got an auto-assigned one,
|
|
193
|
+
// so other clients observe the same stable z-order on subsequent loads.
|
|
194
|
+
if (idsNeedingZIndex.length > 0) {
|
|
195
|
+
doc.transact(() => {
|
|
196
|
+
for (const id of idsNeedingZIndex) {
|
|
197
|
+
const current = store.getShape(id);
|
|
198
|
+
if (current)
|
|
199
|
+
shapesMap.set(id, toPlainObject(current));
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
// `noteShapesLoaded(...)` above already recomputed `shapeCount` and
|
|
204
|
+
// notified once for the batch, so no follow-up `update({ shapeCount })`
|
|
205
|
+
// is needed here.
|
|
206
|
+
}
|
|
207
|
+
applyInitialLoad();
|
|
208
|
+
// ── Idle timer ─────────────────────────────────────────────────────────────
|
|
209
|
+
let idleTimer = null;
|
|
210
|
+
function clearIdleTimer() {
|
|
211
|
+
if (idleTimer) {
|
|
212
|
+
clearTimeout(idleTimer);
|
|
213
|
+
idleTimer = null;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function resetIdleTimer() {
|
|
217
|
+
if (idleTimeoutMs <= 0 || destroyed)
|
|
218
|
+
return;
|
|
219
|
+
clearIdleTimer();
|
|
220
|
+
idleTimer = setTimeout(() => {
|
|
221
|
+
disconnect({ reason: "idle" });
|
|
222
|
+
}, idleTimeoutMs);
|
|
223
|
+
}
|
|
224
|
+
// ── Provider lifecycle ─────────────────────────────────────────────────────
|
|
225
|
+
let whenSyncedResolve = null;
|
|
226
|
+
const whenSynced = new Promise((resolve) => {
|
|
227
|
+
whenSyncedResolve = resolve;
|
|
228
|
+
});
|
|
229
|
+
let firstSyncSettled = false;
|
|
230
|
+
function settleFirstSync() {
|
|
231
|
+
if (firstSyncSettled)
|
|
232
|
+
return;
|
|
233
|
+
firstSyncSettled = true;
|
|
234
|
+
whenSyncedResolve?.();
|
|
235
|
+
}
|
|
236
|
+
async function connect() {
|
|
237
|
+
if (destroyed || paused || currentState)
|
|
238
|
+
return;
|
|
239
|
+
const myGeneration = ++connectGeneration;
|
|
240
|
+
status.update({ state: "connecting" });
|
|
241
|
+
let connParams = {};
|
|
242
|
+
if (resolveParams) {
|
|
243
|
+
try {
|
|
244
|
+
const ctx = {
|
|
245
|
+
attempt,
|
|
246
|
+
previousCloseCode: lastCloseCode,
|
|
247
|
+
previousCloseReason: lastCloseReason,
|
|
248
|
+
};
|
|
249
|
+
const resolved = await resolveParams(ctx);
|
|
250
|
+
// After await: bail out if disconnect/destroy happened or a newer
|
|
251
|
+
// connect() superseded this run.
|
|
252
|
+
if (destroyed || paused || myGeneration !== connectGeneration)
|
|
253
|
+
return;
|
|
254
|
+
connParams = resolved.params ?? {};
|
|
255
|
+
}
|
|
256
|
+
catch (err) {
|
|
257
|
+
if (destroyed || paused || myGeneration !== connectGeneration)
|
|
258
|
+
return;
|
|
259
|
+
status.update({
|
|
260
|
+
state: "error",
|
|
261
|
+
error: err instanceof Error ? err.message : String(err),
|
|
262
|
+
});
|
|
263
|
+
// Unblock `whenSynced` so plugin setup can proceed — consumers should
|
|
264
|
+
// inspect `status.getSnapshot()` to detect the persistent failure state.
|
|
265
|
+
settleFirstSync();
|
|
266
|
+
scheduleReconnect();
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (destroyed || paused || myGeneration !== connectGeneration)
|
|
271
|
+
return;
|
|
272
|
+
const provider = new WebsocketProvider(url, roomName, doc, {
|
|
273
|
+
connect: true,
|
|
274
|
+
params: connParams,
|
|
275
|
+
awareness: sharedAwareness,
|
|
276
|
+
WebSocketPolyfill: WebSocketPolyfill,
|
|
277
|
+
resyncInterval: 0,
|
|
278
|
+
});
|
|
279
|
+
const onStatus = (event) => {
|
|
280
|
+
if (event.status === "connected") {
|
|
281
|
+
attempt = 0;
|
|
282
|
+
lastCloseCode = undefined;
|
|
283
|
+
lastCloseReason = undefined;
|
|
284
|
+
notifyStatus("connected");
|
|
285
|
+
resetIdleTimer();
|
|
286
|
+
}
|
|
287
|
+
else if (event.status === "connecting") {
|
|
288
|
+
notifyStatus("connecting");
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
notifyStatus("disconnected");
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
const onSync = (isSynced) => {
|
|
295
|
+
if (isSynced) {
|
|
296
|
+
// At this moment `shapesMap` reflects the merged server state
|
|
297
|
+
// (server's view ∪ what we uploaded). Treat every key here as
|
|
298
|
+
// confirmed. Anything added afterward without a subsequent
|
|
299
|
+
// sync event will diverge.
|
|
300
|
+
status.setConfirmedFromServer(shapesMap.keys());
|
|
301
|
+
status.update({
|
|
302
|
+
state: "synced",
|
|
303
|
+
shapeCount: shapesMap.size,
|
|
304
|
+
lastSyncedAt: Date.now(),
|
|
305
|
+
});
|
|
306
|
+
settleFirstSync();
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
const onConnectionClose = (event) => {
|
|
310
|
+
const code = event?.code ?? 0;
|
|
311
|
+
const reason = event?.reason ?? "";
|
|
312
|
+
lastCloseCode = code;
|
|
313
|
+
lastCloseReason = reason;
|
|
314
|
+
const decision = onCloseCode?.(code, reason);
|
|
315
|
+
if (decision === "stop") {
|
|
316
|
+
tearDownProvider();
|
|
317
|
+
notifyStatus("disconnected");
|
|
318
|
+
settleFirstSync();
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
// "retry" or undefined → fall through to reconnect
|
|
322
|
+
tearDownProvider();
|
|
323
|
+
if (decision === "retry") {
|
|
324
|
+
// Explicit retry reconnects immediately, so reset the backoff counter
|
|
325
|
+
// (this also resets `ctx.attempt` — see ResolveParamsContext.attempt docstring).
|
|
326
|
+
attempt = 0;
|
|
327
|
+
void connect();
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
scheduleReconnect();
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
const onConnectionError = () => {
|
|
334
|
+
// y-websocket emits connection-error before close; we rely on close for reconnect.
|
|
335
|
+
};
|
|
336
|
+
provider.on("status", onStatus);
|
|
337
|
+
provider.on("sync", onSync);
|
|
338
|
+
provider.on("connection-close", onConnectionClose);
|
|
339
|
+
provider.on("connection-error", onConnectionError);
|
|
340
|
+
currentState = {
|
|
341
|
+
provider,
|
|
342
|
+
unbind: () => {
|
|
343
|
+
provider.off("status", onStatus);
|
|
344
|
+
provider.off("sync", onSync);
|
|
345
|
+
provider.off("connection-close", onConnectionClose);
|
|
346
|
+
provider.off("connection-error", onConnectionError);
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function tearDownProvider() {
|
|
351
|
+
if (!currentState)
|
|
352
|
+
return;
|
|
353
|
+
currentState.unbind();
|
|
354
|
+
try {
|
|
355
|
+
currentState.provider.disconnect();
|
|
356
|
+
}
|
|
357
|
+
catch {
|
|
358
|
+
// ignore
|
|
359
|
+
}
|
|
360
|
+
try {
|
|
361
|
+
// `destroy` cleans up the socket but keeps the awareness instance that we've
|
|
362
|
+
// captured. We reattach to a fresh one on reconnect via `sharedAwareness`.
|
|
363
|
+
currentState.provider.destroy();
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
// ignore
|
|
367
|
+
}
|
|
368
|
+
currentState = null;
|
|
369
|
+
}
|
|
370
|
+
let reconnectTimer = null;
|
|
371
|
+
function scheduleReconnect() {
|
|
372
|
+
if (destroyed)
|
|
373
|
+
return;
|
|
374
|
+
if (reconnectTimer)
|
|
375
|
+
return;
|
|
376
|
+
attempt += 1;
|
|
377
|
+
// Exponential backoff with jitter, cap 30s
|
|
378
|
+
const base = Math.min(1000 * 2 ** Math.min(attempt, 6), 30000);
|
|
379
|
+
const delay = base + Math.random() * 1000;
|
|
380
|
+
reconnectTimer = setTimeout(() => {
|
|
381
|
+
reconnectTimer = null;
|
|
382
|
+
void connect();
|
|
383
|
+
}, delay);
|
|
384
|
+
}
|
|
385
|
+
function disconnect(_opts) {
|
|
386
|
+
// Pause + bump generation so any in-flight `connect()` (e.g. mid-await
|
|
387
|
+
// on resolveParams) aborts before it can create a provider.
|
|
388
|
+
paused = true;
|
|
389
|
+
connectGeneration += 1;
|
|
390
|
+
if (reconnectTimer) {
|
|
391
|
+
clearTimeout(reconnectTimer);
|
|
392
|
+
reconnectTimer = null;
|
|
393
|
+
}
|
|
394
|
+
clearIdleTimer();
|
|
395
|
+
tearDownProvider();
|
|
396
|
+
notifyStatus("disconnected");
|
|
397
|
+
}
|
|
398
|
+
function resume() {
|
|
399
|
+
if (destroyed)
|
|
400
|
+
return;
|
|
401
|
+
// Clear pause and any pending backoff so we don't get overlapping connects.
|
|
402
|
+
paused = false;
|
|
403
|
+
if (reconnectTimer) {
|
|
404
|
+
clearTimeout(reconnectTimer);
|
|
405
|
+
reconnectTimer = null;
|
|
406
|
+
}
|
|
407
|
+
resetIdleTimer();
|
|
408
|
+
if (currentState)
|
|
409
|
+
return;
|
|
410
|
+
attempt = 0;
|
|
411
|
+
void connect();
|
|
412
|
+
}
|
|
413
|
+
// ── WsProviderHandle adapter ───────────────────────────────────────────────
|
|
414
|
+
const wsProvider = {
|
|
415
|
+
get connected() {
|
|
416
|
+
return Boolean(currentState && (currentState.provider.wsconnected ?? false));
|
|
417
|
+
},
|
|
418
|
+
// Always bound to `doc` and reused across every WebsocketProvider — consumers
|
|
419
|
+
// (e.g. presence-cursor) can destructure at plugin-creation time without races.
|
|
420
|
+
awareness: sharedAwareness,
|
|
421
|
+
broadcast(_msg) {
|
|
422
|
+
// y-websocket has no broadcast channel separate from Y.Doc updates; no-op.
|
|
423
|
+
},
|
|
424
|
+
onBroadcast(handler) {
|
|
425
|
+
broadcastListeners.add(handler);
|
|
426
|
+
return () => broadcastListeners.delete(handler);
|
|
427
|
+
},
|
|
428
|
+
onStatusChange(handler) {
|
|
429
|
+
statusListeners.add(handler);
|
|
430
|
+
// Fire current state immediately for parity with createWsProvider behavior.
|
|
431
|
+
// Use the status tracker so pre-provider connection attempts (e.g. while
|
|
432
|
+
// awaiting `resolveParams`) correctly report `"connecting"` instead of
|
|
433
|
+
// `"disconnected"`.
|
|
434
|
+
const snapshot = status.getSnapshot().state;
|
|
435
|
+
const initial = snapshot === "synced"
|
|
436
|
+
? "connected"
|
|
437
|
+
: snapshot === "connecting" || snapshot === "syncing"
|
|
438
|
+
? "connecting"
|
|
439
|
+
: snapshot === "error"
|
|
440
|
+
? "failed"
|
|
441
|
+
: "disconnected";
|
|
442
|
+
handler(initial);
|
|
443
|
+
return () => statusListeners.delete(handler);
|
|
444
|
+
},
|
|
445
|
+
requestPartition(_names) {
|
|
446
|
+
// y-websocket has no partition concept; no-op.
|
|
447
|
+
},
|
|
448
|
+
onPartitionMeta(_handler) {
|
|
449
|
+
return () => {
|
|
450
|
+
// no-op
|
|
451
|
+
};
|
|
452
|
+
},
|
|
453
|
+
destroy() {
|
|
454
|
+
destroy();
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
function destroy() {
|
|
458
|
+
if (destroyed)
|
|
459
|
+
return;
|
|
460
|
+
destroyed = true;
|
|
461
|
+
// Invalidate any in-flight `connect()` awaiting `resolveParams`.
|
|
462
|
+
connectGeneration += 1;
|
|
463
|
+
if (reconnectTimer) {
|
|
464
|
+
clearTimeout(reconnectTimer);
|
|
465
|
+
reconnectTimer = null;
|
|
466
|
+
}
|
|
467
|
+
clearIdleTimer();
|
|
468
|
+
tearDownProvider();
|
|
469
|
+
shapesMap.unobserve(shapesObserver);
|
|
470
|
+
unsubMutation();
|
|
471
|
+
statusListeners.clear();
|
|
472
|
+
broadcastListeners.clear();
|
|
473
|
+
sharedAwareness.destroy();
|
|
474
|
+
if (ownsDoc) {
|
|
475
|
+
doc.destroy();
|
|
476
|
+
}
|
|
477
|
+
settleFirstSync();
|
|
478
|
+
}
|
|
479
|
+
if (autoConnect) {
|
|
480
|
+
void connect();
|
|
481
|
+
}
|
|
482
|
+
return {
|
|
483
|
+
doc,
|
|
484
|
+
status,
|
|
485
|
+
whenSynced,
|
|
486
|
+
wsProvider,
|
|
487
|
+
disconnect: () => disconnect({ reason: "manual" }),
|
|
488
|
+
resume,
|
|
489
|
+
destroy,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
//# sourceMappingURL=yws-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yws-sync.js","sourceRoot":"","sources":["../src/yws-sync.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7D,SAAS,aAAa,CAAC,KAAgB;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1C,CAAC;AAOD,MAAM,UAAU,oBAAoB,CACnC,KAAiB,EACjB,OAA8B;IAE9B,MAAM,EACL,GAAG,EACH,QAAQ,EACR,YAAY,GAAG,QAAQ,EACvB,aAAa,EACb,WAAW,EACX,aAAa,GAAG,CAAC,EACjB,WAAW,GAAG,IAAI,EAClB,GAAG,EAAE,WAAW,EAChB,iBAAiB,GACjB,GAAG,OAAO,CAAC;IAEZ,MAAM,GAAG,GAAG,WAAW,IAAI,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC;IACvC,MAAM,OAAO,GAAG,WAAW,KAAK,SAAS,CAAC;IAC1C,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAA0B,YAAY,CAAC,CAAC;IACpE,MAAM,MAAM,GAAG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;QACpC,aAAa,EAAE,CAAC;QAChB,eAAe,CAAC,KAAK,EAAE,CAAC;QACxB,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAC3B,eAAe,CAAC,OAAO,EAAE,CAAC;QAC1B,IAAI,OAAO,EAAE,CAAC;YACb,GAAG,CAAC,OAAO,EAAE,CAAC;QACf,CAAC;QACD,eAAe,EAAE,CAAC;IACnB,CAAC;IAED,IAAI,WAAW,EAAE,CAAC;QACjB,KAAK,OAAO,EAAE,CAAC;IAChB,CAAC;IAED,OAAO;QACN,GAAG;QACH,MAAM;QACN,UAAU;QACV,UAAU;QACV,UAAU,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;QAClD,MAAM;QACN,OAAO;KACP,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@edv4h/usketch-plugin-sync-ywebsocket",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.ts",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"y-protocols": "1.0.7",
|
|
16
|
+
"y-websocket": "^3.0.0",
|
|
17
|
+
"yjs": "^13.6.0",
|
|
18
|
+
"@edv4h/usketch-shared": "2.0.0",
|
|
19
|
+
"@edv4h/usketch-sync": "1.0.0"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": ">=19"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/react": "19.2.14",
|
|
26
|
+
"typescript": "5.9.3",
|
|
27
|
+
"vitest": "3.2.4"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/EdV4H/usketch.git",
|
|
40
|
+
"directory": "plugins/usketch-plugin-sync-ywebsocket"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/EdV4H/usketch#readme",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/EdV4H/usketch/issues"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsc -p tsconfig.json",
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"test": "vitest run --passWithNoTests",
|
|
50
|
+
"clean": "rm -rf dist"
|
|
51
|
+
}
|
|
52
|
+
}
|