react-realtime-hooks 1.4.3 → 2.0.0
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 +10 -4
- package/dist/index.cjs +7 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.d.cts
CHANGED
|
@@ -76,6 +76,11 @@ interface ReconnectDelayContext {
|
|
|
76
76
|
type ReconnectDelayStrategy = (context: ReconnectDelayContext) => number;
|
|
77
77
|
interface UseReconnectOptions {
|
|
78
78
|
enabled?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Maximum number of reconnect attempts before the hook gives up and
|
|
81
|
+
* transitions to `"stopped"`. Default is `10` (changed from `null` in
|
|
82
|
+
* 2.0). Pass `null` explicitly to retry indefinitely.
|
|
83
|
+
*/
|
|
79
84
|
maxAttempts?: number | null;
|
|
80
85
|
initialDelayMs?: number;
|
|
81
86
|
maxDelayMs?: number;
|
|
@@ -107,7 +112,12 @@ type HeartbeatAckMatcher<TMessage> = (message: TMessage) => boolean;
|
|
|
107
112
|
interface UseHeartbeatOptions<TOutgoing = unknown, TIncoming = TOutgoing> {
|
|
108
113
|
enabled?: boolean;
|
|
109
114
|
intervalMs: number;
|
|
110
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Time to wait for an ack after a beat before flipping `hasTimedOut` to
|
|
117
|
+
* `true`. Default is `10_000` (10 seconds), changed from no default in
|
|
118
|
+
* 2.0. Pass `null` explicitly to disable the timeout entirely.
|
|
119
|
+
*/
|
|
120
|
+
timeoutMs?: number | null;
|
|
111
121
|
message?: TOutgoing | (() => TOutgoing);
|
|
112
122
|
beat?: HeartbeatBeatFn;
|
|
113
123
|
matchesAck?: HeartbeatAckMatcher<TIncoming>;
|
package/dist/index.d.ts
CHANGED
|
@@ -76,6 +76,11 @@ interface ReconnectDelayContext {
|
|
|
76
76
|
type ReconnectDelayStrategy = (context: ReconnectDelayContext) => number;
|
|
77
77
|
interface UseReconnectOptions {
|
|
78
78
|
enabled?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Maximum number of reconnect attempts before the hook gives up and
|
|
81
|
+
* transitions to `"stopped"`. Default is `10` (changed from `null` in
|
|
82
|
+
* 2.0). Pass `null` explicitly to retry indefinitely.
|
|
83
|
+
*/
|
|
79
84
|
maxAttempts?: number | null;
|
|
80
85
|
initialDelayMs?: number;
|
|
81
86
|
maxDelayMs?: number;
|
|
@@ -107,7 +112,12 @@ type HeartbeatAckMatcher<TMessage> = (message: TMessage) => boolean;
|
|
|
107
112
|
interface UseHeartbeatOptions<TOutgoing = unknown, TIncoming = TOutgoing> {
|
|
108
113
|
enabled?: boolean;
|
|
109
114
|
intervalMs: number;
|
|
110
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Time to wait for an ack after a beat before flipping `hasTimedOut` to
|
|
117
|
+
* `true`. Default is `10_000` (10 seconds), changed from no default in
|
|
118
|
+
* 2.0. Pass `null` explicitly to disable the timeout entirely.
|
|
119
|
+
*/
|
|
120
|
+
timeoutMs?: number | null;
|
|
111
121
|
message?: TOutgoing | (() => TOutgoing);
|
|
112
122
|
beat?: HeartbeatBeatFn;
|
|
113
123
|
matchesAck?: HeartbeatAckMatcher<TIncoming>;
|
package/dist/index.js
CHANGED
|
@@ -313,6 +313,7 @@ var DEFAULT_RECONNECT_OPTIONS = {
|
|
|
313
313
|
enabled: true,
|
|
314
314
|
initialDelayMs: 1e3,
|
|
315
315
|
jitterRatio: 0.2,
|
|
316
|
+
maxAttempts: 10,
|
|
316
317
|
maxDelayMs: 3e4,
|
|
317
318
|
resetOnSuccess: true
|
|
318
319
|
};
|
|
@@ -364,7 +365,7 @@ var normalizeReconnectOptions = (options) => {
|
|
|
364
365
|
jitterRatio: sanitizeJitterRatio(
|
|
365
366
|
options?.jitterRatio ?? DEFAULT_RECONNECT_OPTIONS.jitterRatio
|
|
366
367
|
),
|
|
367
|
-
maxAttempts: sanitizeMaxAttempts(options
|
|
368
|
+
maxAttempts: options?.maxAttempts === void 0 ? DEFAULT_RECONNECT_OPTIONS.maxAttempts : sanitizeMaxAttempts(options.maxAttempts),
|
|
368
369
|
maxDelayMs,
|
|
369
370
|
resetOnSuccess: options?.resetOnSuccess ?? DEFAULT_RECONNECT_OPTIONS.resetOnSuccess
|
|
370
371
|
};
|
|
@@ -582,6 +583,7 @@ var useReconnect = (options = {}) => {
|
|
|
582
583
|
status: state.status
|
|
583
584
|
};
|
|
584
585
|
};
|
|
586
|
+
var DEFAULT_HEARTBEAT_TIMEOUT_MS = 1e4;
|
|
585
587
|
var createInitialState2 = (isRunning) => ({
|
|
586
588
|
hasTimedOut: false,
|
|
587
589
|
isRunning,
|
|
@@ -615,13 +617,14 @@ var useHeartbeat = (options) => {
|
|
|
615
617
|
options.onTimeout?.();
|
|
616
618
|
});
|
|
617
619
|
const scheduleTimeout = useStableCallback(() => {
|
|
618
|
-
|
|
620
|
+
const timeoutMs = options.timeoutMs === void 0 ? DEFAULT_HEARTBEAT_TIMEOUT_MS : options.timeoutMs;
|
|
621
|
+
if (timeoutMs === null) {
|
|
619
622
|
timeoutRef.current.cancel();
|
|
620
623
|
return;
|
|
621
624
|
}
|
|
622
625
|
timeoutRef.current.schedule(() => {
|
|
623
626
|
handleTimeout();
|
|
624
|
-
},
|
|
627
|
+
}, timeoutMs);
|
|
625
628
|
});
|
|
626
629
|
const handleBeatSuccess = useStableCallback((performedAt) => {
|
|
627
630
|
commitState((current) => ({
|
|
@@ -984,7 +987,7 @@ var useWebSocket = (options) => {
|
|
|
984
987
|
startOnMount: false
|
|
985
988
|
};
|
|
986
989
|
if (heartbeatConfig !== null && heartbeatConfig.timeoutMs !== void 0) {
|
|
987
|
-
heartbeatHookOptions.timeoutMs = heartbeatConfig.timeoutMs;
|
|
990
|
+
heartbeatHookOptions.timeoutMs = heartbeatConfig.timeoutMs ?? null;
|
|
988
991
|
}
|
|
989
992
|
if (heartbeatConfig !== null && heartbeatConfig.matchesAck !== void 0) {
|
|
990
993
|
heartbeatHookOptions.matchesAck = heartbeatConfig.matchesAck;
|