heartbeat( )
Checks if a delegated provider or the local SDK worker is responsive.
function heartbeat(params?: { delegate?: DelegateBase }): Promise<HeartbeatResponse>;Sends a heartbeat round-trip to verify that a delegated provider is online or that the local SDK worker is responsive. When called without arguments, checks the local worker.
Parameters
| Name | Type | Required? | Description |
|---|---|---|---|
| params | object | ✗ | Optional delegation target |
| params.delegate | DelegateBase | ✗ | The provider to check — omit to check the local worker |
DelegateBase
Consumers connect directly to the provider via the DHT using providerPublicKey — no topic or discovery step is required.
| Field | Type | Required? | Description |
|---|---|---|---|
| providerPublicKey | string | ✓ | Provider peer public key hex string (from startQVACProvider) |
| timeout | number | ✗ | Connection timeout in milliseconds (min 100). On a cold DHT the first connect can take 15–45s. |
| healthCheckTimeout | number | ✗ | Health check timeout in milliseconds (min 100) |
Returns
Promise<HeartbeatResponse>
HeartbeatResponse
| Field | Type | Description |
|---|---|---|
| type | "heartbeat" | Response type discriminator |
| number | number | Round-trip sequence number |
Throws
| Error | When |
|---|---|
INVALID_RESPONSE_TYPE | Response type does not match expected "heartbeat" |
Examples
// Check if a delegated provider is online
try {
await heartbeat({
delegate: { providerPublicKey: "peerHex", timeout: 3000 },
});
console.log("Provider is online");
} catch {
console.log("Provider is offline");
}
// Check if the local SDK worker is responsive
await heartbeat();