@@ -38,16 +38,26 @@ export class RejectUnauthorized implements Extension {
3838 // Read the hocuspocusMessageType
3939 const hocuspocusMessageType = incomingMessage . readVarUint ( ) ;
4040 // 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+ ) {
4247 return ;
4348 }
4449
4550 // Read the ySyncMessageType
4651 const ySyncMessageType = incomingMessage . readVarUint ( ) ;
4752
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
5161 return ;
5262 }
5363
@@ -72,7 +82,7 @@ export class RejectUnauthorized implements Extension {
7282 * @param restrictedType The type that we want to protect
7383 * @returns true if the update was rejected, false otherwise
7484 */
75- private rollbackUpdateIfNeeded (
85+ private applyUpdateAndRollbackIfNeeded (
7686 yUpdate : Uint8Array ,
7787 ydoc : Y . Doc ,
7888 restrictedType : Y . AbstractType < any >
@@ -113,13 +123,13 @@ export class RejectUnauthorized implements Extension {
113123 }
114124
115125 const protectedType = ydoc . getMap ( this . threadsMapKey ) ;
116- const didNeedToUndo = this . rollbackUpdateIfNeeded (
126+ const didRollback = this . applyUpdateAndRollbackIfNeeded (
117127 yUpdate ,
118128 ydoc ,
119129 protectedType
120130 ) ;
121131
122- if ( didNeedToUndo ) {
132+ if ( didRollback ) {
123133 // 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)
124134 const error = {
125135 reason : `Modification of a restricted type: ${ this . threadsMapKey } was rejected` ,
0 commit comments