mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add missing pong reply in docs (#20765)
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
5
.changeset/yellow-bulldogs-impress.md
Normal file
5
.changeset/yellow-bulldogs-impress.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"docs": patch
|
||||
---
|
||||
|
||||
Added info about pong reply to WebSocket ping event
|
||||
@@ -97,3 +97,4 @@
|
||||
- u5r0
|
||||
- wasimTQ
|
||||
- omahs
|
||||
- codeit-ninja
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user