@owlmeans/client-socket 0.1.18-rc.47 → 0.1.18-rc.49
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 +6 -6
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/client-socket/SKILL.md +1 -1
- package/build/consts.d.ts +1 -0
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +1 -0
- package/build/consts.js.map +1 -1
- package/build/consts.local.d.ts +3 -0
- package/build/consts.local.d.ts.map +1 -0
- package/build/consts.local.js +2 -0
- package/build/consts.local.js.map +1 -0
- package/build/helper/types.d.ts +22 -0
- package/build/helper/types.d.ts.map +1 -0
- package/build/helper/types.js +2 -0
- package/build/helper/types.js.map +1 -0
- package/build/helper.d.ts +7 -28
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +74 -141
- package/build/helper.js.map +1 -1
- package/build/hooks.d.ts +18 -0
- package/build/hooks.d.ts.map +1 -0
- package/build/hooks.js +66 -0
- package/build/hooks.js.map +1 -0
- package/build/index.d.ts +2 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/status.d.ts +0 -1
- package/build/status.d.ts.map +1 -1
- package/build/status.js +2 -2
- package/build/status.js.map +1 -1
- package/build/utils/connection.d.ts +1 -30
- package/build/utils/connection.d.ts.map +1 -1
- package/build/utils/connection.js +1 -5
- package/build/utils/connection.js.map +1 -1
- package/build/utils/consts.local.d.ts +6 -0
- package/build/utils/consts.local.d.ts.map +1 -0
- package/build/utils/consts.local.js +6 -0
- package/build/utils/consts.local.js.map +1 -0
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/types.d.ts +31 -0
- package/build/utils/types.d.ts.map +1 -0
- package/build/utils/types.js +2 -0
- package/build/utils/types.js.map +1 -0
- package/package.json +13 -13
- package/src/consts.local.ts +3 -0
- package/src/consts.ts +2 -0
- package/src/helper/types.ts +20 -0
- package/src/helper.ts +90 -160
- package/src/hooks.ts +75 -0
- package/src/index.ts +2 -0
- package/src/status.ts +2 -4
- package/src/utils/connection.ts +3 -43
- package/src/utils/consts.local.ts +5 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/types.ts +33 -0
- package/tests/reconnect.spec.ts +11 -11
package/build/status.js.map
CHANGED
|
@@ -1 +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,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;
|
|
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,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAIxD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,KAAK,GAAW,aAAa,EAAuB,EAAE;IAC9F,MAAM,MAAM,GAAG,IAAI,GAAG,EAAiC,CAAA;IACvD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAsB,CAAA;IAC9C,MAAM,SAAS,GAAG,IAAI,GAAG,EAA0C,CAAA;IACnE,MAAM,cAAc,GAAG,IAAI,GAAG,EAAc,CAAA;IAC5C,IAAI,OAAO,GAA0B,QAAQ,CAAA;IAE7C,MAAM,SAAS,GAAG,GAAG,EAAE;QACrB,IAAI,KAAK,GAA0B,QAAQ,CAAA;QA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,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,cAAc,CAAC,CAAC,CAAA;QACxF,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,KAAK,KAAK,cAAc;YAAE,WAAW,CAAC,KAAK,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;QAClG,OAAO,GAAG,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,CAAA,CAAC,CAAC,CAAA;IAC3C,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAEb,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,CAAA,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAEhE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAA;AAC5B,CAAC,CAAA"}
|
|
@@ -1,33 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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
|
-
}
|
|
1
|
+
import type { ManagedConnection, ManagedConnectionOptions } from './types.js';
|
|
31
2
|
/**
|
|
32
3
|
* Build a `Connection` whose transport survives a dropped WebSocket.
|
|
33
4
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAI7E;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,SAAU,wBAAwB,KAAG,iBAqQ/D,CAAA"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { createBasicConnection, MessageType, SocketConnectionError, SocketSystemEvent, SOCKET_HEARTBEAT_TIMEOUT_CODE } from '@owlmeans/socket';
|
|
2
2
|
import { AuthenticationStage } from '@owlmeans/auth';
|
|
3
3
|
import { logger } from '@owlmeans/log';
|
|
4
|
+
import { TERMINAL_CLOSE_CODES } from './consts.local.js';
|
|
4
5
|
const log = logger('client-socket');
|
|
5
|
-
/** Close codes that mean "this connection is finished on purpose" — never worth retrying: a
|
|
6
|
-
* normal closure the SERVER initiated (1000, e.g. the protocol's own one-shot completion) and a
|
|
7
|
-
* policy violation (1008, e.g. the guard rejected the frame that opened it). A client-initiated
|
|
8
|
-
* close is handled separately, through `closedByClient`. */
|
|
9
|
-
const TERMINAL_CLOSE_CODES = new Set([1000, 1008]);
|
|
10
6
|
/**
|
|
11
7
|
* Build a `Connection` whose transport survives a dropped WebSocket.
|
|
12
8
|
*
|
|
@@ -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":"AAAA,OAAO,EAAiC,qBAAqB,EAAE,WAAW,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAA;AAC7K,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAGxD,MAAM,GAAG,GAAG,MAAM,CAAC,eAAe,CAAC,CAAA;AAEnC;;;;;;;;;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,M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AAA;IAErB,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;AAC7C,CAAC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Close codes that mean "this connection is finished on purpose" — never worth retrying: a
|
|
2
|
+
* normal closure the SERVER initiated (1000, e.g. the protocol's own one-shot completion) and a
|
|
3
|
+
* policy violation (1008, e.g. the guard rejected the frame that opened it). A client-initiated
|
|
4
|
+
* close is handled separately, through `closedByClient`. */
|
|
5
|
+
export declare const TERMINAL_CLOSE_CODES: ReadonlySet<number>;
|
|
6
|
+
//# sourceMappingURL=consts.local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.local.d.ts","sourceRoot":"","sources":["../../src/utils/consts.local.ts"],"names":[],"mappings":"AAAA;;;6DAG6D;AAC7D,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAAyB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Close codes that mean "this connection is finished on purpose" — never worth retrying: a
|
|
2
|
+
* normal closure the SERVER initiated (1000, e.g. the protocol's own one-shot completion) and a
|
|
3
|
+
* policy violation (1008, e.g. the guard rejected the frame that opened it). A client-initiated
|
|
4
|
+
* close is handled separately, through `closedByClient`. */
|
|
5
|
+
export const TERMINAL_CLOSE_CODES = new Set([1000, 1008]);
|
|
6
|
+
//# sourceMappingURL=consts.local.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.local.js","sourceRoot":"","sources":["../../src/utils/consts.local.ts"],"names":[],"mappings":"AAAA;;;6DAG6D;AAC7D,MAAM,CAAC,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA"}
|
package/build/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAA;AAC/B,mBAAmB,YAAY,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ReconnectPolicy, SocketConnectionState } from '../types.js';
|
|
2
|
+
import type { Connection } from '@owlmeans/socket';
|
|
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
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/client-socket",
|
|
3
|
-
"version": "0.1.18-rc.
|
|
3
|
+
"version": "0.1.18-rc.49",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -26,22 +26,22 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@owlmeans/dep-config": "workspace:*",
|
|
29
|
-
"@types/bun": "^1.4.
|
|
30
|
-
"@types/react": "^19.
|
|
29
|
+
"@types/bun": "^1.4.2",
|
|
30
|
+
"@types/react": "^19.3.0",
|
|
31
31
|
"nodemon": "^3.1.14",
|
|
32
32
|
"typescript": "^7.0.2"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@owlmeans/auth": "^0.1.18-rc.
|
|
36
|
-
"@owlmeans/basic-envelope": "^0.1.18-rc.
|
|
37
|
-
"@owlmeans/basic-ids": "^0.1.18-rc.
|
|
38
|
-
"@owlmeans/client": "^0.1.18-rc.
|
|
39
|
-
"@owlmeans/client-context": "^0.1.18-rc.
|
|
40
|
-
"@owlmeans/client-entrypoint": "^0.1.18-rc.
|
|
41
|
-
"@owlmeans/context": "^0.1.18-rc.
|
|
42
|
-
"@owlmeans/entrypoint": "^0.1.18-rc.
|
|
43
|
-
"@owlmeans/log": "^0.1.18-rc.
|
|
44
|
-
"@owlmeans/socket": "^0.1.18-rc.
|
|
35
|
+
"@owlmeans/auth": "^0.1.18-rc.40",
|
|
36
|
+
"@owlmeans/basic-envelope": "^0.1.18-rc.46",
|
|
37
|
+
"@owlmeans/basic-ids": "^0.1.18-rc.37",
|
|
38
|
+
"@owlmeans/client": "^0.1.18-rc.51",
|
|
39
|
+
"@owlmeans/client-context": "^0.1.18-rc.48",
|
|
40
|
+
"@owlmeans/client-entrypoint": "^0.1.18-rc.47",
|
|
41
|
+
"@owlmeans/context": "^0.1.18-rc.34",
|
|
42
|
+
"@owlmeans/entrypoint": "^0.1.18-rc.41",
|
|
43
|
+
"@owlmeans/log": "^0.1.18-rc.2",
|
|
44
|
+
"@owlmeans/socket": "^0.1.18-rc.40"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
package/src/consts.ts
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ClientEntrypoint } from '@owlmeans/client-entrypoint'
|
|
2
|
+
import type { AbstractRequest } from '@owlmeans/entrypoint'
|
|
3
|
+
import type { Connection } from '@owlmeans/socket'
|
|
4
|
+
import type { ConnectOptions, Context, WsOptions } from '../types.js'
|
|
5
|
+
|
|
6
|
+
/** Opens managed sockets that restore themselves after a network failure. */
|
|
7
|
+
export interface SocketClientHelper {
|
|
8
|
+
/**
|
|
9
|
+
* Open a socket with no declared entrypoint behind it — the primitive `ws()` builds on, and what
|
|
10
|
+
* a test drives directly against a bare WebSocket server.
|
|
11
|
+
*/
|
|
12
|
+
connect: (address: () => Promise<string> | string, ctx: Context, options?: ConnectOptions) => Promise<Connection>
|
|
13
|
+
/**
|
|
14
|
+
* Open a socket through a declared entrypoint protocol, restoring it on its own after a network
|
|
15
|
+
* failure — see the client-socket skill's "Disconnects" section for the full policy. Resolves
|
|
16
|
+
* once the first attempt opens; rejects with `SocketConnectionError('lost')` if the retry budget
|
|
17
|
+
* elapses before that ever happens (or the single attempt fails, with `reconnect: false`).
|
|
18
|
+
*/
|
|
19
|
+
ws: (module: ClientEntrypoint<string>, request?: AbstractRequest<{ token?: string }>, options?: WsOptions) => Promise<Connection>
|
|
20
|
+
}
|
package/src/helper.ts
CHANGED
|
@@ -1,180 +1,110 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ClientEntrypoint, clientRequestHelper } from '@owlmeans/client-entrypoint'
|
|
2
2
|
import type { AbstractRequest } from '@owlmeans/entrypoint'
|
|
3
|
-
import {
|
|
4
|
-
import type { Connection } from '@owlmeans/socket'
|
|
5
|
-
import { SocketConnectionError } from '@owlmeans/socket'
|
|
3
|
+
import { type Connection, SocketConnectionError } from '@owlmeans/socket'
|
|
6
4
|
import { makeConnection } from './utils/connection.js'
|
|
7
5
|
import { assertContext } from '@owlmeans/context'
|
|
8
|
-
import type { EntrypointReference } from '@owlmeans/context'
|
|
9
6
|
import type { Config, Context, ConnectOptions, ReconnectPolicy, SocketStatusServiceAppend, WsOptions } from './types.js'
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { entrypointUrl } from '@owlmeans/client-entrypoint/utils'
|
|
13
|
-
import { useEffect, useMemo, useState } from 'react'
|
|
7
|
+
import type { SocketClientHelper } from './helper/types.js'
|
|
8
|
+
import { makeApiCallHelper } from '@owlmeans/client-entrypoint/utils'
|
|
14
9
|
import { createIdOfLength } from '@owlmeans/basic-ids'
|
|
15
|
-
import { DEFAULT_RECONNECT_POLICY } from './consts.js'
|
|
16
|
-
import { SOCKET_STATUS } from './status.js'
|
|
10
|
+
import { DEFAULT_RECONNECT_POLICY, SOCKET_STATUS } from './consts.js'
|
|
17
11
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const openRawSocket = async (url: string): Promise<WebSocket> => {
|
|
28
|
-
const socket = new WebSocket(url)
|
|
29
|
-
return await new Promise<WebSocket>((resolve, reject) => {
|
|
30
|
-
const cleanup = () => {
|
|
31
|
-
socket.removeEventListener('open', onOpen)
|
|
32
|
-
socket.removeEventListener('error', onFail)
|
|
33
|
-
socket.removeEventListener('close', onFail)
|
|
34
|
-
}
|
|
35
|
-
const onOpen = () => { cleanup(); resolve(socket) }
|
|
36
|
-
const onFail = () => { cleanup(); reject(new SocketConnectionError('handshake')) }
|
|
37
|
-
socket.addEventListener('open', onOpen)
|
|
38
|
-
socket.addEventListener('error', onFail)
|
|
39
|
-
socket.addEventListener('close', onFail)
|
|
40
|
-
})
|
|
41
|
-
}
|
|
12
|
+
export const createSocketClientHelper = (): SocketClientHelper => {
|
|
13
|
+
const resolvePolicy = (
|
|
14
|
+
ctx: Context, options?: ConnectOptions
|
|
15
|
+
): { policy: ReconnectPolicy, retry: boolean } => {
|
|
16
|
+
const requested = options?.reconnect !== undefined ? options.reconnect : ctx.cfg.socket?.reconnect
|
|
17
|
+
const retry = requested !== false
|
|
18
|
+
const overrides = requested === false || requested == null ? {} : requested
|
|
19
|
+
return { policy: { ...DEFAULT_RECONNECT_POLICY, ...overrides }, retry }
|
|
20
|
+
}
|
|
42
21
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
22
|
+
const openRawSocket = async (url: string): Promise<WebSocket> => {
|
|
23
|
+
const socket = new WebSocket(url)
|
|
24
|
+
return await new Promise<WebSocket>((resolve, reject) => {
|
|
25
|
+
const cleanup = () => {
|
|
26
|
+
socket.removeEventListener('open', onOpen)
|
|
27
|
+
socket.removeEventListener('error', onFail)
|
|
28
|
+
socket.removeEventListener('close', onFail)
|
|
29
|
+
}
|
|
30
|
+
const onOpen = () => { cleanup(); resolve(socket) }
|
|
31
|
+
const onFail = () => { cleanup(); reject(new SocketConnectionError('handshake')) }
|
|
32
|
+
socket.addEventListener('open', onOpen)
|
|
33
|
+
socket.addEventListener('error', onFail)
|
|
34
|
+
socket.addEventListener('close', onFail)
|
|
35
|
+
})
|
|
36
|
+
}
|
|
49
37
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
})
|
|
58
|
-
const { connection, ready } = managed
|
|
38
|
+
const establish = async (
|
|
39
|
+
ctx: Context, policy: ReconnectPolicy, retry: boolean, open: () => Promise<WebSocket>
|
|
40
|
+
): Promise<Connection> => {
|
|
41
|
+
const statusId = createIdOfLength(8)
|
|
42
|
+
const status = ctx.hasService(SOCKET_STATUS)
|
|
43
|
+
? (ctx as unknown as SocketStatusServiceAppend).socketStatus() : null
|
|
59
44
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
45
|
+
let opened = false
|
|
46
|
+
let lost = false
|
|
47
|
+
const managed = makeConnection({
|
|
48
|
+
policy, retry, open, onStatus: state => {
|
|
49
|
+
lost = state === 'lost'
|
|
50
|
+
status?.report(statusId, state, state === 'online' ? undefined : revive)
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
const { connection, ready } = managed
|
|
65
54
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
55
|
+
const baseClose = connection.close
|
|
56
|
+
connection.close = async () => {
|
|
57
|
+
await baseClose()
|
|
58
|
+
status?.release(statusId)
|
|
70
59
|
}
|
|
71
|
-
// Never opened, so `ws()` already rejected and nobody holds this connection to hand a revived
|
|
72
|
-
// socket to: drop it for good and leave re-dialing to its owner (`useWs` does, on `onRetry`).
|
|
73
|
-
void baseClose()
|
|
74
|
-
status?.release(statusId)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// A rejection leaves this id reporting `'lost'` rather than releasing it — there is no
|
|
78
|
-
// `Connection` to hand back for a caller to close, and the aggregate is what puts
|
|
79
|
-
// `SocketReloadDialog` up. It is released by `revive` above, on the next `retry()`.
|
|
80
|
-
await ready
|
|
81
|
-
opened = true
|
|
82
60
|
|
|
83
|
-
|
|
84
|
-
|
|
61
|
+
const revive = () => {
|
|
62
|
+
if (opened || !lost) {
|
|
63
|
+
managed.revive()
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
// Never opened, so `ws()` already rejected and nobody holds this connection to hand a revived
|
|
67
|
+
// socket to: drop it for good and leave re-dialing to its owner (`useWs` does, on `onRetry`).
|
|
68
|
+
void baseClose()
|
|
69
|
+
status?.release(statusId)
|
|
70
|
+
}
|
|
85
71
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
address: () => Promise<string> | string, ctx: Context, options?: ConnectOptions
|
|
92
|
-
): Promise<Connection> => {
|
|
93
|
-
const { policy, retry } = resolvePolicy(ctx, options)
|
|
94
|
-
return await establish(ctx, policy, retry, async () => openRawSocket(await address()))
|
|
95
|
-
}
|
|
72
|
+
// A rejection leaves this id reporting `'lost'` rather than releasing it — there is no
|
|
73
|
+
// `Connection` to hand back for a caller to close, and the aggregate is what puts
|
|
74
|
+
// `SocketReloadDialog` up. It is released by `revive` above, on the next `retry()`.
|
|
75
|
+
await ready
|
|
76
|
+
opened = true
|
|
96
77
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* failure — see the client-socket skill's "Disconnects" section for the full policy. Resolves
|
|
100
|
-
* once the first attempt opens; rejects with `SocketConnectionError('lost')` if the retry budget
|
|
101
|
-
* elapses before that ever happens (or the single attempt fails, with `reconnect: false`).
|
|
102
|
-
*/
|
|
103
|
-
export const ws = async (
|
|
104
|
-
module: ClientEntrypoint<string>, request?: AbstractRequest<{ token?: string }>, options?: WsOptions
|
|
105
|
-
): Promise<Connection> => {
|
|
106
|
-
const ctx = assertContext<Config, Context>(module.ctx as Context, 'client-ws')
|
|
107
|
-
request = request ?? provideRequest(module.alias, module.path())
|
|
108
|
-
const { policy, retry } = resolvePolicy(ctx, options)
|
|
78
|
+
return connection
|
|
79
|
+
}
|
|
109
80
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
81
|
+
const connect = async (
|
|
82
|
+
address: () => Promise<string> | string, ctx: Context, options?: ConnectOptions
|
|
83
|
+
): Promise<Connection> => {
|
|
84
|
+
const { policy, retry } = resolvePolicy(ctx, options)
|
|
85
|
+
return await establish(ctx, policy, retry, async () => openRawSocket(await address()))
|
|
86
|
+
}
|
|
116
87
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
*
|
|
124
|
-
* Re-opens on its own after a network drop (see `ws()`). `null` until the first attempt opens,
|
|
125
|
-
* and again once the retry budget elapses without one ever opening — dialed afresh on the next
|
|
126
|
-
* `SocketStatusService.retry()`. A screen that must tell those two apart reads
|
|
127
|
-
* `useSocketStatus()` (from `./status.js`) alongside this.
|
|
128
|
-
*/
|
|
129
|
-
export const useWs = (
|
|
130
|
-
module: EntrypointReference | string, request?: Partial<AbstractRequest<any>>, options?: WsOptions
|
|
131
|
-
): Connection | null => {
|
|
132
|
-
const ctx = useContext()
|
|
133
|
-
const mod = useMemo(
|
|
134
|
-
() => ctx.entrypoint<ClientEntrypoint>(module),
|
|
135
|
-
[module]
|
|
136
|
-
)
|
|
137
|
-
const [failed, setFailed] = useState(false)
|
|
138
|
-
const [dial, setDial] = useState(0)
|
|
139
|
-
const connection = useValue<Connection | null>(async (cancel) => {
|
|
140
|
-
const _request = provideRequest(mod.alias, mod.path())
|
|
141
|
-
Object.assign(_request, request)
|
|
142
|
-
try {
|
|
143
|
-
const conn = await ws(mod, _request, options)
|
|
144
|
-
if (cancel?.current) {
|
|
145
|
-
// The component unmounted while the handshake (or its retries) were still in flight —
|
|
146
|
-
// there is no `useEffect` cleanup coming for this value, so close it here instead of
|
|
147
|
-
// leaving a live socket and its retry timers attached to nothing.
|
|
148
|
-
void conn.close()
|
|
149
|
-
return null
|
|
150
|
-
}
|
|
151
|
-
return conn
|
|
152
|
-
} catch {
|
|
153
|
-
if (!cancel?.current) setFailed(true)
|
|
154
|
-
return null
|
|
155
|
-
}
|
|
156
|
-
}, [
|
|
157
|
-
mod.alias,
|
|
158
|
-
request?.query?.[AUTH_QUERY],
|
|
159
|
-
request?.params ? JSON.stringify(request.params) : undefined,
|
|
160
|
-
dial
|
|
161
|
-
])
|
|
88
|
+
const ws = async (
|
|
89
|
+
module: ClientEntrypoint<string>, request?: AbstractRequest<{ token?: string }>, options?: WsOptions
|
|
90
|
+
): Promise<Connection> => {
|
|
91
|
+
const ctx = assertContext<Config, Context>(module.ctx as Context, 'client-ws')
|
|
92
|
+
request = request ?? clientRequestHelper.provideRequest(module.alias, module.path())
|
|
93
|
+
const { policy, retry } = resolvePolicy(ctx, options)
|
|
162
94
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
setDial(n => n + 1)
|
|
95
|
+
return await establish(ctx, policy, retry, async () => {
|
|
96
|
+
await options?.beforeConnect?.(request!)
|
|
97
|
+
const url = await makeApiCallHelper({ ref: module }).entrypointUrl(request)
|
|
98
|
+
return await openRawSocket(url)
|
|
168
99
|
})
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
useEffect(() => {
|
|
172
|
-
if (connection != null) {
|
|
173
|
-
return () => {
|
|
174
|
-
void connection.close()
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}, [connection])
|
|
100
|
+
}
|
|
178
101
|
|
|
179
|
-
return
|
|
102
|
+
return { connect, ws }
|
|
180
103
|
}
|
|
104
|
+
|
|
105
|
+
export const socketClientHelper = createSocketClientHelper()
|
|
106
|
+
|
|
107
|
+
/** @deprecated compat:factory-refactor — use `socketClientHelper.ws(…)` */
|
|
108
|
+
export const ws = (
|
|
109
|
+
module: ClientEntrypoint<string>, request?: AbstractRequest<{ token?: string }>, options?: WsOptions
|
|
110
|
+
): Promise<Connection> => socketClientHelper.ws(module, request, options)
|