You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/server/hooks.md
+31-2Lines changed: 31 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,6 @@ By way of illustration, if a user isn’t allowed to connect: Just throw an erro
49
49
|`beforeBroadcastStateless`| Before broadcast a stateless message |[Read more](/server/hooks#before-broadcast-stateless)|
50
50
|`afterUnloadDocument`| When a document is closed |[Read more](/server/hooks#after-unload-document)|
51
51
52
-
53
52
## Usage
54
53
55
54
```js
@@ -759,7 +758,6 @@ const server = new Server({
759
758
server.listen();
760
759
```
761
760
762
-
763
761
### onStateless
764
762
765
763
The `onStateless` hooks are called after the server has received a stateless message. It should return a Promise.
@@ -796,6 +794,37 @@ const server = new Server({
796
794
server.listen()
797
795
```
798
796
797
+
### beforeSync
798
+
799
+
The `beforeSync` hooks are called before a sync message is handled. This is useful if you want to inspect the sync message that will be applied to the document.
800
+
801
+
**Hook payload**
802
+
803
+
```js
804
+
constdata= {
805
+
documentName: string,
806
+
document:Document,
807
+
// The y-protocols/sync message type
808
+
type: number,
809
+
// The payload of the y-protocols/sync message
810
+
payload:Uint8Array,
811
+
}
812
+
```
813
+
814
+
**Example**
815
+
816
+
```js
817
+
import { Server } from'@hocuspocus/server'
818
+
819
+
constserver=newServer({
820
+
asyncbeforeSync({ payload, document, documentName, type }) {
821
+
console.log(`Server will handle a sync message: "${payload}"!`)
822
+
},
823
+
})
824
+
825
+
server.listen()
826
+
```
827
+
799
828
### beforeBroadcastStateless
800
829
801
830
The `beforeBroadcastStateless` hooks are called before the server broadcast a stateless message.
0 commit comments