@hocuspocus/provider 2.0.2 → 2.0.4

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.
@@ -1,5 +1,5 @@
1
1
  import * as Y from 'yjs';
2
- import { readAuthMessage, writeAuthentication, WsReadyStates, Unauthorized, Forbidden, awarenessStatesToArray } from '@hocuspocus/common';
2
+ import { readAuthMessage, writeAuthentication, WsReadyStates, Unauthorized, Forbidden, MessageTooBig, awarenessStatesToArray } from '@hocuspocus/common';
3
3
  import { retry } from '@lifeomic/attempt';
4
4
 
5
5
  /**
@@ -1782,7 +1782,7 @@ class MessageReceiver {
1782
1782
  }
1783
1783
  if (syncMessageType === messageYjsUpdate || syncMessageType === messageYjsSyncStep2) {
1784
1784
  if (provider.unsyncedChanges > 0) {
1785
- provider.unsyncedChanges -= 1;
1785
+ provider.updateUnsyncedChanges(-1);
1786
1786
  }
1787
1787
  }
1788
1788
  }
@@ -2206,6 +2206,10 @@ class HocuspocusProviderWebsocket extends EventEmitter {
2206
2206
  return; // TODO REMOVE ME
2207
2207
  }
2208
2208
  }
2209
+ if (event.code === MessageTooBig.code) {
2210
+ console.warn(`[HocuspocusProvider] Connection closed with status MessageTooBig: ${event.reason}`);
2211
+ this.shouldConnect = false;
2212
+ }
2209
2213
  if (this.connectionAttempt) {
2210
2214
  // That connection attempt failed.
2211
2215
  this.rejectConnectionAttempt();
@@ -2379,6 +2383,10 @@ class HocuspocusProvider extends EventEmitter {
2379
2383
  get hasUnsyncedChanges() {
2380
2384
  return this.unsyncedChanges > 0;
2381
2385
  }
2386
+ updateUnsyncedChanges(unsyncedChanges = 0) {
2387
+ this.unsyncedChanges += unsyncedChanges;
2388
+ this.emit('unsyncedChanges', this.unsyncedChanges);
2389
+ }
2382
2390
  forceSync() {
2383
2391
  this.send(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name });
2384
2392
  }
@@ -2398,7 +2406,7 @@ class HocuspocusProvider extends EventEmitter {
2398
2406
  if (origin === this) {
2399
2407
  return;
2400
2408
  }
2401
- this.unsyncedChanges += 1;
2409
+ this.updateUnsyncedChanges(1);
2402
2410
  this.send(UpdateMessage, { update, documentName: this.configuration.name }, true);
2403
2411
  }
2404
2412
  awarenessUpdateHandler({ added, updated, removed }, origin) {
@@ -2416,6 +2424,9 @@ class HocuspocusProvider extends EventEmitter {
2416
2424
  if (this.isSynced === state) {
2417
2425
  return;
2418
2426
  }
2427
+ if (state && this.unsyncedChanges > 0) {
2428
+ this.updateUnsyncedChanges(-1 * this.unsyncedChanges);
2429
+ }
2419
2430
  this.isSynced = state;
2420
2431
  this.emit('synced', { state });
2421
2432
  this.emit('sync', { state });
@@ -2435,6 +2446,7 @@ class HocuspocusProvider extends EventEmitter {
2435
2446
  this.configuration.websocketProvider.detach(this);
2436
2447
  }
2437
2448
  async onOpen(event) {
2449
+ this.isAuthenticated = false;
2438
2450
  this.emit('open', { event });
2439
2451
  if (this.isAuthenticationRequired) {
2440
2452
  this.send(AuthenticationMessage, {
@@ -2567,17 +2579,23 @@ class HocuspocusProvider extends EventEmitter {
2567
2579
  }
2568
2580
  }
2569
2581
 
2582
+ class TiptapCollabProviderWebsocket extends HocuspocusProviderWebsocket {
2583
+ constructor(configuration) {
2584
+ super({ ...configuration, url: `wss://${configuration.appId}.collab.tiptap.cloud` });
2585
+ }
2586
+ }
2587
+
2570
2588
  class TiptapCollabProvider extends HocuspocusProvider {
2571
2589
  constructor(configuration) {
2572
2590
  if (!configuration.websocketProvider) {
2573
- configuration.websocketProvider = new HocuspocusProviderWebsocket({ url: `wss://${configuration.appId}.collab.tiptap.cloud` });
2591
+ configuration.websocketProvider = new TiptapCollabProviderWebsocket({ appId: configuration.appId });
2574
2592
  }
2575
2593
  if (!configuration.token) {
2576
- configuration.token = 'notoken';
2594
+ configuration.token = 'notoken'; // need to send a token anyway (which will be ignored)
2577
2595
  }
2578
2596
  super(configuration);
2579
2597
  }
2580
2598
  }
2581
2599
 
2582
- export { HocuspocusProvider, HocuspocusProviderWebsocket, MessageType, TiptapCollabProvider, WebSocketStatus };
2600
+ export { HocuspocusProvider, HocuspocusProviderWebsocket, MessageType, TiptapCollabProvider, TiptapCollabProviderWebsocket, WebSocketStatus };
2583
2601
  //# sourceMappingURL=hocuspocus-provider.esm.js.map