@@ -38,16 +38,26 @@ export class RejectUnauthorized implements Extension {
38
38
// Read the hocuspocusMessageType
39
39
const hocuspocusMessageType = incomingMessage . readVarUint ( ) ;
40
40
// If the hocuspocusMessageType is not Sync, we don't handle the message, since it is not an update
41
- if ( hocuspocusMessageType !== MessageType . Sync ) {
41
+ if (
42
+ ! (
43
+ hocuspocusMessageType === MessageType . Sync ||
44
+ hocuspocusMessageType === MessageType . SyncReply
45
+ )
46
+ ) {
42
47
return ;
43
48
}
44
49
45
50
// Read the ySyncMessageType
46
51
const ySyncMessageType = incomingMessage . readVarUint ( ) ;
47
52
48
- // If the ySyncMessageType is not messageYjsUpdate, we don't handle the message, since it is not an update
49
- if ( ySyncMessageType !== syncProtocol . messageYjsUpdate ) {
50
- // not an update
53
+ // If the ySyncMessageType is not a messageYjsUpdate or a messageYjsSyncStep2, we don't handle the message, since it is not an update
54
+ if (
55
+ ! (
56
+ ySyncMessageType === syncProtocol . messageYjsUpdate ||
57
+ ySyncMessageType === syncProtocol . messageYjsSyncStep2
58
+ )
59
+ ) {
60
+ // not an update we want to handle
51
61
return ;
52
62
}
53
63
@@ -72,7 +82,7 @@ export class RejectUnauthorized implements Extension {
72
82
* @param restrictedType The type that we want to protect
73
83
* @returns true if the update was rejected, false otherwise
74
84
*/
75
- private rollbackUpdateIfNeeded (
85
+ private applyUpdateAndRollbackIfNeeded (
76
86
yUpdate : Uint8Array ,
77
87
ydoc : Y . Doc ,
78
88
restrictedType : Y . AbstractType < any >
@@ -113,13 +123,13 @@ export class RejectUnauthorized implements Extension {
113
123
}
114
124
115
125
const protectedType = ydoc . getMap ( this . threadsMapKey ) ;
116
- const didNeedToUndo = this . rollbackUpdateIfNeeded (
126
+ const didRollback = this . applyUpdateAndRollbackIfNeeded (
117
127
yUpdate ,
118
128
ydoc ,
119
129
protectedType
120
130
) ;
121
131
122
- if ( didNeedToUndo ) {
132
+ if ( didRollback ) {
123
133
// TODO, we can close their connection or just let them continue, since we've already undone their changes (and our changes are newer than theirs)
124
134
const error = {
125
135
reason : `Modification of a restricted type: ${ this . threadsMapKey } was rejected` ,
0 commit comments