@hocuspocus/provider 2.2.3 → 2.3.1

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,11 +1,11 @@
1
- import * as awarenessProtocol from 'y-protocols/awareness'
2
- import { readSyncMessage, messageYjsSyncStep2, messageYjsUpdate } from 'y-protocols/sync'
3
1
  import { readAuthMessage } from '@hocuspocus/common'
4
- import { readVarString } from 'lib0/decoding'
5
- import { MessageType } from './types.js'
2
+ import { readVarInt, readVarString } from 'lib0/decoding'
3
+ import * as awarenessProtocol from 'y-protocols/awareness'
4
+ import { messageYjsSyncStep2, readSyncMessage } from 'y-protocols/sync'
6
5
  import { HocuspocusProvider } from './HocuspocusProvider.js'
7
6
  import { IncomingMessage } from './IncomingMessage.js'
8
7
  import { OutgoingMessage } from './OutgoingMessage.js'
8
+ import { MessageType } from './types.js'
9
9
 
10
10
  export class MessageReceiver {
11
11
 
@@ -23,7 +23,7 @@ export class MessageReceiver {
23
23
  return this
24
24
  }
25
25
 
26
- public apply(provider: HocuspocusProvider, emitSynced = true) {
26
+ public apply(provider: HocuspocusProvider, emitSynced: boolean) {
27
27
  const { message } = this
28
28
  const type = message.readVarUint()
29
29
 
@@ -51,9 +51,8 @@ export class MessageReceiver {
51
51
  break
52
52
 
53
53
  case MessageType.SyncStatus:
54
- // nothing for now; forward-compatability
54
+ this.applySyncStatusMessage(provider, readVarInt(message.decoder) === 1)
55
55
  break
56
-
57
56
  default:
58
57
  throw new Error(`Can’t apply message of unknown type: ${type}`)
59
58
  }
@@ -89,11 +88,11 @@ export class MessageReceiver {
89
88
  if (emitSynced && syncMessageType === messageYjsSyncStep2) {
90
89
  provider.synced = true
91
90
  }
91
+ }
92
92
 
93
- if (syncMessageType === messageYjsUpdate || syncMessageType === messageYjsSyncStep2) {
94
- if (provider.unsyncedChanges > 0) {
95
- provider.updateUnsyncedChanges(-1)
96
- }
93
+ applySyncStatusMessage(provider: HocuspocusProvider, applied: boolean) {
94
+ if (applied) {
95
+ provider.decrementUnsyncedChanges()
97
96
  }
98
97
  }
99
98
 
package/src/types.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { Encoder } from 'lib0/encoding'
2
- import type { CloseEvent, Event, MessageEvent } from 'ws'
2
+ import type { Event, MessageEvent } from 'ws'
3
3
  import { Awareness } from 'y-protocols/awareness'
4
4
  import * as Y from 'yjs'
5
+ import { CloseEvent } from '@hocuspocus/common'
5
6
  import { IncomingMessage } from './IncomingMessage.js'
6
7
  import { OutgoingMessage } from './OutgoingMessage.js'
7
8
  import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.js'