Add missing pong reply in docs (#20765)

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
Code IT
2023-12-18 13:37:48 +01:00
committed by GitHub
parent 71032776f9
commit 083a95d52d
3 changed files with 23 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"docs": patch
---
Added info about pong reply to WebSocket ping event

View File

@@ -97,3 +97,4 @@
- u5r0
- wasimTQ
- omahs
- codeit-ninja

View File

@@ -183,6 +183,23 @@ You may have noticed that, periodically, you will receive a message with a type
application technology stack.
2. To verify that the connection is still active.
In order to prevent the connection from _closing_, you may reply with a `pong` event:
```js
// Exemplary code
connection.addEventListener('message', (message) => {
const data = JSON.parse(message.data);
if (data.type === 'ping') {
this.connection.send(
JSON.stringify({
type: 'pong',
}),
);
}
});
```
On Directus Cloud, this feature is enabled. If you are self-hosting, you can alter this behavior with the
`WEBSOCKETS_HEARTBEAT_ENABLED` and `WEBSOCKETS_HEARTBEAT_PERIOD` environment variables.