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/components/transport-types/websocket-transport.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -158,6 +158,23 @@ The heartbeat interval is controlled by the `WS_HEARTBEAT_INTERVAL_MS` adapter s
158
158
159
159
**Note:** The heartbeat only starts if the `heartbeat` handler is provided. If you don't need heartbeat functionality, simply omit the `heartbeat` handler.
160
160
161
+
### Pong handler (optional)
162
+
163
+
When using WebSocket protocol-level pings (via `connection.ping()`), the server will respond with a `pong` frame. The `pong` handler lets you react to those responses — for example, to track latency, log liveness confirmations, or reset a timeout.
164
+
165
+
```typescript
166
+
handlers: {
167
+
heartbeat: (connection) => {
168
+
connection.ping()
169
+
},
170
+
pong: (connection, data) => {
171
+
logger.debug('Received pong from server', { data: data.toString() })
172
+
},
173
+
}
174
+
```
175
+
176
+
The `pong` handler receives the WebSocket connection and a `Buffer` containing any data the server included in the pong frame. It is optional — if omitted, pong frames are silently ignored.
177
+
161
178
### Retrieving and storing the response or errors
162
179
163
180
As shown in the first example, the **handlers** object accepts a function called **message** which will be executed when Data Provider sends a message through the WS connection. It takes this message as its first argument and the adapter context as the second, and should build and return a list of response objects (_ProviderResult_) that will be stored in the response cache for the endpoint.
0 commit comments