@abraca/dabra 0.1.4 → 0.1.5
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 +1 -1
- package/src/AbracadabraProvider.ts +25 -4
package/package.json
CHANGED
|
@@ -312,7 +312,8 @@ export class AbracadabraProvider extends HocuspocusProvider {
|
|
|
312
312
|
|
|
313
313
|
/**
|
|
314
314
|
* Create (or return cached) a child AbracadabraProvider for a given
|
|
315
|
-
* child document id.
|
|
315
|
+
* child document id. Each child opens its own WebSocket connection because
|
|
316
|
+
* the server is document-scoped (one WebSocket ↔ one document).
|
|
316
317
|
*/
|
|
317
318
|
async loadChild(childId: string): Promise<AbracadabraProvider> {
|
|
318
319
|
if (this.childProviders.has(childId)) {
|
|
@@ -321,12 +322,31 @@ export class AbracadabraProvider extends HocuspocusProvider {
|
|
|
321
322
|
|
|
322
323
|
const childDoc = new Y.Doc({ guid: childId });
|
|
323
324
|
|
|
324
|
-
|
|
325
|
+
// Notify the server that this child belongs to the parent document and
|
|
326
|
+
// wait for server confirmation before opening the child WebSocket.
|
|
327
|
+
// Without waiting, the child's SyncStep1 may race against subdoc
|
|
328
|
+
// creation and get a NotFound error on first sync.
|
|
329
|
+
await new Promise<void>((resolve) => {
|
|
330
|
+
const onRegistered = ({ childId: cid }: onSubdocRegisteredParameters) => {
|
|
331
|
+
if (cid === childId) {
|
|
332
|
+
this.off("subdocRegistered", onRegistered);
|
|
333
|
+
resolve();
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
this.on("subdocRegistered", onRegistered);
|
|
337
|
+
this.registerSubdoc(childDoc);
|
|
338
|
+
// Fallback: don't block forever if the server is slow or the
|
|
339
|
+
// doc was already registered in a previous session.
|
|
340
|
+
setTimeout(resolve, 3000);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// Each child gets its own WebSocket connection. Omitting
|
|
344
|
+
// websocketProvider lets HocuspocusProvider create one automatically
|
|
345
|
+
// (manageSocket = true), so we do NOT call attach() manually.
|
|
325
346
|
const childProvider = new AbracadabraProvider({
|
|
326
347
|
name: childId,
|
|
327
348
|
document: childDoc,
|
|
328
|
-
url:
|
|
329
|
-
WebSocketPolyfill: parentWsp.configuration.WebSocketPolyfill,
|
|
349
|
+
url: this.abracadabraConfig.url,
|
|
330
350
|
token: this.configuration.token,
|
|
331
351
|
subdocLoading: this.subdocLoading,
|
|
332
352
|
disableOfflineStore: this.abracadabraConfig.disableOfflineStore,
|
|
@@ -334,6 +354,7 @@ export class AbracadabraProvider extends HocuspocusProvider {
|
|
|
334
354
|
cryptoIdentity: this.abracadabraConfig.cryptoIdentity,
|
|
335
355
|
signChallenge: this.abracadabraConfig.signChallenge,
|
|
336
356
|
});
|
|
357
|
+
|
|
337
358
|
this.childProviders.set(childId, childProvider);
|
|
338
359
|
|
|
339
360
|
this.emit("subdocLoaded", { childId, provider: childProvider });
|