@hardlydifficult/websocket 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ ws.send({ type: "hello" }); // sends as JSON
|
|
|
39
39
|
### Constructor Options
|
|
40
40
|
|
|
41
41
|
| Option | Type | Default | Description |
|
|
42
|
-
|
|
42
|
+
|---|---|---|---|
|
|
43
43
|
| `url` | `string` | — | WebSocket server URL |
|
|
44
44
|
| `backoff` | `BackoffOptions` | `{ initialDelayMs: 1000, maxDelayMs: 30000, multiplier: 2 }` | Reconnection backoff config |
|
|
45
45
|
| `heartbeat` | `HeartbeatOptions` | `{ intervalMs: 30000, timeoutMs: 10000 }` | Ping/pong monitoring |
|
|
@@ -101,7 +101,7 @@ ws.reconnect(); // fetches fresh token from auth
|
|
|
101
101
|
### Token Refresh Strategy
|
|
102
102
|
|
|
103
103
|
| Token lifetime | Refresh strategy | Example (60s token) | Example (5min token) |
|
|
104
|
-
|
|
104
|
+
|---|---|---|---|
|
|
105
105
|
| Short (≤4min) | 50% lifetime | 30s after issue | N/A |
|
|
106
106
|
| Long (>4min) | 2min before expiry | N/A | 3min after issue |
|
|
107
107
|
|
|
@@ -141,4 +141,22 @@ if (tracker.tryAccept()) {
|
|
|
141
141
|
|
|
142
142
|
// On shutdown signal
|
|
143
143
|
tracker.startDraining("Server shutdown");
|
|
144
|
-
```
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Public API Reference
|
|
147
|
+
|
|
148
|
+
### Exports
|
|
149
|
+
|
|
150
|
+
- `ReconnectingWebSocket<T>`: Auto-reconnecting WebSocket client class
|
|
151
|
+
- `RequestTracker`: Request tracking class for graceful shutdown
|
|
152
|
+
- `calculateTokenRefreshTime(issuedAt: number, expiresAt: number): number`: Calculate refresh time
|
|
153
|
+
- `getBackoffDelay(attempt: number, options: Required<BackoffOptions>): number`: Calculate exponential backoff delay
|
|
154
|
+
- `AuthOptions`: Type for auth configuration
|
|
155
|
+
- `BackoffOptions`: Type for backoff configuration
|
|
156
|
+
- `HeartbeatOptions`: Type for heartbeat configuration
|
|
157
|
+
- `WebSocketOptions<T>`: Type for WebSocket client options
|
|
158
|
+
|
|
159
|
+
### Types
|
|
160
|
+
|
|
161
|
+
- `WebSocketEvents<T>`: Event callback types for `ReconnectingWebSocket`
|
|
162
|
+
- `RequestTrackerEvents`: Event callback types for `RequestTracker`
|