Update events.md

This commit is contained in:
ThisDavidRichard 2024-03-11 15:41:37 +01:00 committed by GitHub
parent d6c641d1c5
commit 9630f17b71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,25 @@ tableOfContents: true
Events in Collaboration providers allow you to respond to various states and changes, such as successful connections or authentication updates. You can attach event listeners during the provider's initialization or add them later based on your application's needs.
## Key Events and their uses
| Event | Description |
| --- | --- |
| open | Triggered when the WebSocket connection is established. |
| connect | Occurs when the provider successfully connects to the server. |
| authenticated | Indicates successful client authentication. |
| authenticationFailed | Fires when client authentication fails. |
| status | Reflects changes in connection status. |
| message | Captures incoming messages. |
| outgoingMessage | Signals when a message is about to be sent. |
| synced | Marks the initial successful sync of the Y.js document. |
| close | Triggered when the WebSocket connection closes. |
| disconnect | Occurs upon provider disconnection. |
| destroy | Signifies the impending destruction of the provider. |
| awarenessUpdate | Tracks updates in user awareness information. |
| awarenessChange | Indicates changes in the awareness state. |
| stateless | When the stateless message was received. |
## Configuring Event Listeners
To ensure immediate event tracking, you can pass event listeners directly to the provider's constructor. This method guarantees that listeners are active from the start.
@ -58,25 +77,6 @@ provider.on("message", onMessage);
provider.off("message", onMessage);
```
## Key Events and their uses
| Event | Description |
| --- | --- |
| open | Triggered when the WebSocket connection is established. |
| connect | Occurs when the provider successfully connects to the server. |
| authenticated | Indicates successful client authentication. |
| authenticationFailed | Fires when client authentication fails. |
| status | Reflects changes in connection status. |
| message | Captures incoming messages. |
| outgoingMessage | Signals when a message is about to be sent. |
| synced | Marks the initial successful sync of the Y.js document. |
| close | Triggered when the WebSocket connection closes. |
| disconnect | Occurs upon provider disconnection. |
| destroy | Signifies the impending destruction of the provider. |
| awarenessUpdate | Tracks updates in user awareness information. |
| awarenessChange | Indicates changes in the awareness state. |
| stateless | When the stateless message was received. |
## Use cases for event handling
### Real-time Connection Status