lspeasy / client/src / ConnectionHealthTracker
Class: ConnectionHealthTracker
Defined in: packages/client/src/connection/health.ts:35
Tracks connection state transitions and message activity timestamps.
Remarks
ConnectionHealthTracker is created internally by LSPClient and exposed via client.connectionHealth. Subscribe to stateChanged and healthChanged events to react to disconnections or transport failures.
Use When
You need to monitor connection liveness — for example, to show a status indicator, trigger reconnection logic, or surface transport errors to users.
See
HeartbeatMonitor for detecting silent transport failures with periodic ping/pong checks.
Never
NEVER mutate the object returned by getHealth() — it is a defensive copy but consumers that store a reference and then modify it will see stale state.
NEVER call setState from outside LSPClient internals. External callers have no knowledge of the full state-transition graph; setting state directly can desync the client's internal bookkeeping from the tracker's reported state.
Extends
Transport<HealthEventMap>
Constructors
Constructor
new ConnectionHealthTracker(): ConnectionHealthTracker;Returns
ConnectionHealthTracker
Inherited from
DisposableEventEmitter<HealthEventMap>.constructorMethods
getHealth()
getHealth(): ConnectionHealth;Defined in: packages/client/src/connection/health.ts:48
Returns a defensive copy of the current health snapshot.
Returns
A shallow copy of the current ConnectionHealth object, including a nested copy of heartbeat when present.
markMessageReceived()
markMessageReceived(): void;Defined in: packages/client/src/connection/health.ts:107
Records inbound message activity.
Returns
void
markMessageSent()
markMessageSent(): void;Defined in: packages/client/src/connection/health.ts:96
Records outbound message activity.
Returns
void
onHealthChange()
onHealthChange(handler): () => void;Defined in: packages/client/src/connection/health.ts:157
Subscribes to health snapshot updates.
Parameters
| Parameter | Type | Description |
|---|---|---|
handler | (health) => void | Callback invoked with the latest ConnectionHealth snapshot after any state or activity change. |
Returns
An unsubscribe function — call it to remove the listener.
() => void
onStateChange()
onStateChange(handler): () => void;Defined in: packages/client/src/connection/health.ts:145
Subscribes to connection state transitions.
Parameters
| Parameter | Type | Description |
|---|---|---|
handler | (event) => void | Callback invoked with a StateChangeEvent each time the connection state changes. |
Returns
An unsubscribe function — call it to remove the listener.
() => void
setHeartbeat()
setHeartbeat(status): void;Defined in: packages/client/src/connection/health.ts:130
Updates the heartbeat subsection of the current health snapshot.
Parameters
| Parameter | Type |
|---|---|
status | HeartbeatStatus |
Returns
void
setState()
setState(next, reason?): void;Defined in: packages/client/src/connection/health.ts:73
Updates connection state and emits state/health change events.
Parameters
| Parameter | Type | Description |
|---|---|---|
next | ConnectionState | The new ConnectionState to transition to. |
reason? | string | Optional human-readable reason for the state transition (e.g. 'Transport error'). Included in the emitted StateChangeEvent. |
Returns
void
See
- ConnectionState for valid state values.
- ConnectionHealthTracker for the full class contract.