@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.
@@ -110,6 +110,7 @@ export declare class HocuspocusProvider extends EventEmitter {
110
110
  shouldConnect: boolean;
111
111
  status: WebSocketStatus;
112
112
  isSynced: boolean;
113
+ unsyncedChanges: number;
113
114
  isAuthenticated: boolean;
114
115
  lastMessageReceived: number;
115
116
  mux: mutex.mutex;
@@ -128,6 +129,7 @@ export declare class HocuspocusProvider extends EventEmitter {
128
129
  rejectConnectionAttempt(): void;
129
130
  get document(): Y.Doc;
130
131
  get awareness(): Awareness;
132
+ get hasUnsyncedChanges(): boolean;
131
133
  checkConnection(): void;
132
134
  forceSync(): void;
133
135
  boundBeforeUnload: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hocuspocus/provider",
3
- "version": "1.0.0-alpha.37",
3
+ "version": "1.0.0-alpha.38",
4
4
  "description": "hocuspocus provider",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
@@ -34,5 +34,5 @@
34
34
  "y-protocols": "^1.0.5",
35
35
  "yjs": "^13.5.29"
36
36
  },
37
- "gitHead": "af278e7c5d91c74afefd9234379c8179c8b91e6d"
37
+ "gitHead": "fe784d26fb1b281ab6d0bc7b5fca500be3b62684"
38
38
  }
@@ -182,6 +182,8 @@ export class HocuspocusProvider extends EventEmitter {
182
182
 
183
183
  isSynced = false
184
184
 
185
+ unsyncedChanges = 0
186
+
185
187
  isAuthenticated = false
186
188
 
187
189
  lastMessageReceived = 0
@@ -266,6 +268,7 @@ export class HocuspocusProvider extends EventEmitter {
266
268
  return
267
269
  }
268
270
 
271
+ this.unsyncedChanges = 0 // set to 0 in case we got reconnected
269
272
  this.shouldConnect = true
270
273
  this.subscribeToBroadcastChannel()
271
274
 
@@ -346,6 +349,10 @@ export class HocuspocusProvider extends EventEmitter {
346
349
  return this.configuration.awareness
347
350
  }
348
351
 
352
+ get hasUnsyncedChanges() {
353
+ return this.unsyncedChanges > 0
354
+ }
355
+
349
356
  checkConnection() {
350
357
  // Don’t check the connection when it’s not even established
351
358
  if (this.status !== WebSocketStatus.Connected) {
@@ -395,6 +402,7 @@ export class HocuspocusProvider extends EventEmitter {
395
402
  return
396
403
  }
397
404
 
405
+ this.unsyncedChanges += 1
398
406
  this.send(UpdateMessage, { update }, true)
399
407
  }
400
408
 
@@ -1,5 +1,5 @@
1
1
  import * as awarenessProtocol from 'y-protocols/awareness'
2
- import { readSyncMessage, messageYjsSyncStep2 } from 'y-protocols/sync'
2
+ import { readSyncMessage, messageYjsSyncStep2, messageYjsUpdate } from 'y-protocols/sync'
3
3
  import { readAuthMessage } from '@hocuspocus/common'
4
4
  import { MessageType } from './types'
5
5
  import { HocuspocusProvider } from './HocuspocusProvider'
@@ -75,9 +75,15 @@ export class MessageReceiver {
75
75
  )
76
76
 
77
77
  // Synced once we receive Step2
78
- if (emitSynced && syncMessageType === messageYjsSyncStep2) {
78
+ if (emitSynced && (syncMessageType === messageYjsSyncStep2)) {
79
79
  provider.synced = true
80
80
  }
81
+
82
+ if (syncMessageType === messageYjsUpdate || syncMessageType === messageYjsSyncStep2) {
83
+ if (provider.unsyncedChanges > 0) {
84
+ provider.unsyncedChanges -= 1
85
+ }
86
+ }
81
87
  }
82
88
 
83
89
  private applyAwarenessMessage(provider: HocuspocusProvider) {