@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.
@@ -1620,9 +1620,14 @@ class MessageReceiver {
1620
1620
  // Apply update
1621
1621
  const syncMessageType = readSyncMessage(message.decoder, message.encoder, provider.document, provider);
1622
1622
  // Synced once we receive Step2
1623
- if (emitSynced && syncMessageType === messageYjsSyncStep2) {
1623
+ if (emitSynced && (syncMessageType === messageYjsSyncStep2)) {
1624
1624
  provider.synced = true;
1625
1625
  }
1626
+ if (syncMessageType === messageYjsUpdate || syncMessageType === messageYjsSyncStep2) {
1627
+ if (provider.unsyncedChanges > 0) {
1628
+ provider.unsyncedChanges -= 1;
1629
+ }
1630
+ }
1626
1631
  }
1627
1632
  applyAwarenessMessage(provider) {
1628
1633
  const { message } = this;
@@ -1808,6 +1813,7 @@ class HocuspocusProvider extends EventEmitter {
1808
1813
  this.shouldConnect = true;
1809
1814
  this.status = exports.WebSocketStatus.Disconnected;
1810
1815
  this.isSynced = false;
1816
+ this.unsyncedChanges = 0;
1811
1817
  this.isAuthenticated = false;
1812
1818
  this.lastMessageReceived = 0;
1813
1819
  this.mux = createMutex();
@@ -1864,6 +1870,7 @@ class HocuspocusProvider extends EventEmitter {
1864
1870
  if (this.status === exports.WebSocketStatus.Connected) {
1865
1871
  return;
1866
1872
  }
1873
+ this.unsyncedChanges = 0; // set to 0 in case we got reconnected
1867
1874
  this.shouldConnect = true;
1868
1875
  this.subscribeToBroadcastChannel();
1869
1876
  try {
@@ -1936,6 +1943,9 @@ class HocuspocusProvider extends EventEmitter {
1936
1943
  get awareness() {
1937
1944
  return this.configuration.awareness;
1938
1945
  }
1946
+ get hasUnsyncedChanges() {
1947
+ return this.unsyncedChanges > 0;
1948
+ }
1939
1949
  checkConnection() {
1940
1950
  var _a;
1941
1951
  // Don’t check the connection when it’s not even established
@@ -1974,6 +1984,7 @@ class HocuspocusProvider extends EventEmitter {
1974
1984
  if (origin === this) {
1975
1985
  return;
1976
1986
  }
1987
+ this.unsyncedChanges += 1;
1977
1988
  this.send(UpdateMessage, { update }, true);
1978
1989
  }
1979
1990
  awarenessUpdateHandler({ added, updated, removed }, origin) {