@abraca/dabra 0.1.7 → 0.2.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.
@@ -1351,10 +1351,15 @@ var HocuspocusProviderWebsocket = class extends EventEmitter {
1351
1351
  if (this.connectionAttempt) this.rejectConnectionAttempt();
1352
1352
  this.status = WebSocketStatus.Disconnected;
1353
1353
  this.emit("status", { status: WebSocketStatus.Disconnected });
1354
+ const isRateLimited = event?.code === 4429;
1354
1355
  this.emit("disconnect", { event });
1355
- if (!this.cancelWebsocketRetry && this.shouldConnect) setTimeout(() => {
1356
- this.connect();
1357
- }, this.configuration.delay);
1356
+ if (isRateLimited) this.emit("rateLimited");
1357
+ if (!this.cancelWebsocketRetry && this.shouldConnect) {
1358
+ const delay = isRateLimited ? 6e4 : this.configuration.delay;
1359
+ setTimeout(() => {
1360
+ this.connect();
1361
+ }, delay);
1362
+ }
1358
1363
  }
1359
1364
  destroy() {
1360
1365
  this.emit("destroy");
@@ -1677,6 +1682,7 @@ var HocuspocusProvider = class extends EventEmitter {
1677
1682
  forceSyncInterval: false,
1678
1683
  onAuthenticated: () => null,
1679
1684
  onAuthenticationFailed: () => null,
1685
+ onRateLimited: () => null,
1680
1686
  onOpen: () => null,
1681
1687
  onConnect: () => null,
1682
1688
  onMessage: () => null,
@@ -1708,6 +1714,7 @@ var HocuspocusProvider = class extends EventEmitter {
1708
1714
  this.forwardClose = (e) => this.emit("close", e);
1709
1715
  this.forwardDisconnect = (e) => this.emit("disconnect", e);
1710
1716
  this.forwardDestroy = () => this.emit("destroy");
1717
+ this.forwardRateLimited = () => this.emit("rateLimited");
1711
1718
  this.setConfiguration(configuration);
1712
1719
  this.configuration.document = configuration.document ? configuration.document : new Y.Doc();
1713
1720
  this.configuration.awareness = configuration.awareness !== void 0 ? configuration.awareness : new Awareness(this.document);
@@ -1722,6 +1729,7 @@ var HocuspocusProvider = class extends EventEmitter {
1722
1729
  this.on("unsyncedChanges", this.configuration.onUnsyncedChanges);
1723
1730
  this.on("authenticated", this.configuration.onAuthenticated);
1724
1731
  this.on("authenticationFailed", this.configuration.onAuthenticationFailed);
1732
+ this.on("rateLimited", this.configuration.onRateLimited);
1725
1733
  this.awareness?.on("update", () => {
1726
1734
  this.emit("awarenessUpdate", { states: awarenessStatesToArray(this.awareness.getStates()) });
1727
1735
  });
@@ -1914,6 +1922,7 @@ var HocuspocusProvider = class extends EventEmitter {
1914
1922
  this.configuration.websocketProvider.off("disconnect", this.forwardDisconnect);
1915
1923
  this.configuration.websocketProvider.off("destroy", this.configuration.onDestroy);
1916
1924
  this.configuration.websocketProvider.off("destroy", this.forwardDestroy);
1925
+ this.configuration.websocketProvider.off("rateLimited", this.forwardRateLimited);
1917
1926
  this.configuration.websocketProvider.detach(this);
1918
1927
  this._isAttached = false;
1919
1928
  }
@@ -1931,6 +1940,7 @@ var HocuspocusProvider = class extends EventEmitter {
1931
1940
  this.configuration.websocketProvider.on("disconnect", this.forwardDisconnect);
1932
1941
  this.configuration.websocketProvider.on("destroy", this.configuration.onDestroy);
1933
1942
  this.configuration.websocketProvider.on("destroy", this.forwardDestroy);
1943
+ this.configuration.websocketProvider.on("rateLimited", this.forwardRateLimited);
1934
1944
  this.configuration.websocketProvider.attach(this);
1935
1945
  this._isAttached = true;
1936
1946
  }
@@ -2253,9 +2263,9 @@ var AbracadabraProvider = class AbracadabraProvider extends HocuspocusProvider {
2253
2263
  * child document id. Each child opens its own WebSocket connection because
2254
2264
  * the server is document-scoped (one WebSocket ↔ one document).
2255
2265
  */
2256
- async loadChild(childId) {
2257
- if (!isValidDocId(childId)) throw new Error(`loadChild: "${childId}" is not a valid document ID (must be a UUID). If this node was created with an older version of the app, delete it and recreate it.`);
2258
- if (this.childProviders.has(childId)) return this.childProviders.get(childId);
2266
+ loadChild(childId) {
2267
+ if (!isValidDocId(childId)) return Promise.reject(/* @__PURE__ */ new Error(`loadChild: "${childId}" is not a valid document ID (must be a UUID). If this node was created with an older version of the app, delete it and recreate it.`));
2268
+ if (this.childProviders.has(childId)) return Promise.resolve(this.childProviders.get(childId));
2259
2269
  if (this.pendingLoads.has(childId)) return this.pendingLoads.get(childId);
2260
2270
  const load = this._doLoadChild(childId);
2261
2271
  this.pendingLoads.set(childId, load);