Skip to content

Commit

Permalink
add documentation on how to handle read-only users
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Mar 31, 2022
1 parent e48bd03 commit 33d2207
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,15 @@ function readMessage (buffer) {

```

### Handling read-only users

Yjs itself doesn't distinguish between read-only and read-write users. However, you can enforce that no modifying operations are accepted by the server/peer if the client doesn't have write-access.

It suffices to read the first two bytes in order to determine whether a message should be accepted from a read-only user.

* `[0, 0, ..]` is a SyncStep1. It is request to receive the missing state (it contains a state-vector that the server uses to compute the missing updates)
* `[0, 1, ..]` is SyncStep2, which is the reply to a SyncStep1. It contains the missing updates. You want to ignore this message as it contains document updates.
* `[0, 2, ..]` is a regular document update message.
* `[1, ..]` Awareness message. This information is only used to represent shared cursors and the name of each user. However, with enough malice intention you could assign other users temporarily false identities.

It suffices to block messages that start with `[0, 1, ..]` or `[0, 2, ..]`. Optionally, awareness can be disabled by blocking `[1, ..]`.

0 comments on commit 33d2207

Please sign in to comment.