@hocuspocus/provider 1.0.0-alpha.37 → 1.0.0-alpha.38

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.
@@ -1596,9 +1596,14 @@ class MessageReceiver {
1596
1596
  // Apply update
1597
1597
  const syncMessageType = readSyncMessage(message.decoder, message.encoder, provider.document, provider);
1598
1598
  // Synced once we receive Step2
1599
- if (emitSynced && syncMessageType === messageYjsSyncStep2) {
1599
+ if (emitSynced && (syncMessageType === messageYjsSyncStep2)) {
1600
1600
  provider.synced = true;
1601
1601
  }
1602
+ if (syncMessageType === messageYjsUpdate || syncMessageType === messageYjsSyncStep2) {
1603
+ if (provider.unsyncedChanges > 0) {
1604
+ provider.unsyncedChanges -= 1;
1605
+ }
1606
+ }
1602
1607
  }
1603
1608
  applyAwarenessMessage(provider) {
1604
1609
  const { message } = this;
@@ -1784,6 +1789,7 @@ class HocuspocusProvider extends EventEmitter {
1784
1789
  this.shouldConnect = true;
1785
1790
  this.status = WebSocketStatus.Disconnected;
1786
1791
  this.isSynced = false;
1792
+ this.unsyncedChanges = 0;
1787
1793
  this.isAuthenticated = false;
1788
1794
  this.lastMessageReceived = 0;
1789
1795
  this.mux = createMutex();
@@ -1840,6 +1846,7 @@ class HocuspocusProvider extends EventEmitter {
1840
1846
  if (this.status === WebSocketStatus.Connected) {
1841
1847
  return;
1842
1848
  }
1849
+ this.unsyncedChanges = 0; // set to 0 in case we got reconnected
1843
1850
  this.shouldConnect = true;
1844
1851
  this.subscribeToBroadcastChannel();
1845
1852
  try {
@@ -1912,6 +1919,9 @@ class HocuspocusProvider extends EventEmitter {
1912
1919
  get awareness() {
1913
1920
  return this.configuration.awareness;
1914
1921
  }
1922
+ get hasUnsyncedChanges() {
1923
+ return this.unsyncedChanges > 0;
1924
+ }
1915
1925
  checkConnection() {
1916
1926
  var _a;
1917
1927
  // Don’t check the connection when it’s not even established
@@ -1950,6 +1960,7 @@ class HocuspocusProvider extends EventEmitter {
1950
1960
  if (origin === this) {
1951
1961
  return;
1952
1962
  }
1963
+ this.unsyncedChanges += 1;
1953
1964
  this.send(UpdateMessage, { update }, true);
1954
1965
  }
1955
1966
  awarenessUpdateHandler({ added, updated, removed }, origin) {