@camera.ui/transport 0.0.22 → 0.0.23
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.
|
@@ -8,7 +8,9 @@ export interface DegradedRecoveryOptions {
|
|
|
8
8
|
readonly ensureAll: () => void;
|
|
9
9
|
readonly probe: () => Promise<BackgroundProbeOutcome>;
|
|
10
10
|
readonly graceMs?: number;
|
|
11
|
+
readonly isReachable?: () => boolean;
|
|
11
12
|
readonly onEscalate?: (round: number) => void;
|
|
12
13
|
readonly onOffline?: (reason: string) => void;
|
|
14
|
+
readonly onHold?: (reason: string) => void;
|
|
13
15
|
}
|
|
14
16
|
export declare function attachDegradedRecovery(options: DegradedRecoveryOptions): Detach;
|
|
@@ -6,5 +6,6 @@ export interface NetworkChangeOptions {
|
|
|
6
6
|
readonly kernel: Kernel;
|
|
7
7
|
readonly source: NetworkChangeSource;
|
|
8
8
|
readonly onChange: (kernel: Kernel, event: Event) => void;
|
|
9
|
+
readonly debounceMs?: number;
|
|
9
10
|
}
|
|
10
11
|
export declare function attachNetworkChange(options: NetworkChangeOptions): Detach;
|
package/dist/index.js
CHANGED
|
@@ -495,6 +495,11 @@ function attachDegradedRecovery(options) {
|
|
|
495
495
|
const outcome = await options.probe();
|
|
496
496
|
if (detached || options.signal.current.kind !== "degraded") return;
|
|
497
497
|
if (outcome === "failed") {
|
|
498
|
+
if (options.isReachable?.()) {
|
|
499
|
+
options.onHold?.("probe failed but a channel is up — holding");
|
|
500
|
+
arm();
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
498
503
|
options.onOffline?.("degraded: endpoint unreachable");
|
|
499
504
|
options.kernel.dispatch({
|
|
500
505
|
type: "PROBE_FAILED_ALL",
|
|
@@ -518,14 +523,28 @@ function attachDegradedRecovery(options) {
|
|
|
518
523
|
//#endregion
|
|
519
524
|
//#region src/effects/networkChange.ts
|
|
520
525
|
function attachNetworkChange(options) {
|
|
526
|
+
const debounceMs = options.debounceMs ?? 0;
|
|
521
527
|
let detached = false;
|
|
528
|
+
let timer = null;
|
|
522
529
|
const handler = (event) => {
|
|
523
530
|
if (detached) return;
|
|
524
|
-
|
|
531
|
+
if (debounceMs <= 0) {
|
|
532
|
+
options.onChange(options.kernel, event);
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
if (timer !== null) clearTimeout(timer);
|
|
536
|
+
timer = setTimeout(() => {
|
|
537
|
+
timer = null;
|
|
538
|
+
if (!detached) options.onChange(options.kernel, event);
|
|
539
|
+
}, debounceMs);
|
|
525
540
|
};
|
|
526
541
|
options.source.addEventListener("change", handler);
|
|
527
542
|
return () => {
|
|
528
543
|
detached = true;
|
|
544
|
+
if (timer !== null) {
|
|
545
|
+
clearTimeout(timer);
|
|
546
|
+
timer = null;
|
|
547
|
+
}
|
|
529
548
|
options.source.removeEventListener("change", handler);
|
|
530
549
|
};
|
|
531
550
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camera.ui/transport",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "camera.ui transport layer — framework-agnostic connection kernel, reducer state, pluggable transports (HTTP/WS/Socket.IO/NATS), lifecycle effects and worker bridge",
|
|
5
5
|
"author": "seydx (https://github.com/cameraui/clients)",
|
|
6
6
|
"type": "module",
|