@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
package/README.md
CHANGED
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
# @owlmeans/client-socket
|
|
2
2
|
|
|
3
|
-
React hook and factory for WebSocket connections via OwlMeans
|
|
3
|
+
React hook and factory for WebSocket connections via OwlMeans entrypoint routing.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
- `ws(
|
|
8
|
-
- `useWs(
|
|
7
|
+
- `ws(entrypoint, request?)` — creates a `Connection` from the entrypoint's URL and opens a WebSocket
|
|
8
|
+
- `useWs(entrypoint, request?)` — React hook wrapping `ws()` with lifecycle management; pass a
|
|
9
|
+
protocol-bound entrypoint directly
|
|
9
10
|
- The returned `Connection` implements `@owlmeans/socket`'s `Connection` interface
|
|
10
11
|
|
|
11
12
|
## Installation
|
|
12
13
|
|
|
13
14
|
```bash
|
|
14
|
-
bun add @owlmeans/client-socket
|
|
15
|
+
bun add @owlmeans/client-socket@^0.1.18-rc.41
|
|
15
16
|
```
|
|
16
17
|
|
|
17
18
|
## Usage
|
|
18
19
|
|
|
19
|
-
Connect to a WebSocket
|
|
20
|
+
Connect to a WebSocket entrypoint and observe events:
|
|
20
21
|
|
|
21
22
|
```typescript
|
|
22
23
|
import { useWs } from '@owlmeans/client-socket'
|
|
23
24
|
import { MessageType } from '@owlmeans/socket'
|
|
25
|
+
import { useContext } from '@owlmeans/web-client'
|
|
26
|
+
import { appProtocols } from 'my-app-common'
|
|
24
27
|
|
|
25
28
|
function ThinkingPanel({ storyId }: { storyId: string }) {
|
|
26
|
-
const
|
|
29
|
+
const context = useContext()
|
|
30
|
+
const conn = useWs(context.entrypoint(appProtocols.api.storyThinking), { params: { id: storyId } })
|
|
27
31
|
|
|
28
32
|
useEffect(() => {
|
|
29
33
|
if (!conn) return
|
|
@@ -39,27 +43,29 @@ Direct connection (non-hook):
|
|
|
39
43
|
|
|
40
44
|
```typescript
|
|
41
45
|
import { ws } from '@owlmeans/client-socket'
|
|
42
|
-
import
|
|
46
|
+
import { appProtocols } from 'my-app-common'
|
|
43
47
|
|
|
44
|
-
const
|
|
45
|
-
const connection = await ws(
|
|
48
|
+
const wsEntrypoint = context.entrypoint(appProtocols.api.storyThinking)
|
|
49
|
+
const connection = await ws(wsEntrypoint, { params: { id: storyId } })
|
|
46
50
|
```
|
|
47
51
|
|
|
48
52
|
## API
|
|
49
53
|
|
|
50
|
-
### `ws(
|
|
54
|
+
### `ws(entrypoint, request?): Promise<Connection>`
|
|
51
55
|
|
|
52
|
-
|
|
56
|
+
Builds the entrypoint's URL, opens a WebSocket, and returns a `Connection` once the socket opens.
|
|
53
57
|
|
|
54
|
-
### `useWs(
|
|
58
|
+
### `useWs(entrypoint, request?): Connection | null`
|
|
55
59
|
|
|
56
|
-
React hook version of `ws()`. Returns `null` while connecting. Manages connection lifecycle (opens
|
|
60
|
+
React hook version of `ws()`. Returns `null` while connecting. Manages connection lifecycle (opens
|
|
61
|
+
on mount, closes on unmount). Alias input is reserved for a dynamic external boundary; application
|
|
62
|
+
code calls `context.entrypoint(protocol)` first.
|
|
57
63
|
|
|
58
64
|
## Related Packages
|
|
59
65
|
|
|
60
66
|
- [`@owlmeans/socket`](../socket) — `Connection` interface with `notify`, `observe`, `call` methods
|
|
61
67
|
- [`@owlmeans/server-socket`](../server-socket) — server-side connection handler
|
|
62
|
-
- [`@owlmeans/client-
|
|
68
|
+
- [`@owlmeans/client-entrypoint`](../client-entrypoint) — protocol bindings passed to `ws()`
|
|
63
69
|
|
|
64
70
|
<!-- owlmeans:agent-guidance:start -->
|
|
65
71
|
## Agent guidance
|
|
@@ -69,7 +75,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
69
75
|
your project's skill store (`.agents/skills/`):
|
|
70
76
|
|
|
71
77
|
```sh
|
|
72
|
-
npx @owlmeans/agent-skills
|
|
78
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.40
|
|
73
79
|
```
|
|
74
80
|
|
|
75
81
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/client-socket",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.18-rc.41",
|
|
5
|
+
"generatedAt": "2026-09-25T21:19:37.961Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: client-socket
|
|
3
|
-
description: How to use @owlmeans/client-socket —
|
|
3
|
+
description: How to use @owlmeans/client-socket — opening a self-restoring WebSocket Connection to a socket entrypoint from browsers and native clients, the reconnect policy and its options, the socket-status aggregator, the useWs hook and the system frames a carrier emits. Auto-invoked when importing client socket primitives or wiring a browser subscription.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
---
|
|
6
6
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
@@ -8,23 +8,188 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/client-socket
|
|
9
9
|
|
|
10
10
|
**Layer:** Client
|
|
11
|
-
**Install:** `"@owlmeans/client-socket": "^0.1.18-rc.
|
|
11
|
+
**Install:** `"@owlmeans/client-socket": "^0.1.18-rc.41"` in `dependencies`
|
|
12
|
+
|
|
13
|
+
The browser carrier for `@owlmeans/socket`. It supplies the four members the connection model
|
|
14
|
+
leaves abstract — `send`, `close`, `prepare`, `authenticate` — and hands back a plain `Connection`,
|
|
15
|
+
so everything a screen does with the socket is the vocabulary of that package — `observe`,
|
|
16
|
+
`notify`, `call`, `listen`. It also restores a dropped WebSocket on its own, on the SAME
|
|
17
|
+
`Connection` model, so nothing a caller registered with `observe`/`listen` needs to be
|
|
18
|
+
re-registered after a network blip.
|
|
12
19
|
|
|
13
20
|
## Key Exports
|
|
14
21
|
|
|
15
22
|
| Export | Description |
|
|
16
23
|
|--------|-------------|
|
|
17
|
-
| `
|
|
18
|
-
|
|
|
24
|
+
| `ws(entrypoint, request?, options?)` | Open a `Connection` to a socket entrypoint. Resolves once the FIRST attempt opens; rejects with `SocketConnectionError('lost')` if the retry budget elapses first |
|
|
25
|
+
| `useWs(protocol \| alias, request?, options?)` | React hook — `Connection \| null` until it opens (or gives up); re-opens on `alias`/`AUTH_QUERY`/`params` change and closes on unmount |
|
|
26
|
+
| `connect(address, ctx, options?)` | The same machinery with no entrypoint behind it — an `address` callback returning the URL, for an adapter or a test |
|
|
27
|
+
| `appendSocketStatus(ctx, alias?)` / `useSocketStatus()` / `useSocketRetry()` | The status aggregator and its retry — see below |
|
|
28
|
+
| `Config` / `Context` | The client config (`socket?: SocketClientSettings`) and context types this package expects |
|
|
29
|
+
| `ReconnectPolicy` / `SocketClientSettings` / `ConnectOptions` / `WsOptions` | The reconnect policy shape and where it can be set — config, or per-call `options` |
|
|
30
|
+
|
|
31
|
+
## How the address is built
|
|
32
|
+
|
|
33
|
+
A socket entrypoint is **addressed, not called**: `entrypointUrl` from
|
|
34
|
+
`@owlmeans/client-entrypoint/utils` turns the declaration plus the asking context into the `wss://`
|
|
35
|
+
URL — `:params` filled in, query appended, protocol and TLS taken from the entrypoint's address —
|
|
36
|
+
and the connection is opened on that. Nothing is hand-concatenated, so the same declaration the
|
|
37
|
+
server binds is the one the client dials. It is re-resolved on EVERY attempt, first one included,
|
|
38
|
+
so a `beforeConnect` hook that mutates the request's query (a refreshed token, most often) reaches
|
|
39
|
+
every reconnect too, not just the first handshake.
|
|
40
|
+
|
|
41
|
+
Authentication rides on the query, because a WebSocket handshake carries no Authorization header a
|
|
42
|
+
browser can set: the token goes under `AUTH_QUERY`, and the server derives the connection's subject
|
|
43
|
+
from it.
|
|
44
|
+
|
|
45
|
+
**Take the authenticated hook, not this one.** `@owlmeans/client-auth` exports its own `useWs` that
|
|
46
|
+
wraps this one, fills `AUTH_QUERY` from `ctx.auth().token`, and refreshes it via `beforeConnect` on
|
|
47
|
+
every reconnect — unless the request already carried its own token, in which case that caller's
|
|
48
|
+
value is left alone across reconnects too. Import `useWs` from there for anything a guard
|
|
49
|
+
protects, and from here only for an entrypoint that is open to everyone.
|
|
50
|
+
|
|
51
|
+
The in-band auth sequence is a different thing from the query token, and only half of it is here.
|
|
52
|
+
`connection.auth(stage, payload)` sends the frame and resolves on the server's reply — that is the
|
|
53
|
+
client-initiated exchange, and it works. This carrier's own `authenticate` is a stub answering an
|
|
54
|
+
empty tuple, so an `Auth` frame the SERVER opens finds no stage to answer with and is dropped
|
|
55
|
+
without a reply: a browser can start an exchange, never answer one.
|
|
56
|
+
|
|
57
|
+
**A reconnect is a brand-new server-side connection.** If a server sets up subscriptions only
|
|
58
|
+
after an in-band `authenticate` frame (as this platform's own handlers do — see the `socket`
|
|
59
|
+
memory in `viable`), the carrier does NOT replay that frame by itself; it only reopens the pipe.
|
|
60
|
+
A caller that authenticates in-band must listen for `SocketSystemEvent.Reconnected` and resend it
|
|
61
|
+
— `viable`'s `sources/manager-web/src/lib/ws.ts` `useAuthWs` is the worked example.
|
|
19
62
|
|
|
20
63
|
## Usage
|
|
21
64
|
|
|
22
65
|
```typescript
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
66
|
+
// A guarded entrypoint: this useWs fills AUTH_QUERY from the current session and keeps it fresh
|
|
67
|
+
// across reconnects.
|
|
68
|
+
import { useWs } from '@owlmeans/client-auth'
|
|
69
|
+
|
|
70
|
+
// An open one: this useWs sends whatever query it is given, and nothing more.
|
|
71
|
+
// import { useWs } from '@owlmeans/client-socket'
|
|
72
|
+
|
|
73
|
+
const connection = useWs(app.api.project.stream, { params: { id } })
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (connection == null) {
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
const stop = connection.observe<Update>('update', async msg => apply(msg.payload))
|
|
80
|
+
|
|
81
|
+
return () => stop()
|
|
82
|
+
}, [connection])
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Pass the immutable socket protocol declaration in application code. A string alias is reserved
|
|
86
|
+
for an adapter whose remote declaration is unavailable to import. Both hooks re-open when the
|
|
87
|
+
protocol, `AUTH_QUERY` value, or params change — the params are compared by content, so a fresh
|
|
88
|
+
object literal each render does not re-open. Both close the connection when the component unmounts,
|
|
89
|
+
and both answer `null` until the socket is open, so every effect that touches one guards on that.
|
|
90
|
+
|
|
91
|
+
## Disconnects and reconnects
|
|
92
|
+
|
|
93
|
+
The carrier keeps the same `Connection` MODEL for the life of the hook/call and swaps only the
|
|
94
|
+
underlying `WebSocket` underneath it — every `observe`/`listen` a caller registered survives a
|
|
95
|
+
reconnect, because it was registered on the model, not on the socket.
|
|
96
|
+
|
|
97
|
+
**The retry policy** (`ReconnectPolicy`, defaults in `DEFAULT_RECONNECT_POLICY`):
|
|
98
|
+
|
|
99
|
+
| Field | Default | Meaning |
|
|
100
|
+
|---|---|---|
|
|
101
|
+
| `minDelay` | 200ms | First retry delay |
|
|
102
|
+
| `maxDelay` | 3000ms | Delay ceiling — backoff never grows past this |
|
|
103
|
+
| `factor` | 2 | Geometric growth per failed attempt |
|
|
104
|
+
| `jitter` | 0.1 | ±10% randomization on each computed delay |
|
|
105
|
+
| `budget` | 600000ms (10 min) | Total retry time before the carrier gives up |
|
|
106
|
+
| `reviveBudget` | 15000ms | Retry window `retry()` gives a lost socket (and the minimum it leaves one still retrying) — short, so a retry that cannot succeed reports `'lost'` again while someone is still looking |
|
|
107
|
+
| `stableAfter` | 10000ms | How long a reopened socket must stay up before the attempt count, the outage clock and the budget (back to `budget`) reset |
|
|
108
|
+
| `heartbeat` | 30000ms | Ping interval — runs even with `reconnect: false` |
|
|
109
|
+
| `pongTimeout` | 10000ms | Checked at the next heartbeat tick: the ping still unanswered this long ⇒ the carrier force-closes the socket itself (code 4000, `SOCKET_HEARTBEAT_TIMEOUT_CODE`) — the only way a silently half-open TCP connection is noticed before the OS would, minutes later. Measured from the PING, never from the last frame: a hidden tab's timers are throttled to roughly one wake-up a minute, and "nothing for a whole interval" is what throttling looks like, not what a dead socket looks like. Any inbound frame answers the ping; `server-socket` replies `{"type":"pong"}` |
|
|
110
|
+
|
|
111
|
+
Set it on `ctx.cfg.socket.reconnect` (app-wide) or per call via `options.reconnect` (which wins).
|
|
112
|
+
`reconnect: false` disables retries — a drop is reported once and stays dropped, the
|
|
113
|
+
pre-reconnect-support behaviour — while the heartbeat/liveness check above still runs. Use it for
|
|
114
|
+
a stateful one-shot handshake a reconnect could never resume correctly (the wallet-tunnel rely
|
|
115
|
+
session in `client-auth` sets it for exactly this reason).
|
|
116
|
+
|
|
117
|
+
**System frames** (`SocketSystemEvent`, from `@owlmeans/socket`) reach every `connection.listen`
|
|
118
|
+
subscriber:
|
|
119
|
+
|
|
120
|
+
| Event | When |
|
|
121
|
+
|---|---|
|
|
122
|
+
| `disconnected` | The socket dropped and a retry IS scheduled — `{ code }` |
|
|
123
|
+
| `reconnecting` | Before each retry attempt — `{ attempt, delay }` (`delay: 0` for a revive's immediate attempt) |
|
|
124
|
+
| `reconnected` | A retry succeeded, a revived one included — `{ attempts }` |
|
|
125
|
+
| `lost` | The retry budget elapsed with no success — no payload. The connection is NOT closed: it stays revivable (below) until its owner closes it |
|
|
126
|
+
| `close` | The connection is gone for GOOD: a client-initiated close, a terminal server code (1000/1008), or `reconnect: false` and the one attempt failed. Never follows `lost` by itself |
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
connection.listen(async message => {
|
|
130
|
+
const msg = message as EventMessage<unknown>
|
|
131
|
+
if (typeof message !== 'object' || msg.type !== 'system') return
|
|
132
|
+
if (msg.event === SocketSystemEvent.Reconnected) await resubscribe()
|
|
133
|
+
if (msg.event === SocketSystemEvent.Close) await release()
|
|
134
|
+
})
|
|
26
135
|
```
|
|
27
136
|
|
|
137
|
+
**The status aggregator.** `appendSocketStatus(ctx)` registers a shared service every
|
|
138
|
+
`ws()`/`useWs()` connection reports its state into; `useSocketStatus()` reads the WORST state
|
|
139
|
+
across all of them (`'online' | 'reconnecting' | 'lost'`). A `'lost'` connection stays in the
|
|
140
|
+
aggregate — that is what `@owlmeans/web-panel`'s `SocketReloadDialog` reads to put up its global
|
|
141
|
+
prompt (`cfg.socket.reloadDialog`) — until something revives or closes it. Calling
|
|
142
|
+
`appendSocketStatus` unconditionally is cheap and safe for a host package — nothing reports into
|
|
143
|
+
it unless something calls `ws()`/`useWs()`, so an app that never does behaves exactly as before.
|
|
144
|
+
|
|
145
|
+
**Retry.** `socketStatus().retry()` revives every `'lost'` connection and hurries every
|
|
146
|
+
`'reconnecting'` one (attempt at once instead of after the backoff, and at least `reviveBudget`
|
|
147
|
+
left) — without that, a sibling whose older budget runs out a moment later reports `'lost'` right
|
|
148
|
+
after the retry and puts the dialog straight back. It fires `onRetry` listeners and returns `true`
|
|
149
|
+
only when something was lost, so calling it freely is safe.
|
|
150
|
+
The service calls it by itself when the tab becomes visible, the window gains focus, or the
|
|
151
|
+
browser goes back `online` — a background tab is where sockets die unnoticed (throttled timers, a
|
|
152
|
+
sleeping machine), so the moment it is looked at again is when to retry. How a lost connection
|
|
153
|
+
comes back depends on whether it ever opened:
|
|
154
|
+
|
|
155
|
+
- **Opened before** — revived in place: one attempt at once, then the normal backoff within
|
|
156
|
+
`reviveBudget`. Same `Connection` model, and success emits `reconnected`, so the re-auth / re-sync
|
|
157
|
+
listeners every caller already has for a network blip cover this too. Failing again reports
|
|
158
|
+
`lost` again.
|
|
159
|
+
- **Never opened** — `ws()` already rejected and nobody holds it, so it is closed for good and
|
|
160
|
+
released. `useWs` re-dials by itself on `onRetry` (a fresh `ws()`, full `budget`); a direct
|
|
161
|
+
`ws()` caller re-opens on its own terms.
|
|
162
|
+
- A terminal close (1000/1008, `reconnect: false`) is never revived.
|
|
163
|
+
|
|
164
|
+
`useSocketRetry()` gives a UI `{ retry, retrying }` — `retrying` is true from any retry (the
|
|
165
|
+
button, or the service's own on activation) until the aggregate settles on `'online'` or `'lost'`.
|
|
166
|
+
|
|
167
|
+
`useSocketStatus()` tolerates being called before the context's own `configure()`/`init()` has
|
|
168
|
+
run (it defaults to `'online'` and re-attaches once `ctx.waitForInitialized()` resolves) — a
|
|
169
|
+
component mounted as a sibling of the router, as `SocketReloadDialog` is, renders on React's
|
|
170
|
+
first commit, before the router's effect has had a chance to initialize the context.
|
|
171
|
+
|
|
172
|
+
Outbound frames are stamped with `dt` and dropped rather than queued while the socket is not
|
|
173
|
+
`OPEN`, so a `notify` issued while the socket is down is lost rather than delivered late. Nothing
|
|
174
|
+
here replays events the SERVER sent while the socket was down either — a caller that cannot
|
|
175
|
+
tolerate a gap re-syncs its own state on `reconnected` (viable's file-watch editor re-lists files;
|
|
176
|
+
its thinking/slot socket relies on a separate periodic API push for the same reason).
|
|
177
|
+
|
|
28
178
|
## Depends On
|
|
29
179
|
|
|
30
|
-
- `@owlmeans/socket`,
|
|
180
|
+
- `@owlmeans/socket` — `createBasicConnection`, `MessageType`, `SocketSystemEvent`,
|
|
181
|
+
`SOCKET_HEARTBEAT_TIMEOUT_CODE`, `SocketConnectionError`, the `Connection` contract
|
|
182
|
+
- `@owlmeans/client-entrypoint` — `entrypointUrl`, `provideRequest`
|
|
183
|
+
- `@owlmeans/client` — `useContext`, `useValue`; `@owlmeans/client-context` — the config type
|
|
184
|
+
- `@owlmeans/auth` — `AUTH_QUERY`, `AuthenticationStage`
|
|
185
|
+
- `@owlmeans/basic-ids` — `createIdOfLength`, for the per-connection status-tracking id
|
|
186
|
+
- `react` (peer)
|
|
187
|
+
|
|
188
|
+
## Related
|
|
189
|
+
|
|
190
|
+
- `socket` — the message model every verb here belongs to, and the `SocketSystemEvent` vocabulary
|
|
191
|
+
- `server-socket` — the far side: guard enforcement, and what it stamps on a frame
|
|
192
|
+
- `client-auth` — the `useWs` that carries the token and refreshes it across reconnects;
|
|
193
|
+
`client-job` — `useJobFeed`, a worked subscription built on it
|
|
194
|
+
- `web-panel` — `SocketReloadDialog`, the global blocking prompt built on `useSocketStatus()` /
|
|
195
|
+
`useSocketRetry()`
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReconnectPolicy } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* 0.2s → 3s geometric backoff, retried for up to 10 minutes before the carrier gives up and
|
|
4
|
+
* reports the connection lost. See the client-socket skill's "Disconnects" section.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_RECONNECT_POLICY: ReconnectPolicy;
|
|
7
|
+
//# sourceMappingURL=consts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,eAUtC,CAAA"}
|
package/build/consts.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 0.2s → 3s geometric backoff, retried for up to 10 minutes before the carrier gives up and
|
|
3
|
+
* reports the connection lost. See the client-socket skill's "Disconnects" section.
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_RECONNECT_POLICY = {
|
|
6
|
+
minDelay: 200,
|
|
7
|
+
maxDelay: 3_000,
|
|
8
|
+
factor: 2,
|
|
9
|
+
jitter: 0.1,
|
|
10
|
+
budget: 600_000,
|
|
11
|
+
reviveBudget: 15_000,
|
|
12
|
+
stableAfter: 10_000,
|
|
13
|
+
heartbeat: 30_000,
|
|
14
|
+
pongTimeout: 10_000,
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=consts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAoB;IACvD,QAAQ,EAAE,GAAG;IACb,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,GAAG;IACX,MAAM,EAAE,OAAO;IACf,YAAY,EAAE,MAAM;IACpB,WAAW,EAAE,MAAM;IACnB,SAAS,EAAE,MAAM;IACjB,WAAW,EAAE,MAAM;CACpB,CAAA"}
|
package/build/helper.d.ts
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
import type { ClientEntrypoint } from '@owlmeans/client-entrypoint';
|
|
2
2
|
import type { AbstractRequest } from '@owlmeans/entrypoint';
|
|
3
3
|
import type { Connection } from '@owlmeans/socket';
|
|
4
|
+
import type { EntrypointReference } from '@owlmeans/context';
|
|
5
|
+
import type { Context, ConnectOptions, WsOptions } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Open a socket with no declared entrypoint behind it — the primitive `ws()` builds on, and what
|
|
8
|
+
* a test drives directly against a bare WebSocket server.
|
|
9
|
+
*/
|
|
10
|
+
export declare const connect: (address: () => Promise<string> | string, ctx: Context, options?: ConnectOptions) => Promise<Connection>;
|
|
11
|
+
/**
|
|
12
|
+
* Open a socket through a declared entrypoint protocol, restoring it on its own after a network
|
|
13
|
+
* failure — see the client-socket skill's "Disconnects" section for the full policy. Resolves
|
|
14
|
+
* once the first attempt opens; rejects with `SocketConnectionError('lost')` if the retry budget
|
|
15
|
+
* elapses before that ever happens (or the single attempt fails, with `reconnect: false`).
|
|
16
|
+
*/
|
|
4
17
|
export declare const ws: (module: ClientEntrypoint<string>, request?: AbstractRequest<{
|
|
5
18
|
token?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
19
|
+
}>, options?: WsOptions) => Promise<Connection>;
|
|
20
|
+
/**
|
|
21
|
+
* Open a socket through a declared entrypoint protocol.
|
|
22
|
+
*
|
|
23
|
+
* String aliases remain an adapter input for dynamically addressed integrations, while
|
|
24
|
+
* application callers pass their immutable protocol declaration and receive its bound client
|
|
25
|
+
* entrypoint here at the transport boundary.
|
|
26
|
+
*
|
|
27
|
+
* Re-opens on its own after a network drop (see `ws()`). `null` until the first attempt opens,
|
|
28
|
+
* and again once the retry budget elapses without one ever opening — dialed afresh on the next
|
|
29
|
+
* `SocketStatusService.retry()`. A screen that must tell those two apart reads
|
|
30
|
+
* `useSocketStatus()` (from `./status.js`) alongside this.
|
|
31
|
+
*/
|
|
32
|
+
export declare const useWs: (module: EntrypointReference | string, request?: Partial<AbstractRequest<any>>, options?: WsOptions) => Connection | null;
|
|
8
33
|
//# sourceMappingURL=helper.d.ts.map
|
package/build/helper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAIlD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAU,OAAO,EAAE,cAAc,EAA8C,SAAS,EAAE,MAAM,YAAY,CAAA;AA6ExH;;;GAGG;AACH,eAAO,MAAM,OAAO,YACT,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,OAAO,OAAO,YAAY,cAAc,KAC9E,OAAO,CAAC,UAAU,CAGpB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,EAAE,WACL,gBAAgB,CAAC,MAAM,CAAC,YAAY,eAAe,CAAC;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,YAAY,SAAS,KACnG,OAAO,CAAC,UAAU,CAUpB,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,KAAK,WACR,mBAAmB,GAAG,MAAM,YAAY,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,YAAY,SAAS,KACjG,UAAU,GAAG,IAiDf,CAAA"}
|
package/build/helper.js
CHANGED
|
@@ -1,47 +1,144 @@
|
|
|
1
1
|
import { provideRequest } from '@owlmeans/client-entrypoint';
|
|
2
|
-
import {
|
|
3
|
-
import { SocketInitializationError } from '@owlmeans/socket';
|
|
2
|
+
import { SocketConnectionError } from '@owlmeans/socket';
|
|
4
3
|
import { makeConnection } from './utils/connection.js';
|
|
5
4
|
import { assertContext } from '@owlmeans/context';
|
|
6
5
|
import { useContext, useValue } from '@owlmeans/client';
|
|
7
6
|
import { AUTH_QUERY } from '@owlmeans/auth';
|
|
8
|
-
import {
|
|
9
|
-
import { useEffect, useMemo } from 'react';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
7
|
+
import { entrypointUrl } from '@owlmeans/client-entrypoint/utils';
|
|
8
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
9
|
+
import { createIdOfLength } from '@owlmeans/basic-ids';
|
|
10
|
+
import { DEFAULT_RECONNECT_POLICY } from './consts.js';
|
|
11
|
+
import { SOCKET_STATUS } from './status.js';
|
|
12
|
+
const resolvePolicy = (ctx, options) => {
|
|
13
|
+
const requested = options?.reconnect !== undefined ? options.reconnect : ctx.cfg.socket?.reconnect;
|
|
14
|
+
const retry = requested !== false;
|
|
15
|
+
const overrides = requested === false || requested == null ? {} : requested;
|
|
16
|
+
return { policy: { ...DEFAULT_RECONNECT_POLICY, ...overrides }, retry };
|
|
17
|
+
};
|
|
18
|
+
const openRawSocket = async (url) => {
|
|
17
19
|
const socket = new WebSocket(url);
|
|
18
|
-
return new Promise(resolve => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
}, 30_000);
|
|
25
|
-
socket.addEventListener('close', () => {
|
|
26
|
-
console.info('WebSocket connection closed, clearing heartbeat interval.');
|
|
27
|
-
clearInterval(heartbeat);
|
|
28
|
-
});
|
|
29
|
-
resolve(makeConnection(socket, ctx));
|
|
20
|
+
return await new Promise((resolve, reject) => {
|
|
21
|
+
const cleanup = () => {
|
|
22
|
+
socket.removeEventListener('open', onOpen);
|
|
23
|
+
socket.removeEventListener('error', onFail);
|
|
24
|
+
socket.removeEventListener('close', onFail);
|
|
30
25
|
};
|
|
26
|
+
const onOpen = () => { cleanup(); resolve(socket); };
|
|
27
|
+
const onFail = () => { cleanup(); reject(new SocketConnectionError('handshake')); };
|
|
28
|
+
socket.addEventListener('open', onOpen);
|
|
29
|
+
socket.addEventListener('error', onFail);
|
|
30
|
+
socket.addEventListener('close', onFail);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const establish = async (ctx, policy, retry, open) => {
|
|
34
|
+
const statusId = createIdOfLength(8);
|
|
35
|
+
const status = ctx.hasService(SOCKET_STATUS)
|
|
36
|
+
? ctx.socketStatus() : null;
|
|
37
|
+
let opened = false;
|
|
38
|
+
let lost = false;
|
|
39
|
+
const managed = makeConnection({
|
|
40
|
+
policy, retry, open, onStatus: state => {
|
|
41
|
+
lost = state === 'lost';
|
|
42
|
+
status?.report(statusId, state, state === 'online' ? undefined : revive);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const { connection, ready } = managed;
|
|
46
|
+
const baseClose = connection.close;
|
|
47
|
+
connection.close = async () => {
|
|
48
|
+
await baseClose();
|
|
49
|
+
status?.release(statusId);
|
|
50
|
+
};
|
|
51
|
+
const revive = () => {
|
|
52
|
+
if (opened || !lost) {
|
|
53
|
+
managed.revive();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// Never opened, so `ws()` already rejected and nobody holds this connection to hand a revived
|
|
57
|
+
// socket to: drop it for good and leave re-dialing to its owner (`useWs` does, on `onRetry`).
|
|
58
|
+
void baseClose();
|
|
59
|
+
status?.release(statusId);
|
|
60
|
+
};
|
|
61
|
+
// A rejection leaves this id reporting `'lost'` rather than releasing it — there is no
|
|
62
|
+
// `Connection` to hand back for a caller to close, and the aggregate is what puts
|
|
63
|
+
// `SocketReloadDialog` up. It is released by `revive` above, on the next `retry()`.
|
|
64
|
+
await ready;
|
|
65
|
+
opened = true;
|
|
66
|
+
return connection;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Open a socket with no declared entrypoint behind it — the primitive `ws()` builds on, and what
|
|
70
|
+
* a test drives directly against a bare WebSocket server.
|
|
71
|
+
*/
|
|
72
|
+
export const connect = async (address, ctx, options) => {
|
|
73
|
+
const { policy, retry } = resolvePolicy(ctx, options);
|
|
74
|
+
return await establish(ctx, policy, retry, async () => openRawSocket(await address()));
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Open a socket through a declared entrypoint protocol, restoring it on its own after a network
|
|
78
|
+
* failure — see the client-socket skill's "Disconnects" section for the full policy. Resolves
|
|
79
|
+
* once the first attempt opens; rejects with `SocketConnectionError('lost')` if the retry budget
|
|
80
|
+
* elapses before that ever happens (or the single attempt fails, with `reconnect: false`).
|
|
81
|
+
*/
|
|
82
|
+
export const ws = async (module, request, options) => {
|
|
83
|
+
const ctx = assertContext(module.ctx, 'client-ws');
|
|
84
|
+
request = request ?? provideRequest(module.alias, module.path());
|
|
85
|
+
const { policy, retry } = resolvePolicy(ctx, options);
|
|
86
|
+
return await establish(ctx, policy, retry, async () => {
|
|
87
|
+
await options?.beforeConnect?.(request);
|
|
88
|
+
const url = await entrypointUrl({ ref: module }, request);
|
|
89
|
+
return await openRawSocket(url);
|
|
31
90
|
});
|
|
32
91
|
};
|
|
33
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Open a socket through a declared entrypoint protocol.
|
|
94
|
+
*
|
|
95
|
+
* String aliases remain an adapter input for dynamically addressed integrations, while
|
|
96
|
+
* application callers pass their immutable protocol declaration and receive its bound client
|
|
97
|
+
* entrypoint here at the transport boundary.
|
|
98
|
+
*
|
|
99
|
+
* Re-opens on its own after a network drop (see `ws()`). `null` until the first attempt opens,
|
|
100
|
+
* and again once the retry budget elapses without one ever opening — dialed afresh on the next
|
|
101
|
+
* `SocketStatusService.retry()`. A screen that must tell those two apart reads
|
|
102
|
+
* `useSocketStatus()` (from `./status.js`) alongside this.
|
|
103
|
+
*/
|
|
104
|
+
export const useWs = (module, request, options) => {
|
|
34
105
|
const ctx = useContext();
|
|
35
|
-
const mod = useMemo(() =>
|
|
36
|
-
const
|
|
37
|
-
|
|
106
|
+
const mod = useMemo(() => ctx.entrypoint(module), [module]);
|
|
107
|
+
const [failed, setFailed] = useState(false);
|
|
108
|
+
const [dial, setDial] = useState(0);
|
|
109
|
+
const connection = useValue(async (cancel) => {
|
|
110
|
+
const _request = provideRequest(mod.alias, mod.path());
|
|
38
111
|
Object.assign(_request, request);
|
|
39
|
-
|
|
112
|
+
try {
|
|
113
|
+
const conn = await ws(mod, _request, options);
|
|
114
|
+
if (cancel?.current) {
|
|
115
|
+
// The component unmounted while the handshake (or its retries) were still in flight —
|
|
116
|
+
// there is no `useEffect` cleanup coming for this value, so close it here instead of
|
|
117
|
+
// leaving a live socket and its retry timers attached to nothing.
|
|
118
|
+
void conn.close();
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
return conn;
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
if (!cancel?.current)
|
|
125
|
+
setFailed(true);
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
40
128
|
}, [
|
|
41
|
-
mod.
|
|
129
|
+
mod.alias,
|
|
42
130
|
request?.query?.[AUTH_QUERY],
|
|
43
|
-
request?.params ? JSON.stringify(request.params) : undefined
|
|
131
|
+
request?.params ? JSON.stringify(request.params) : undefined,
|
|
132
|
+
dial
|
|
44
133
|
]);
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (!failed || !ctx.hasService(SOCKET_STATUS))
|
|
136
|
+
return;
|
|
137
|
+
return ctx.socketStatus().onRetry(() => {
|
|
138
|
+
setFailed(false);
|
|
139
|
+
setDial(n => n + 1);
|
|
140
|
+
});
|
|
141
|
+
}, [failed]);
|
|
45
142
|
useEffect(() => {
|
|
46
143
|
if (connection != null) {
|
|
47
144
|
return () => {
|
package/build/helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","source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,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;QACrB,CAAC,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA;IAEZ,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;YACvB,OAAO,GAAG,EAAE;gBACV,KAAK,UAAU,CAAC,KAAK,EAAE,CAAA;YACzB,CAAC,CAAA;QACH,CAAC;IACH,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA;IAEhB,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA"}
|
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
package/build/index.js
CHANGED
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Config, Context, SocketConnectionState, SocketStatusService, SocketStatusServiceAppend } from './types.js';
|
|
2
|
+
export declare const SOCKET_STATUS = "socket-status";
|
|
3
|
+
/**
|
|
4
|
+
* Aggregates the coarse health of every `ws()`/`useWs()` connection an app has open into one
|
|
5
|
+
* worst-of-all state. A page with several sockets (thinking stream, file watch, notifications…)
|
|
6
|
+
* still shows one dialog, not one per socket — so the aggregate, not any single connection, is
|
|
7
|
+
* what a UI like `SocketReloadDialog` reads.
|
|
8
|
+
*/
|
|
9
|
+
export declare const createSocketStatusService: (alias?: string) => SocketStatusService;
|
|
10
|
+
/**
|
|
11
|
+
* Register the shared socket-status aggregator. Idempotent, and cheap enough for a host package
|
|
12
|
+
* (`@owlmeans/web-panel`) to call unconditionally on every context: every `ws()`/`useWs()`
|
|
13
|
+
* connection reports itself here if — and only if — the context carries this service, so an app
|
|
14
|
+
* that never calls this behaves exactly as it did before reconnect support existed.
|
|
15
|
+
*/
|
|
16
|
+
export declare const appendSocketStatus: <C extends Config = Config, T extends Context<C> = Context<C>>(ctx: T, alias?: string) => T & SocketStatusServiceAppend;
|
|
17
|
+
/**
|
|
18
|
+
* The worst state across every live `ws()`/`useWs()` connection, or `'online'` if the app never
|
|
19
|
+
* registered the status service (`appendSocketStatus`) or has not finished initializing yet.
|
|
20
|
+
*/
|
|
21
|
+
export declare const useSocketStatus: () => SocketConnectionState;
|
|
22
|
+
/**
|
|
23
|
+
* `retry` revives every lost connection now (`SocketStatusService.retry()`); `retrying` is true
|
|
24
|
+
* from any retry — this one, or the service's own on tab activation — until the aggregate settles
|
|
25
|
+
* back on `'online'` or `'lost'`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const useSocketRetry: () => {
|
|
28
|
+
retry: () => void;
|
|
29
|
+
retrying: boolean;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=status.d.ts.map
|