@owlmeans/client-socket 0.1.18-rc.4 → 0.1.18-rc.41
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 -15
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/client-socket/SKILL.md +173 -8
- package/build/consts.d.ts +7 -0
- package/build/consts.d.ts.map +1 -0
- package/build/consts.js +16 -0
- package/build/consts.js.map +1 -0
- package/build/helper.d.ts +27 -2
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +127 -30
- package/build/helper.js.map +1 -1
- package/build/index.d.ts +2 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/build/status.d.ts +31 -0
- package/build/status.d.ts.map +1 -0
- package/build/status.js +151 -0
- package/build/status.js.map +1 -0
- package/build/types.d.ts +75 -0
- package/build/types.d.ts.map +1 -1
- package/build/utils/connection.d.ts +40 -2
- package/build/utils/connection.d.ts.map +1 -1
- package/build/utils/connection.js +266 -28
- package/build/utils/connection.js.map +1 -1
- package/package.json +13 -10
- package/src/consts.ts +18 -0
- package/src/helper.ts +143 -31
- package/src/index.ts +2 -0
- package/src/status.ts +164 -0
- package/src/types.ts +84 -1
- package/src/utils/connection.ts +292 -32
- package/tests/context.ts +20 -0
- package/tests/reconnect.spec.ts +372 -0
- package/tests/tsconfig.json +12 -0
- package/tsconfig.json +1 -1
- package/build/.gitkeep +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,MAAM,EAAE,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,yBAAyB,EACvF,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,aAAa,kBAAkB,CAAA;AAI5C;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,WAAW,MAAM,KAAmB,mBA6DzE,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,OACxF,CAAC,UAAS,MAAM,KACpB,CAAC,GAAG,yBAON,CAAA;AAgCD;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAO,qBAWlC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,QAAO;IAAE,KAAK,EAAE,MAAM,IAAI,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAcvE,CAAA"}
|
package/build/status.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { createService } from '@owlmeans/context';
|
|
2
|
+
import { useContext } from '@owlmeans/client';
|
|
3
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
4
|
+
export const SOCKET_STATUS = 'socket-status';
|
|
5
|
+
const RANK = { online: 0, reconnecting: 1, lost: 2 };
|
|
6
|
+
/**
|
|
7
|
+
* Aggregates the coarse health of every `ws()`/`useWs()` connection an app has open into one
|
|
8
|
+
* worst-of-all state. A page with several sockets (thinking stream, file watch, notifications…)
|
|
9
|
+
* still shows one dialog, not one per socket — so the aggregate, not any single connection, is
|
|
10
|
+
* what a UI like `SocketReloadDialog` reads.
|
|
11
|
+
*/
|
|
12
|
+
export const createSocketStatusService = (alias = SOCKET_STATUS) => {
|
|
13
|
+
const states = new Map();
|
|
14
|
+
const revivers = new Map();
|
|
15
|
+
const listeners = new Set();
|
|
16
|
+
const retryListeners = new Set();
|
|
17
|
+
let current = 'online';
|
|
18
|
+
const recompute = () => {
|
|
19
|
+
let worst = 'online';
|
|
20
|
+
for (const state of states.values()) {
|
|
21
|
+
if (RANK[state] > RANK[worst])
|
|
22
|
+
worst = state;
|
|
23
|
+
}
|
|
24
|
+
if (worst !== current) {
|
|
25
|
+
current = worst;
|
|
26
|
+
listeners.forEach(listener => listener(current));
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
// Connections still retrying are nudged too, so one whose older budget is about to run out does
|
|
30
|
+
// not report `'lost'` right after its lost siblings were revived.
|
|
31
|
+
const retry = () => {
|
|
32
|
+
const pending = [...states].filter(([, state]) => state !== 'online');
|
|
33
|
+
pending.forEach(([id]) => revivers.get(id)?.());
|
|
34
|
+
if (!pending.some(([, state]) => state === 'lost'))
|
|
35
|
+
return false;
|
|
36
|
+
retryListeners.forEach(listener => listener());
|
|
37
|
+
return true;
|
|
38
|
+
};
|
|
39
|
+
// A backgrounded tab is where sockets die unnoticed (throttled timers, a sleeping machine), so
|
|
40
|
+
// the moment it is looked at again is the moment to retry — before anyone reaches for a button.
|
|
41
|
+
const watchActivation = () => {
|
|
42
|
+
if (typeof document === 'undefined' || typeof window === 'undefined')
|
|
43
|
+
return;
|
|
44
|
+
document.addEventListener('visibilitychange', () => {
|
|
45
|
+
if (document.visibilityState === 'visible')
|
|
46
|
+
retry();
|
|
47
|
+
});
|
|
48
|
+
window.addEventListener('focus', () => { retry(); });
|
|
49
|
+
window.addEventListener('online', () => { retry(); });
|
|
50
|
+
};
|
|
51
|
+
return createService(alias, {
|
|
52
|
+
report: (id, state, revive) => {
|
|
53
|
+
states.set(id, state);
|
|
54
|
+
if (revive != null)
|
|
55
|
+
revivers.set(id, revive);
|
|
56
|
+
else
|
|
57
|
+
revivers.delete(id);
|
|
58
|
+
recompute();
|
|
59
|
+
},
|
|
60
|
+
release: (id) => { states.delete(id); revivers.delete(id); recompute(); },
|
|
61
|
+
state: () => current,
|
|
62
|
+
subscribe: listener => {
|
|
63
|
+
listeners.add(listener);
|
|
64
|
+
return () => { listeners.delete(listener); };
|
|
65
|
+
},
|
|
66
|
+
retry,
|
|
67
|
+
onRetry: listener => {
|
|
68
|
+
retryListeners.add(listener);
|
|
69
|
+
return () => { retryListeners.delete(listener); };
|
|
70
|
+
},
|
|
71
|
+
}, service => async () => {
|
|
72
|
+
watchActivation();
|
|
73
|
+
service.initialized = true;
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Register the shared socket-status aggregator. Idempotent, and cheap enough for a host package
|
|
78
|
+
* (`@owlmeans/web-panel`) to call unconditionally on every context: every `ws()`/`useWs()`
|
|
79
|
+
* connection reports itself here if — and only if — the context carries this service, so an app
|
|
80
|
+
* that never calls this behaves exactly as it did before reconnect support existed.
|
|
81
|
+
*/
|
|
82
|
+
export const appendSocketStatus = (ctx, alias = SOCKET_STATUS) => {
|
|
83
|
+
const _ctx = ctx;
|
|
84
|
+
if (!ctx.hasService(alias)) {
|
|
85
|
+
ctx.registerService(createSocketStatusService(alias));
|
|
86
|
+
}
|
|
87
|
+
_ctx.socketStatus = () => ctx.service(alias);
|
|
88
|
+
return _ctx;
|
|
89
|
+
};
|
|
90
|
+
const readSocketStatusService = (ctx) => {
|
|
91
|
+
try {
|
|
92
|
+
return typeof ctx.hasService === 'function' && ctx.hasService(SOCKET_STATUS)
|
|
93
|
+
? ctx.socketStatus?.() ?? null : null;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// Registered but not yet run through the context's OWN `init()` — a component that renders
|
|
97
|
+
// as a sibling of the router (as `SocketReloadDialog` does) mounts before that finishes,
|
|
98
|
+
// since `context.configure().init()` runs from the router's effect, not before React's
|
|
99
|
+
// first commit. Treat it as "not ready yet" rather than crash the render.
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
/** The status service once the context can hand it out; `null` while it cannot, or never will. */
|
|
104
|
+
const useStatusService = () => {
|
|
105
|
+
const ctx = useContext();
|
|
106
|
+
const [service, setService] = useState(() => readSocketStatusService(ctx));
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (service != null)
|
|
109
|
+
return;
|
|
110
|
+
let cancelled = false;
|
|
111
|
+
void ctx.waitForInitialized?.().then(() => { if (!cancelled)
|
|
112
|
+
setService(readSocketStatusService(ctx)); });
|
|
113
|
+
return () => { cancelled = true; };
|
|
114
|
+
}, [ctx, service]);
|
|
115
|
+
return service;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* The worst state across every live `ws()`/`useWs()` connection, or `'online'` if the app never
|
|
119
|
+
* registered the status service (`appendSocketStatus`) or has not finished initializing yet.
|
|
120
|
+
*/
|
|
121
|
+
export const useSocketStatus = () => {
|
|
122
|
+
const service = useStatusService();
|
|
123
|
+
const [state, setState] = useState(() => service?.state() ?? 'online');
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
if (service == null)
|
|
126
|
+
return;
|
|
127
|
+
setState(service.state());
|
|
128
|
+
return service.subscribe(setState);
|
|
129
|
+
}, [service]);
|
|
130
|
+
return state;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* `retry` revives every lost connection now (`SocketStatusService.retry()`); `retrying` is true
|
|
134
|
+
* from any retry — this one, or the service's own on tab activation — until the aggregate settles
|
|
135
|
+
* back on `'online'` or `'lost'`.
|
|
136
|
+
*/
|
|
137
|
+
export const useSocketRetry = () => {
|
|
138
|
+
const service = useStatusService();
|
|
139
|
+
const [retrying, setRetrying] = useState(false);
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (service == null)
|
|
142
|
+
return;
|
|
143
|
+
const stopRetry = service.onRetry(() => setRetrying(service.state() === 'reconnecting'));
|
|
144
|
+
const stopState = service.subscribe(state => { if (state !== 'reconnecting')
|
|
145
|
+
setRetrying(false); });
|
|
146
|
+
return () => { stopRetry(); stopState(); };
|
|
147
|
+
}, [service]);
|
|
148
|
+
const retry = useCallback(() => { service?.retry(); }, [service]);
|
|
149
|
+
return { retry, retrying };
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,C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package/build/types.d.ts
CHANGED
|
@@ -1,7 +1,82 @@
|
|
|
1
1
|
import type { ClientConfig } from '@owlmeans/client-context';
|
|
2
2
|
import type { ClientContext } from '@owlmeans/client';
|
|
3
|
+
import type { AbstractRequest } from '@owlmeans/entrypoint';
|
|
4
|
+
import type { InitializedService } from '@owlmeans/context';
|
|
3
5
|
export interface Config extends ClientConfig {
|
|
6
|
+
socket?: SocketClientSettings;
|
|
4
7
|
}
|
|
5
8
|
export interface Context<C extends Config = Config> extends ClientContext<C> {
|
|
6
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* How aggressively a dropped socket is retried, and when the carrier gives up on it.
|
|
12
|
+
*
|
|
13
|
+
* The delay grows geometrically from `minDelay` to `maxDelay` (±`jitter`, a fraction of the
|
|
14
|
+
* computed delay) and stays there. `budget` is measured from the connection's FIRST failed
|
|
15
|
+
* attempt in an outage — a socket that opens and drops again right away does not get a fresh
|
|
16
|
+
* budget — and `stableAfter` is how long a reopened socket must stay up before the attempt
|
|
17
|
+
* counter and the outage clock reset, so a flapping link is never read as "recovered" between
|
|
18
|
+
* two drops a second apart.
|
|
19
|
+
*/
|
|
20
|
+
export interface ReconnectPolicy {
|
|
21
|
+
/** First retry delay, in ms. Default 200. */
|
|
22
|
+
minDelay: number;
|
|
23
|
+
/** Delay ceiling, in ms — the backoff never grows past this. Default 3000. */
|
|
24
|
+
maxDelay: number;
|
|
25
|
+
/** Geometric growth factor applied to the delay after every failed attempt. Default 2. */
|
|
26
|
+
factor: number;
|
|
27
|
+
/** Randomization applied to each computed delay, as a fraction of it. Default 0.1 (±10%). */
|
|
28
|
+
jitter: number;
|
|
29
|
+
/** Total time, in ms, the carrier keeps retrying before it reports the socket lost. Default
|
|
30
|
+
* 600000 (10 minutes). */
|
|
31
|
+
budget: number;
|
|
32
|
+
/** Retry window, in ms, of an outage restarted on a lost socket by `SocketStatusService.retry()`
|
|
33
|
+
* (a "Try again" press, the tab coming back) — short, so a retry that cannot succeed reports
|
|
34
|
+
* `'lost'` again while someone is still looking. Default 15000. */
|
|
35
|
+
reviveBudget: number;
|
|
36
|
+
/** How long a reopened socket must stay open before the attempt count and the outage clock
|
|
37
|
+
* reset, in ms. Default 10000. */
|
|
38
|
+
stableAfter: number;
|
|
39
|
+
/** Heartbeat ping interval, in ms. Default 30000. */
|
|
40
|
+
heartbeat: number;
|
|
41
|
+
/** How long to wait for ANY inbound frame after a ping before treating the socket as dead and
|
|
42
|
+
* forcing it closed, in ms. Default 10000. */
|
|
43
|
+
pongTimeout: number;
|
|
44
|
+
}
|
|
45
|
+
export interface SocketClientSettings {
|
|
46
|
+
/** `false` disables reconnection outright — a dropped socket is reported gone and stays gone,
|
|
47
|
+
* the pre-reconnect-support behaviour. Anything else merges over the defaults. */
|
|
48
|
+
reconnect?: false | Partial<ReconnectPolicy>;
|
|
49
|
+
}
|
|
50
|
+
export interface ConnectOptions {
|
|
51
|
+
reconnect?: false | Partial<ReconnectPolicy>;
|
|
52
|
+
}
|
|
53
|
+
export interface WsOptions extends ConnectOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Run before every connection attempt, the first one included, given the request that will be
|
|
56
|
+
* turned into the socket URL — where a caller refreshes a token or other query/param value
|
|
57
|
+
* that may have changed since the previous attempt.
|
|
58
|
+
*/
|
|
59
|
+
beforeConnect?: (request: AbstractRequest<any>) => void | Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
/** The coarse health of a socket connection — the worst of everything a status service tracks. */
|
|
62
|
+
export type SocketConnectionState = 'online' | 'reconnecting' | 'lost';
|
|
63
|
+
export interface SocketStatusService extends InitializedService {
|
|
64
|
+
/** Record this connection's current state under `id` — call again to update it. `revive` is
|
|
65
|
+
* how `retry()` brings it back (`'lost'`) or hurries it (`'reconnecting'`); every report
|
|
66
|
+
* replaces the previous one. */
|
|
67
|
+
report: (id: string, state: SocketConnectionState, revive?: () => void) => void;
|
|
68
|
+
/** Stop tracking `id` (the connection closed on purpose). */
|
|
69
|
+
release: (id: string) => void;
|
|
70
|
+
/** The worst state across every tracked connection; `'online'` when none are tracked. */
|
|
71
|
+
state: () => SocketConnectionState;
|
|
72
|
+
subscribe: (listener: (state: SocketConnectionState) => void) => () => void;
|
|
73
|
+
/** Revive every `'lost'` connection and hurry every `'reconnecting'` one, then tell `onRetry`
|
|
74
|
+
* listeners. `false` (and no listener call) when nothing was lost. Also fires by itself when a
|
|
75
|
+
* browser tab becomes visible, its window gains focus, or the network comes back online. */
|
|
76
|
+
retry: () => boolean;
|
|
77
|
+
onRetry: (listener: () => void) => () => void;
|
|
78
|
+
}
|
|
79
|
+
export interface SocketStatusServiceAppend {
|
|
80
|
+
socketStatus: () => SocketStatusService;
|
|
81
|
+
}
|
|
7
82
|
//# sourceMappingURL=types.d.ts.map
|
package/build/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAE3D,MAAM,WAAW,MAAO,SAAQ,YAAY;IAC1C,MAAM,CAAC,EAAE,oBAAoB,CAAA;CAC9B;AAED,MAAM,WAAW,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;CAAI;AAEhF;;;;;;;;;GASG;AACH,MAAM,WAAW,eAAe;IAC9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AAK,EAAE,qBAAqB,KAAK,IAAI,KAAK,MAAM,IAAI,CAAA;IAC3E;;iGAE6F;IAC7F,KAAK,EAAE,MAAM,OAAO,CAAA;IACpB,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAA;CAC9C;AAED,MAAM,WAAW,yBAAyB;IACxC,YAAY,EAAE,MAAM,mBAAmB,CAAA;CACxC"}
|
|
@@ -1,4 +1,42 @@
|
|
|
1
|
-
import type { Config, Context } from '../types.js';
|
|
2
1
|
import type { Connection } from '@owlmeans/socket';
|
|
3
|
-
|
|
2
|
+
import type { ReconnectPolicy, SocketConnectionState } from '../types.js';
|
|
3
|
+
export interface ConnectionOpener {
|
|
4
|
+
(): Promise<WebSocket>;
|
|
5
|
+
}
|
|
6
|
+
export interface ManagedConnectionOptions {
|
|
7
|
+
policy: ReconnectPolicy;
|
|
8
|
+
/** Whether a drop schedules a retry at all. `false` keeps the pre-reconnect-support
|
|
9
|
+
* behaviour — one attempt, report and stop — while the heartbeat/liveness check below still
|
|
10
|
+
* runs exactly as it always did. */
|
|
11
|
+
retry: boolean;
|
|
12
|
+
/** Opens a fresh socket for the first attempt and every retry — already reflecting whatever a
|
|
13
|
+
* caller's `beforeConnect` refreshed (a token, most often). Resolves once the socket is OPEN,
|
|
14
|
+
* rejects on a handshake failure. */
|
|
15
|
+
open: ConnectionOpener;
|
|
16
|
+
/** Told this connection's coarse health, if a caller wants to aggregate it — the status
|
|
17
|
+
* service `@owlmeans/web-panel`'s reload dialog reads. */
|
|
18
|
+
onStatus?: (state: SocketConnectionState) => void;
|
|
19
|
+
}
|
|
20
|
+
export interface ManagedConnection {
|
|
21
|
+
connection: Connection;
|
|
22
|
+
/** Settles once the first socket opens; rejects with `SocketConnectionError('lost')` once the
|
|
23
|
+
* retry budget elapses first (or the single attempt fails, with `retry: false`). */
|
|
24
|
+
ready: Promise<void>;
|
|
25
|
+
/** Restart retrying a connection that gave up after its budget: one attempt at once, then the
|
|
26
|
+
* usual backoff within `policy.reviveBudget`. On a connection still waiting out a backoff
|
|
27
|
+
* delay: attempt at once, and leave it at least `reviveBudget`. A no-op otherwise — a terminal
|
|
28
|
+
* close (client close, 1000/1008, `retry: false`) is never revived. */
|
|
29
|
+
revive: () => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Build a `Connection` whose transport survives a dropped WebSocket.
|
|
33
|
+
*
|
|
34
|
+
* The connection MODEL (`createBasicConnection()`) is created exactly once and never replaced —
|
|
35
|
+
* every `observe`/`listen` a caller registered keeps firing across a reconnect, because only the
|
|
36
|
+
* underlying `WebSocket` is swapped underneath it. A server's own subscriptions do NOT survive a
|
|
37
|
+
* new TCP connection, so a caller whose server sets up state only after an in-band
|
|
38
|
+
* `authenticated` frame (as this platform's handlers do) must replay that frame itself on
|
|
39
|
+
* `SocketSystemEvent.Reconnected` — this carrier only re-opens the pipe.
|
|
40
|
+
*/
|
|
41
|
+
export declare const makeConnection: (opts: ManagedConnectionOptions) => ManagedConnection;
|
|
4
42
|
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA4B,MAAM,kBAAkB,CAAA;AAM5E,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAQzE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,OAAO,CAAC,SAAS,CAAC,CAAA;CACvB;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,eAAe,CAAA;IACvB;;yCAEqC;IACrC,KAAK,EAAE,OAAO,CAAA;IACd;;0CAEsC;IACtC,IAAI,EAAE,gBAAgB,CAAA;IACtB;+DAC2D;IAC3D,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,CAAA;CAClD;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,UAAU,CAAA;IACtB;yFACqF;IACrF,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACpB;;;4EAGwE;IACxE,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,SAAU,wBAAwB,KAAG,iBAqQ/D,CAAA"}
|
|
@@ -1,19 +1,274 @@
|
|
|
1
|
-
import { createBasicConnection, MessageType } from '@owlmeans/socket';
|
|
2
|
-
|
|
1
|
+
import { createBasicConnection, MessageType, SocketConnectionError, SocketSystemEvent, SOCKET_HEARTBEAT_TIMEOUT_CODE } from '@owlmeans/socket';
|
|
2
|
+
import { AuthenticationStage } from '@owlmeans/auth';
|
|
3
|
+
/** Close codes that mean "this connection is finished on purpose" — never worth retrying: a
|
|
4
|
+
* normal closure the SERVER initiated (1000, e.g. the protocol's own one-shot completion) and a
|
|
5
|
+
* policy violation (1008, e.g. the guard rejected the frame that opened it). A client-initiated
|
|
6
|
+
* close is handled separately, through `closedByClient`. */
|
|
7
|
+
const TERMINAL_CLOSE_CODES = new Set([1000, 1008]);
|
|
8
|
+
/**
|
|
9
|
+
* Build a `Connection` whose transport survives a dropped WebSocket.
|
|
10
|
+
*
|
|
11
|
+
* The connection MODEL (`createBasicConnection()`) is created exactly once and never replaced —
|
|
12
|
+
* every `observe`/`listen` a caller registered keeps firing across a reconnect, because only the
|
|
13
|
+
* underlying `WebSocket` is swapped underneath it. A server's own subscriptions do NOT survive a
|
|
14
|
+
* new TCP connection, so a caller whose server sets up state only after an in-band
|
|
15
|
+
* `authenticated` frame (as this platform's handlers do) must replay that frame itself on
|
|
16
|
+
* `SocketSystemEvent.Reconnected` — this carrier only re-opens the pipe.
|
|
17
|
+
*/
|
|
18
|
+
export const makeConnection = (opts) => {
|
|
19
|
+
const { policy, retry, open, onStatus } = opts;
|
|
3
20
|
const model = createBasicConnection();
|
|
21
|
+
let current = null;
|
|
22
|
+
let closedByClient = false;
|
|
23
|
+
let finished = false;
|
|
24
|
+
// Gave up after the budget, but still revivable — unlike `finished`, nothing here is final.
|
|
25
|
+
let lost = false;
|
|
26
|
+
let attempts = 0;
|
|
27
|
+
let outageStartedAt = null;
|
|
28
|
+
let outageBudget = policy.budget;
|
|
29
|
+
let stableTimer = null;
|
|
30
|
+
let retryTimer = null;
|
|
31
|
+
let heartbeatTimer = null;
|
|
32
|
+
// When the ping still waiting for an answer was sent, or null once anything came back.
|
|
33
|
+
let pingSentAt = null;
|
|
34
|
+
let resolveReady = () => void 0;
|
|
35
|
+
let rejectReady = () => void 0;
|
|
36
|
+
const ready = new Promise((resolve, reject) => { resolveReady = resolve; rejectReady = reject; });
|
|
37
|
+
let settled = false;
|
|
38
|
+
const settle = (error) => {
|
|
39
|
+
if (settled)
|
|
40
|
+
return;
|
|
41
|
+
settled = true;
|
|
42
|
+
if (error != null)
|
|
43
|
+
rejectReady(error);
|
|
44
|
+
else
|
|
45
|
+
resolveReady();
|
|
46
|
+
};
|
|
47
|
+
const emitSystem = async (event, payload) => {
|
|
48
|
+
const msg = { type: MessageType.System, event, payload };
|
|
49
|
+
model.prepare?.(msg);
|
|
50
|
+
await Promise.all(model.getListeners().map(async (listener) => {
|
|
51
|
+
try {
|
|
52
|
+
await listener(msg);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error('Socket system listener error:', error);
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
};
|
|
59
|
+
const clearHeartbeat = () => {
|
|
60
|
+
if (heartbeatTimer != null) {
|
|
61
|
+
clearInterval(heartbeatTimer);
|
|
62
|
+
heartbeatTimer = null;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const clearTimers = () => {
|
|
66
|
+
if (retryTimer != null) {
|
|
67
|
+
clearTimeout(retryTimer);
|
|
68
|
+
retryTimer = null;
|
|
69
|
+
}
|
|
70
|
+
if (stableTimer != null) {
|
|
71
|
+
clearTimeout(stableTimer);
|
|
72
|
+
stableTimer = null;
|
|
73
|
+
}
|
|
74
|
+
clearHeartbeat();
|
|
75
|
+
};
|
|
76
|
+
const startHeartbeat = (socket) => {
|
|
77
|
+
pingSentAt = null;
|
|
78
|
+
heartbeatTimer = setInterval(() => {
|
|
79
|
+
if (socket.readyState !== WebSocket.OPEN)
|
|
80
|
+
return;
|
|
81
|
+
if (pingSentAt != null && Date.now() - pingSentAt > policy.pongTimeout) {
|
|
82
|
+
// Silent half-open TCP: the ping this socket owes an answer to went out long enough ago
|
|
83
|
+
// that any live peer would have replied — force the close its own stack would eventually
|
|
84
|
+
// notice on its own, minutes later.
|
|
85
|
+
socket.close(SOCKET_HEARTBEAT_TIMEOUT_CODE);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// Measured from the PING rather than from the last frame: a hidden tab's timers are
|
|
89
|
+
// throttled to about one wake-up a minute, so "nothing has arrived for longer than a
|
|
90
|
+
// heartbeat interval" is what throttling looks like, not what a dead socket looks like —
|
|
91
|
+
// it used to kill a perfectly healthy backgrounded connection on every wake-up.
|
|
92
|
+
pingSentAt = Date.now();
|
|
93
|
+
socket.send(JSON.stringify({ type: 'ping' }));
|
|
94
|
+
}, policy.heartbeat);
|
|
95
|
+
};
|
|
96
|
+
const computeDelay = (attempt) => {
|
|
97
|
+
const raw = Math.min(policy.maxDelay, policy.minDelay * Math.pow(policy.factor, attempt - 1));
|
|
98
|
+
const span = raw * policy.jitter;
|
|
99
|
+
const jittered = raw + (Math.random() * 2 - 1) * span;
|
|
100
|
+
return Math.max(policy.minDelay, Math.min(policy.maxDelay, Math.round(jittered)));
|
|
101
|
+
};
|
|
102
|
+
const finish = async (code) => {
|
|
103
|
+
if (finished)
|
|
104
|
+
return;
|
|
105
|
+
finished = true;
|
|
106
|
+
closedByClient = true;
|
|
107
|
+
clearTimers();
|
|
108
|
+
onStatus?.('lost');
|
|
109
|
+
await emitSystem(SocketSystemEvent.Close, { code });
|
|
110
|
+
settle(new SocketConnectionError('lost'));
|
|
111
|
+
};
|
|
112
|
+
// No `Close` frame here: the connection stays revivable, and `close` means gone for good.
|
|
113
|
+
const giveUp = async () => {
|
|
114
|
+
lost = true;
|
|
115
|
+
clearTimers();
|
|
116
|
+
onStatus?.('lost');
|
|
117
|
+
await emitSystem(SocketSystemEvent.Lost, {});
|
|
118
|
+
settle(new SocketConnectionError('lost'));
|
|
119
|
+
};
|
|
120
|
+
const scheduleReconnect = () => {
|
|
121
|
+
if (outageStartedAt == null)
|
|
122
|
+
outageStartedAt = Date.now();
|
|
123
|
+
if (Date.now() - outageStartedAt >= outageBudget) {
|
|
124
|
+
void giveUp();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
attempts += 1;
|
|
128
|
+
const delay = computeDelay(attempts);
|
|
129
|
+
onStatus?.('reconnecting');
|
|
130
|
+
void emitSystem(SocketSystemEvent.Reconnecting, { attempt: attempts, delay });
|
|
131
|
+
retryTimer = setTimeout(() => { retryTimer = null; void attemptConnect(); }, delay);
|
|
132
|
+
};
|
|
133
|
+
const attemptConnect = async () => {
|
|
134
|
+
if (closedByClient)
|
|
135
|
+
return;
|
|
136
|
+
let socket;
|
|
137
|
+
try {
|
|
138
|
+
socket = await open();
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
if (retry)
|
|
142
|
+
scheduleReconnect();
|
|
143
|
+
else
|
|
144
|
+
void finish(1006);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (closedByClient) {
|
|
148
|
+
// Closed while this handshake was in flight — nobody is left to own the socket.
|
|
149
|
+
socket.close(1000);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
onOpened(socket);
|
|
153
|
+
};
|
|
154
|
+
const revive = () => {
|
|
155
|
+
if (finished)
|
|
156
|
+
return;
|
|
157
|
+
if (lost) {
|
|
158
|
+
lost = false;
|
|
159
|
+
attempts = 1;
|
|
160
|
+
outageStartedAt = Date.now();
|
|
161
|
+
outageBudget = policy.reviveBudget;
|
|
162
|
+
onStatus?.('reconnecting');
|
|
163
|
+
void emitSystem(SocketSystemEvent.Reconnecting, { attempt: attempts, delay: 0 });
|
|
164
|
+
void attemptConnect();
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
// Still retrying: never give up sooner than a revived connection would — otherwise a retry of
|
|
168
|
+
// its lost siblings is undone moments later when this one's older budget runs out, even by an
|
|
169
|
+
// attempt already in flight — and attempt now rather than after the backoff.
|
|
170
|
+
if (current != null)
|
|
171
|
+
return;
|
|
172
|
+
const now = Date.now();
|
|
173
|
+
if (outageStartedAt != null && outageBudget - (now - outageStartedAt) < policy.reviveBudget) {
|
|
174
|
+
outageStartedAt = now;
|
|
175
|
+
outageBudget = policy.reviveBudget;
|
|
176
|
+
}
|
|
177
|
+
if (retryTimer == null)
|
|
178
|
+
return;
|
|
179
|
+
clearTimeout(retryTimer);
|
|
180
|
+
retryTimer = null;
|
|
181
|
+
void attemptConnect();
|
|
182
|
+
};
|
|
183
|
+
const onOpened = (socket) => {
|
|
184
|
+
current = socket;
|
|
185
|
+
const wasRetry = attempts > 0;
|
|
186
|
+
const receiveMessage = async (event) => {
|
|
187
|
+
// Any frame at all answers the outstanding ping — the point is liveness, not pongs.
|
|
188
|
+
pingSentAt = null;
|
|
189
|
+
if (typeof event.data === 'string') {
|
|
190
|
+
try {
|
|
191
|
+
if (JSON.parse(event.data)?.type === 'pong')
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// The shared parser below reports malformed JSON consistently.
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
await model.receive(event.data);
|
|
199
|
+
};
|
|
200
|
+
const messageHandler = (event) => {
|
|
201
|
+
void receiveMessage(event).catch(error => {
|
|
202
|
+
console.error('WebSocket message rejected:', error);
|
|
203
|
+
socket.close(1008);
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
const errorHandler = () => {
|
|
207
|
+
// The close event that always follows carries the code; nothing actionable here beyond
|
|
208
|
+
// keeping the browser's own unhandled-error reporting quiet for it.
|
|
209
|
+
};
|
|
210
|
+
const closeHandler = async (event) => {
|
|
211
|
+
if (current !== socket)
|
|
212
|
+
return;
|
|
213
|
+
socket.removeEventListener('message', messageHandler);
|
|
214
|
+
socket.removeEventListener('close', closeHandler);
|
|
215
|
+
socket.removeEventListener('error', errorHandler);
|
|
216
|
+
clearHeartbeat();
|
|
217
|
+
current = null;
|
|
218
|
+
if (closedByClient) {
|
|
219
|
+
await emitSystem(SocketSystemEvent.Close, { code: event.code });
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (!retry || TERMINAL_CLOSE_CODES.has(event.code)) {
|
|
223
|
+
await finish(event.code);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (model._authSequence != null) {
|
|
227
|
+
model._authSequence.reject(new SocketConnectionError('disconnected'));
|
|
228
|
+
model._authSequence = undefined;
|
|
229
|
+
}
|
|
230
|
+
model.stage = AuthenticationStage.Init;
|
|
231
|
+
await emitSystem(SocketSystemEvent.Disconnected, { code: event.code });
|
|
232
|
+
scheduleReconnect();
|
|
233
|
+
};
|
|
234
|
+
socket.addEventListener('message', messageHandler);
|
|
235
|
+
socket.addEventListener('close', closeHandler);
|
|
236
|
+
socket.addEventListener('error', errorHandler);
|
|
237
|
+
startHeartbeat(socket);
|
|
238
|
+
if (stableTimer != null)
|
|
239
|
+
clearTimeout(stableTimer);
|
|
240
|
+
stableTimer = setTimeout(() => {
|
|
241
|
+
attempts = 0;
|
|
242
|
+
outageStartedAt = null;
|
|
243
|
+
outageBudget = policy.budget;
|
|
244
|
+
}, policy.stableAfter);
|
|
245
|
+
onStatus?.('online');
|
|
246
|
+
settle();
|
|
247
|
+
if (wasRetry)
|
|
248
|
+
void emitSystem(SocketSystemEvent.Reconnected, { attempts });
|
|
249
|
+
};
|
|
4
250
|
model.send = async (message) => {
|
|
5
|
-
if (typeof message !== 'string')
|
|
251
|
+
if (typeof message !== 'string')
|
|
6
252
|
model.prepare?.(message);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
conn.send(typeof message === 'string' ? message : JSON.stringify(message));
|
|
253
|
+
if (current?.readyState === WebSocket.OPEN) {
|
|
254
|
+
current.send(typeof message === 'string' ? message : JSON.stringify(message));
|
|
10
255
|
}
|
|
11
256
|
};
|
|
12
257
|
model.close = async () => {
|
|
13
|
-
if (
|
|
14
|
-
|
|
258
|
+
if (finished)
|
|
259
|
+
return;
|
|
260
|
+
finished = true;
|
|
261
|
+
closedByClient = true;
|
|
262
|
+
clearTimers();
|
|
263
|
+
if (current != null && (current.readyState === WebSocket.OPEN || current.readyState === WebSocket.CONNECTING)) {
|
|
264
|
+
current.close(1000);
|
|
15
265
|
}
|
|
16
|
-
|
|
266
|
+
else {
|
|
267
|
+
// No live socket to fire a close event from — mid-retry, or closed before the first open
|
|
268
|
+
// ever resolved — so report the same frame directly.
|
|
269
|
+
await emitSystem(SocketSystemEvent.Close, { code: 1000 });
|
|
270
|
+
}
|
|
271
|
+
settle(new SocketConnectionError('closed'));
|
|
17
272
|
};
|
|
18
273
|
model.authenticate = async (_stage, _payload) => {
|
|
19
274
|
// @TODO Provide authentication flow logic here
|
|
@@ -24,24 +279,7 @@ export const makeConnection = (conn, _context) => {
|
|
|
24
279
|
message.dt = message.dt ?? Date.now();
|
|
25
280
|
return message;
|
|
26
281
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
const closeHandler = async (event) => {
|
|
31
|
-
const msg = {
|
|
32
|
-
type: MessageType.System,
|
|
33
|
-
event: 'close',
|
|
34
|
-
payload: { code: event.code }
|
|
35
|
-
};
|
|
36
|
-
if (model.prepare != null) {
|
|
37
|
-
model.prepare(msg);
|
|
38
|
-
}
|
|
39
|
-
await Promise.all(model.getListeners().map(async (listener) => listener(msg)));
|
|
40
|
-
conn.removeEventListener('message', messageHandler);
|
|
41
|
-
conn.removeEventListener('close', closeHandler);
|
|
42
|
-
};
|
|
43
|
-
conn.addEventListener('message', messageHandler);
|
|
44
|
-
conn.addEventListener('close', closeHandler);
|
|
45
|
-
return model;
|
|
282
|
+
void attemptConnect();
|
|
283
|
+
return { connection: model, ready, revive };
|
|
46
284
|
};
|
|
47
285
|
//# sourceMappingURL=connection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EAAE,WAAW,EAAE,qBAAqB,EAAE,iBAAiB,EAC5E,6BAA6B,EAC9B,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAGpD;;;6DAG6D;AAC7D,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AAiCvE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAA8B,EAAqB,EAAE;IAClF,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAA;IAC9C,MAAM,KAAK,GAAG,qBAAqB,EAAE,CAAA;IAErC,IAAI,OAAO,GAAqB,IAAI,CAAA;IACpC,IAAI,cAAc,GAAG,KAAK,CAAA;IAC1B,IAAI,QAAQ,GAAG,KAAK,CAAA;IACpB,4FAA4F;IAC5F,IAAI,IAAI,GAAG,KAAK,CAAA;IAChB,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,IAAI,eAAe,GAAkB,IAAI,CAAA;IACzC,IAAI,YAAY,GAAG,MAAM,CAAC,MAAM,CAAA;IAChC,IAA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