@ac-kit/net-websocket 0.0.0-stage → 0.1.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,92 @@
1
+ # @ac-kit/net-websocket
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 5075202: HTTP/3, over a multiplexed connection contract.
8
+
9
+ - `net-core`: `IMultiplexedConnection` and `IMultiplexedStream` — a secure
10
+ connection carrying many streams, each a `Transport` that either side can
11
+ reset or stop on its own — with `MultiplexedStreamHandlers` and the errors a
12
+ reset, a stop or the connection's end report. `Connector` is now generic over
13
+ what it establishes, like `IListener`.
14
+ - `async`: `staggeredRace`, RFC 8305 connection racing for any candidates.
15
+ - `format-varint`: QUIC variable-length integers (RFC 9000 §16) —
16
+ `readQuicVarint`, `readBigQuicVarint` (the whole 62-bit range, as a
17
+ `bigint`), `writeQuicVarint`, `encodeQuicVarint`, `quicVarintByteLength` and
18
+ `quicVarintEncodedLength`.
19
+ - `format-http`: `QpackDecoder` (RFC 9204, dynamic table and blocked streams)
20
+ and `QpackEncoder` (static table and literals); `Http3FrameDecoder` and
21
+ `encodeHttp3Frame` for HTTP/3 frames (RFC 9114), with DATA streamed in
22
+ pieces; `Http3Settings`, `Http3StreamType`, `Http3Error` and
23
+ `Http3ErrorCode`. `parseAltSvc` and `tryParseAltSvc` read the `Alt-Svc`
24
+ field (RFC 7838), `AltSvcSyntaxError` reporting a malformed one.
25
+ - `net-http`: `Http3ServerConnection` and `Http3ClientConnection`, with
26
+ trailers, GOAWAY and extended `CONNECT` tunnels (RFC 9220). `HttpServer`
27
+ serves HTTP/3 on multiplexed listeners with its `http3` option; `HttpAgent`
28
+ reaches `https:` origins over HTTP/3 with its own: those advertising it
29
+ through `Alt-Svc`, raced against TCP and falling back to it, or every one
30
+ with `priorKnowledge`.
31
+ - `net-quic`: first release. `QuicListener` and `createQuicConnector` over a
32
+ native quiche binding; the binding of each platform is its own optional
33
+ package, `@ac-kit/net-quic-<platform>`. A client's UDP socket is connected,
34
+ so a refused port fails the attempt at once.
35
+ - `node`: `DgramSocket.connect`, `disconnect`, `remoteAddress` and
36
+ `sendConnected`, for a UDP socket bound to one remote endpoint.
37
+ - `integration-test-util`: `createSelfSignedCertificate` takes the names the
38
+ certificate is valid for.
39
+ - `net-websocket`: documented over HTTP/3, which needed no change.
40
+ - Updated dependencies [5075202]
41
+ - @ac-kit/net-core@0.3.0
42
+ - @ac-kit/async@0.2.0
43
+ - @ac-kit/format-http@0.3.0
44
+ - @ac-kit/net-http@0.3.0
45
+
46
+ ## 0.1.0
47
+
48
+ ### Minor Changes
49
+
50
+ - 1af504e: HTTP/2, and TLS with ALPN.
51
+
52
+ - `format-http`: `Http2FrameCodec`, the RFC 9113 frame codec with field blocks
53
+ HPACK-coded on the way, and `HpackEncoder`/`HpackDecoder` (RFC 7541) on their
54
+ own. Sensitive fields are sent never-indexed; an oversized header list is a
55
+ stream error that keeps both ends' tables in step.
56
+ - `net-http`: `Http2ServerConnection` and `Http2ClientConnection` — concurrent
57
+ streams, flow control as backpressure, trailers, `GOAWAY`, a control-frame
58
+ rate guard against rapid-reset floods, and extended `CONNECT` tunnels.
59
+ `HttpServer` serves HTTP/2 through ALPN `h2` and cleartext prior knowledge
60
+ with its `http2` option; `HttpAgent` offers `h2` and multiplexes one
61
+ connection per origin with its own. A request's `protocol` now also works
62
+ over HTTP/1.1, sent as an `Upgrade`.
63
+ - `net-core`: `peekTransport`, to read a connection's first bytes without
64
+ consuming them.
65
+ - `net-transport-node`: TLS in `TcpListener.listen` (`tls` option, ALPN,
66
+ handshake timeout) and in the new `createTcpConnector`; `connectTcp` opens
67
+ `secure` targets with Node's default trust. Concurrent writes waiting for
68
+ `drain` share one listener.
69
+ - `integration-test-util`: `createSelfSignedCertificate`, a throwaway
70
+ certificate for TLS tests.
71
+ - `net-websocket`: `connectWebSocket` over HTTP/2 (RFC 8441), through the same
72
+ version-neutral request.
73
+ - 1af504e: New packages: WebSocket (RFC 6455).
74
+
75
+ - `format-websocket`: `WebSocketFrameCodec` with streamed data payloads,
76
+ masking, close codes and the close payload.
77
+ - `net-websocket`: `WebSocketPeer` over any `Transport`, and the opening
78
+ handshake on both sides — `acceptWebSocket` inside an `@ac-kit/net-http`
79
+ handler, `connectWebSocket` through an `HttpAgent`.
80
+
81
+ ### Patch Changes
82
+
83
+ - Updated dependencies [1af504e]
84
+ - Updated dependencies [1af504e]
85
+ - Updated dependencies [1af504e]
86
+ - Updated dependencies [1af504e]
87
+ - Updated dependencies [1af504e]
88
+ - Updated dependencies [1af504e]
89
+ - @ac-kit/format-http@0.2.0
90
+ - @ac-kit/net-http@0.2.0
91
+ - @ac-kit/net-core@0.2.0
92
+ - @ac-kit/format-websocket@0.1.0
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024-2026 Anthony Champagne and contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,3 +1,66 @@
1
- # Temporary Holding Version
1
+ # @ac-kit/net-websocket
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ WebSocket endpoints over any `Transport`: a peer that sends and receives
4
+ messages, and the opening handshake on both sides.
5
+
6
+ ```ts
7
+ import { HttpServer } from "@ac-kit/net-http";
8
+ import { acceptWebSocket } from "@ac-kit/net-websocket";
9
+
10
+ const server = new HttpServer({
11
+ handler: (request) => {
12
+ if (request.headers.get("origin")?.[0] !== "http://127.0.0.1:8080") {
13
+ return { status: 403 };
14
+ }
15
+ return acceptWebSocket(
16
+ request,
17
+ { maxMessageSize: 1 << 20, closeTimeoutMs: 5_000 },
18
+ (peer) => {
19
+ peer.subscribe("message", (data) => void peer.send(data));
20
+ },
21
+ );
22
+ },
23
+ maxHeadSize: 16 * 1024,
24
+ idleTimeoutMs: 5_000,
25
+ maxConnections: 100,
26
+ });
27
+ ```
28
+
29
+ ## What it exposes
30
+
31
+ - `WebSocketPeer` — one end of a connection. `send` a string or bytes,
32
+ `subscribe("message")` for whole messages, `ping`, and `close` for the
33
+ closing handshake. Fragmented messages are reassembled up to
34
+ `maxMessageSize`, text is checked to be UTF-8, pings are answered, and every
35
+ violation fails the connection with the close code RFC 6455 assigns.
36
+ - `acceptWebSocket` — validates an opening handshake inside an
37
+ `@ac-kit/net-http` handler and returns the response to send: `101` with the
38
+ `Sec-WebSocket-Accept` for an HTTP/1.1 `Upgrade`, `200` for an extended
39
+ `CONNECT`, `400` or `426` for an invalid one. The peer is handed to a callback
40
+ once the response is out.
41
+ - `connectWebSocket` — sends the opening handshake through an `HttpAgent` (or
42
+ one client connection), checks the answer, and returns the peer. The request
43
+ is version-neutral: an HTTP/1.1 connection carries it as an `Upgrade`, an
44
+ HTTP/2 or HTTP/3 one as an extended `CONNECT` on its own stream, beside the
45
+ connection's other streams.
46
+ - `computeWebSocketAccept` — the `Sec-WebSocket-Accept` for a key.
47
+
48
+ Checking `Origin` before accepting is the server's job: without it, any web
49
+ page the user visits can open a WebSocket to the server with the user's
50
+ cookies.
51
+
52
+ Portable: no Node.js built-ins. The peer only ever sees a `Transport`, so it
53
+ runs the same over a TCP connection after `Upgrade`, over an HTTP/2 or HTTP/3
54
+ stream, or over any other transport.
55
+
56
+ See the
57
+ [generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/net-websocket/)
58
+ for the full reference.
59
+
60
+ ## Further reading
61
+
62
+ - [RFC 6455](https://www.rfc-editor.org/rfc/rfc6455) — the WebSocket protocol
63
+ (authoritative).
64
+ - [RFC 8441](https://www.rfc-editor.org/rfc/rfc8441) — WebSocket over HTTP/2's
65
+ extended `CONNECT`.
66
+ - [RFC 9220](https://www.rfc-editor.org/rfc/rfc9220) — the same over HTTP/3.
@@ -0,0 +1,13 @@
1
+ import type { HttpHeaders } from "@ac-kit/format-http";
2
+ /** Whether `key` is a valid `Sec-WebSocket-Key`: base64 of 16 bytes. */
3
+ export declare function isWebSocketKey_(key: string): boolean;
4
+ /** A fresh `Sec-WebSocket-Key`: 16 random bytes, base64-encoded. */
5
+ export declare function createWebSocketKey_(): string;
6
+ /**
7
+ * Whether a comma-separated field lists `token`, case-insensitively —
8
+ * `Connection: keep-alive, Upgrade` lists `upgrade`.
9
+ */
10
+ export declare function hasHeaderToken_(headers: HttpHeaders, name: string, token: string): boolean;
11
+ /** The values of a comma-separated field, trimmed, empty ones dropped. */
12
+ export declare function listHeaderTokens_(headers: HttpHeaders, name: string): string[];
13
+ //# sourceMappingURL=_websocket-handshake.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_websocket-handshake.d.ts","sourceRoot":"","sources":["../../src/handshake/_websocket-handshake.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,wEAAwE;AACxE,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAMpD;AAED,oEAAoE;AACpE,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC9B,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACX,OAAO,CAKT;AAED,0EAA0E;AAC1E,wBAAgB,iBAAiB,CAChC,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,MAAM,GACV,MAAM,EAAE,CAIV"}
@@ -0,0 +1,28 @@
1
+ /** Whether `key` is a valid `Sec-WebSocket-Key`: base64 of 16 bytes. */
2
+ export function isWebSocketKey_(key) {
3
+ try {
4
+ return Uint8Array.fromBase64(key).length === 16;
5
+ }
6
+ catch {
7
+ return false;
8
+ }
9
+ }
10
+ /** A fresh `Sec-WebSocket-Key`: 16 random bytes, base64-encoded. */
11
+ export function createWebSocketKey_() {
12
+ return crypto.getRandomValues(new Uint8Array(16)).toBase64();
13
+ }
14
+ /**
15
+ * Whether a comma-separated field lists `token`, case-insensitively —
16
+ * `Connection: keep-alive, Upgrade` lists `upgrade`.
17
+ */
18
+ export function hasHeaderToken_(headers, name, token) {
19
+ return (headers.get(name)?.some((value) => value.trim().toLowerCase() === token) ??
20
+ false);
21
+ }
22
+ /** The values of a comma-separated field, trimmed, empty ones dropped. */
23
+ export function listHeaderTokens_(headers, name) {
24
+ return (headers.get(name) ?? [])
25
+ .map((value) => value.trim())
26
+ .filter((value) => value !== "");
27
+ }
28
+ //# sourceMappingURL=_websocket-handshake.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_websocket-handshake.js","sourceRoot":"","sources":["../../src/handshake/_websocket-handshake.ts"],"names":[],"mappings":"AAEA,wEAAwE;AACxE,MAAM,UAAU,eAAe,CAAC,GAAW;IAC1C,IAAI,CAAC;QACJ,OAAO,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,mBAAmB;IAClC,OAAO,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC9D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC9B,OAAoB,EACpB,IAAY,EACZ,KAAa;IAEb,OAAO,CACN,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC;QACxE,KAAK,CACL,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,iBAAiB,CAChC,OAAoB,EACpB,IAAY;IAEZ,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC9B,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;SAC5B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { HttpHeaders } from "@ac-kit/format-http";
2
+ import type { HttpIncomingRequest, HttpOutgoingResponse } from "@ac-kit/net-http";
3
+ import { WebSocketPeer } from "../peer/websocket-peer.js";
4
+ /** Options for {@link acceptWebSocket}. */
5
+ export type WebSocketAcceptOptions = {
6
+ /** See `WebSocketPeerOptions.maxMessageSize`. Required. */
7
+ readonly maxMessageSize: number;
8
+ /** See `WebSocketPeerOptions.closeTimeoutMs`. Required. */
9
+ readonly closeTimeoutMs: number;
10
+ /**
11
+ * Subprotocols this server speaks, in its order of preference; the first one
12
+ * the client also offered is chosen. None is chosen when this is omitted or
13
+ * nothing matches — the client then decides whether to go on.
14
+ */
15
+ readonly protocols?: readonly string[];
16
+ /** Extra fields for the `101` (or `200`) response. */
17
+ readonly headers?: HttpHeaders;
18
+ };
19
+ /**
20
+ * Answers a request to open a WebSocket: validates the opening handshake and
21
+ * returns the response a handler should return.
22
+ *
23
+ * Accepts both forms: an HTTP/1.1 `GET` with `Upgrade: websocket` (RFC 6455
24
+ * §4.2), answered `101` with its `Sec-WebSocket-Accept`, and an extended
25
+ * `CONNECT` with protocol `websocket` (RFC 8441 for HTTP/2, RFC 9220 for
26
+ * HTTP/3), answered `200`. Once the response is sent the connection or stream
27
+ * becomes a {@link WebSocketPeer}, handed to `onOpen`.
28
+ *
29
+ * An invalid handshake is answered `400`, and an unsupported
30
+ * `Sec-WebSocket-Version` `426` listing version 13; `onOpen` is then never
31
+ * called. Checking `Origin` — what stops another site's page from opening a
32
+ * WebSocket with the user's cookies — is the caller's job, before calling
33
+ * this.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const handler: HttpHandler = (request) =>
38
+ * acceptWebSocket(
39
+ * request,
40
+ * { maxMessageSize: 1 << 20, closeTimeoutMs: 5000 },
41
+ * (peer) => {
42
+ * peer.subscribe("message", (data) => void peer.send(data));
43
+ * },
44
+ * );
45
+ * ```;
46
+ */
47
+ export declare function acceptWebSocket(request: HttpIncomingRequest, options: WebSocketAcceptOptions, onOpen: (peer: WebSocketPeer) => void): Promise<HttpOutgoingResponse>;
48
+ //# sourceMappingURL=accept-websocket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accept-websocket.d.ts","sourceRoot":"","sources":["../../src/handshake/accept-websocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EACX,mBAAmB,EACnB,oBAAoB,EACpB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAQ1D,2CAA2C;AAC3C,MAAM,MAAM,sBAAsB,GAAG;IACpC,2DAA2D;IAC3D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAEhC,2DAA2D;IAC3D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAEhC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAEvC,sDAAsD;IACtD,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC;CAC/B,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,eAAe,CACpC,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,GACnC,OAAO,CAAC,oBAAoB,CAAC,CAsD/B"}
@@ -0,0 +1,79 @@
1
+ import { HttpHeaders } from "@ac-kit/format-http";
2
+ import { WebSocketPeer } from "../peer/websocket-peer.js";
3
+ import { hasHeaderToken_, isWebSocketKey_, listHeaderTokens_, } from "./_websocket-handshake.js";
4
+ import { computeWebSocketAccept } from "./websocket-accept.js";
5
+ const SUPPORTED_VERSION_ = "13";
6
+ /**
7
+ * Answers a request to open a WebSocket: validates the opening handshake and
8
+ * returns the response a handler should return.
9
+ *
10
+ * Accepts both forms: an HTTP/1.1 `GET` with `Upgrade: websocket` (RFC 6455
11
+ * §4.2), answered `101` with its `Sec-WebSocket-Accept`, and an extended
12
+ * `CONNECT` with protocol `websocket` (RFC 8441 for HTTP/2, RFC 9220 for
13
+ * HTTP/3), answered `200`. Once the response is sent the connection or stream
14
+ * becomes a {@link WebSocketPeer}, handed to `onOpen`.
15
+ *
16
+ * An invalid handshake is answered `400`, and an unsupported
17
+ * `Sec-WebSocket-Version` `426` listing version 13; `onOpen` is then never
18
+ * called. Checking `Origin` — what stops another site's page from opening a
19
+ * WebSocket with the user's cookies — is the caller's job, before calling
20
+ * this.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const handler: HttpHandler = (request) =>
25
+ * acceptWebSocket(
26
+ * request,
27
+ * { maxMessageSize: 1 << 20, closeTimeoutMs: 5000 },
28
+ * (peer) => {
29
+ * peer.subscribe("message", (data) => void peer.send(data));
30
+ * },
31
+ * );
32
+ * ```;
33
+ */
34
+ export async function acceptWebSocket(request, options, onOpen) {
35
+ const { headers } = request;
36
+ const extended = request.method === "CONNECT" && request.protocol === "websocket";
37
+ const upgrade = request.method === "GET" &&
38
+ request.version === "1.1" &&
39
+ hasHeaderToken_(headers, "upgrade", "websocket") &&
40
+ hasHeaderToken_(headers, "connection", "upgrade");
41
+ if (!extended && !upgrade) {
42
+ return { status: 400 };
43
+ }
44
+ if (headers.get("sec-websocket-version")?.[0]?.trim() !== SUPPORTED_VERSION_) {
45
+ return {
46
+ status: 426,
47
+ headers: new HttpHeaders({ "Sec-WebSocket-Version": SUPPORTED_VERSION_ }),
48
+ };
49
+ }
50
+ const key = headers.get("sec-websocket-key");
51
+ if (upgrade && (key?.length !== 1 || !isWebSocketKey_(key[0].trim()))) {
52
+ return { status: 400 };
53
+ }
54
+ const offered = listHeaderTokens_(headers, "sec-websocket-protocol");
55
+ const protocol = options.protocols?.find((name) => offered.includes(name)) ?? null;
56
+ const response = new HttpHeaders(options.headers);
57
+ if (protocol !== null) {
58
+ response.set("sec-websocket-protocol", [protocol]);
59
+ }
60
+ if (upgrade) {
61
+ response.set("upgrade", ["websocket"]);
62
+ response.set("connection", ["Upgrade"]);
63
+ response.set("sec-websocket-accept", [
64
+ await computeWebSocketAccept(key[0].trim()),
65
+ ]); // checked to hold one valid key above
66
+ }
67
+ return {
68
+ status: upgrade ? 101 : 200,
69
+ headers: response,
70
+ tunnel: (transport) => onOpen(new WebSocketPeer({
71
+ transport,
72
+ role: "server",
73
+ maxMessageSize: options.maxMessageSize,
74
+ closeTimeoutMs: options.closeTimeoutMs,
75
+ protocol,
76
+ })),
77
+ };
78
+ }
79
+ //# sourceMappingURL=accept-websocket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accept-websocket.js","sourceRoot":"","sources":["../../src/handshake/accept-websocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAMlD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EACN,eAAe,EACf,eAAe,EACf,iBAAiB,GACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAqB/D,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACpC,OAA4B,EAC5B,OAA+B,EAC/B,MAAqC;IAErC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,MAAM,QAAQ,GACb,OAAO,CAAC,MAAM,KAAK,SAAS,IAAI,OAAO,CAAC,QAAQ,KAAK,WAAW,CAAC;IAClE,MAAM,OAAO,GACZ,OAAO,CAAC,MAAM,KAAK,KAAK;QACxB,OAAO,CAAC,OAAO,KAAK,KAAK;QACzB,eAAe,CAAC,OAAO,EAAE,SAAS,EAAE,WAAW,CAAC;QAChD,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;IACnD,IAAI,CAAC,QAAQ,IAAI,CAAC,OAAO,EAAE,CAAC;QAC3B,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IACxB,CAAC;IAC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AI,EAAE,CAAC;SAC7C,CAAC,CAAC,CAAC,sCAAsC;IAC3C,CAAC;IAED,OAAO;QACN,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG;QAC3B,OAAO,EAAE,QAAQ;QACjB,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,CACrB,MAAM,CACL,IAAI,aAAa,CAAC;YACjB,SAAS;YACT,IAAI,EAAE,QAAQ;YACd,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,QAAQ;SACR,CAAC,CACF;KACF,CAAC;AACH,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { HttpHeaders } from "@ac-kit/format-http";
2
+ import type { HttpIncomingResponse, HttpOutgoingRequest, HttpRequestOptions } from "@ac-kit/net-http";
3
+ import { WebSocketPeer } from "../peer/websocket-peer.js";
4
+ /**
5
+ * Anything that sends an HTTP request: an `HttpAgent`, one
6
+ * `Http1ClientConnection`, or one `Http2ClientConnection`.
7
+ */
8
+ export type HttpRequester = {
9
+ request(request: HttpOutgoingRequest, options?: HttpRequestOptions): Promise<HttpIncomingResponse>;
10
+ };
11
+ /** Options for {@link connectWebSocket}. */
12
+ export type WebSocketConnectOptions = {
13
+ /** See `WebSocketPeerOptions.maxMessageSize`. Required. */
14
+ readonly maxMessageSize: number;
15
+ /** See `WebSocketPeerOptions.closeTimeoutMs`. Required. */
16
+ readonly closeTimeoutMs: number;
17
+ /** Subprotocols to offer, in order of preference. */
18
+ readonly protocols?: readonly string[];
19
+ /** Extra request fields, such as `Origin` or `Authorization`. */
20
+ readonly headers?: HttpHeaders;
21
+ /** Abandons the handshake. */
22
+ readonly signal?: AbortSignal;
23
+ };
24
+ /** The server refused, or answered the opening handshake incorrectly. */
25
+ export declare class WebSocketHandshakeError extends Error {
26
+ readonly status: number;
27
+ /** @param status The response status, which was not `101`, when it was. */
28
+ constructor(message: string, status: number);
29
+ }
30
+ /**
31
+ * Open a WebSocket: send the opening handshake through `requester`, check the
32
+ * server's answer, and return the peer over the connection it handed over.
33
+ *
34
+ * `ws:` and `wss:` URLs are requested as `http:` and `https:`. The request is a
35
+ * `CONNECT` with protocol `websocket`, which HTTP/1.1 sends as its `Upgrade`
36
+ * handshake and HTTP/2 and HTTP/3 as an extended `CONNECT` (RFC 8441, RFC
37
+ * 9220).
38
+ *
39
+ * Over HTTP/1.1 the response must be a `101` with `Upgrade: websocket`, the
40
+ * `Sec-WebSocket-Accept` matching the key sent; over HTTP/2 and HTTP/3, a
41
+ * `2xx`. Either way it must choose no extension (none is offered), and a
42
+ * subprotocol only from those offered.
43
+ *
44
+ * @throws {WebSocketHandshakeError} When the server refuses or answers
45
+ * incorrectly.
46
+ * @throws When the request fails, or `options.signal` aborts first.
47
+ */
48
+ export declare function connectWebSocket(requester: HttpRequester, url: URL, options: WebSocketConnectOptions): Promise<WebSocketPeer>;
49
+ //# sourceMappingURL=connect-websocket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect-websocket.d.ts","sourceRoot":"","sources":["../../src/handshake/connect-websocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EACX,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAQ1D;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC3B,OAAO,CACN,OAAO,EAAE,mBAAmB,EAC5B,OAAO,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,oBAAoB,CAAC,CAAC;CACjC,CAAC;AAEF,4CAA4C;AAC5C,MAAM,MAAM,uBAAuB,GAAG;IACrC,2DAA2D;IAC3D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAEhC,2DAA2D;IAC3D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAEhC,qDAAqD;IACrD,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAEvC,iEAAiE;IACjE,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC;IAE/B,8BAA8B;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B,CAAC;AAEF,yEAAyE;AACzE,qBAAa,uBAAwB,SAAQ,KAAK;IAIhD,QAAQ,CAAC,MAAM,EAAE,MAAM;IAHxB,2EAA2E;IAC3E,YACC,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM,EAIvB;CACD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,gBAAgB,CACrC,SAAS,EAAE,aAAa,EACxB,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,uBAAuB,GAC9B,OAAO,CAAC,aAAa,CAAC,CAsCxB"}
@@ -0,0 +1,92 @@
1
+ import { HttpHeaders } from "@ac-kit/format-http";
2
+ import { WebSocketPeer } from "../peer/websocket-peer.js";
3
+ import { createWebSocketKey_, hasHeaderToken_, listHeaderTokens_, } from "./_websocket-handshake.js";
4
+ import { computeWebSocketAccept } from "./websocket-accept.js";
5
+ /** The server refused, or answered the opening handshake incorrectly. */
6
+ export class WebSocketHandshakeError extends Error {
7
+ status;
8
+ /** @param status The response status, which was not `101`, when it was. */
9
+ constructor(message, status) {
10
+ super(message);
11
+ this.status = status;
12
+ this.name = "WebSocketHandshakeError";
13
+ }
14
+ }
15
+ /**
16
+ * Open a WebSocket: send the opening handshake through `requester`, check the
17
+ * server's answer, and return the peer over the connection it handed over.
18
+ *
19
+ * `ws:` and `wss:` URLs are requested as `http:` and `https:`. The request is a
20
+ * `CONNECT` with protocol `websocket`, which HTTP/1.1 sends as its `Upgrade`
21
+ * handshake and HTTP/2 and HTTP/3 as an extended `CONNECT` (RFC 8441, RFC
22
+ * 9220).
23
+ *
24
+ * Over HTTP/1.1 the response must be a `101` with `Upgrade: websocket`, the
25
+ * `Sec-WebSocket-Accept` matching the key sent; over HTTP/2 and HTTP/3, a
26
+ * `2xx`. Either way it must choose no extension (none is offered), and a
27
+ * subprotocol only from those offered.
28
+ *
29
+ * @throws {WebSocketHandshakeError} When the server refuses or answers
30
+ * incorrectly.
31
+ * @throws When the request fails, or `options.signal` aborts first.
32
+ */
33
+ export async function connectWebSocket(requester, url, options) {
34
+ const target = new URL(url);
35
+ if (target.protocol === "ws:" || target.protocol === "wss:") {
36
+ target.protocol = target.protocol === "ws:" ? "http:" : "https:";
37
+ }
38
+ const key = createWebSocketKey_();
39
+ const headers = new HttpHeaders(options.headers);
40
+ // Used by HTTP/1.1 only; RFC 8441 and RFC 9220 ignore it.
41
+ headers.set("sec-websocket-key", [key]);
42
+ headers.set("sec-websocket-version", ["13"]);
43
+ const offered = options.protocols ?? [];
44
+ if (offered.length > 0) {
45
+ headers.set("sec-websocket-protocol", [...offered]);
46
+ }
47
+ const response = await requester.request({ method: "CONNECT", protocol: "websocket", url: target, headers }, { signal: options.signal });
48
+ const { tunnel } = response;
49
+ const failure = await checkHandshake_(response, key, offered);
50
+ if (failure !== null || tunnel === null) {
51
+ tunnel?.destroy();
52
+ await response.body?.cancel();
53
+ throw new WebSocketHandshakeError(failure ?? "No connection handed over", response.status);
54
+ }
55
+ return new WebSocketPeer({
56
+ transport: tunnel,
57
+ role: "client",
58
+ maxMessageSize: options.maxMessageSize,
59
+ closeTimeoutMs: options.closeTimeoutMs,
60
+ protocol: response.headers.get("sec-websocket-protocol")?.[0]?.trim() ?? null,
61
+ });
62
+ }
63
+ /** @returns Why the response does not complete the handshake, or `null`. */
64
+ async function checkHandshake_(response, key, offered) {
65
+ const { headers } = response;
66
+ if (response.version !== "1.0" && response.version !== "1.1") {
67
+ if (response.status < 200 || response.status >= 300) {
68
+ return `Server answered ${response.status}`;
69
+ }
70
+ }
71
+ else if (response.status !== 101) {
72
+ return `Server answered ${response.status}`;
73
+ }
74
+ else if (!hasHeaderToken_(headers, "upgrade", "websocket") ||
75
+ !hasHeaderToken_(headers, "connection", "upgrade")) {
76
+ return "Response does not upgrade to websocket";
77
+ }
78
+ else if (headers.get("sec-websocket-accept")?.[0]?.trim() !==
79
+ (await computeWebSocketAccept(key))) {
80
+ return "Sec-WebSocket-Accept does not match";
81
+ }
82
+ if (listHeaderTokens_(headers, "sec-websocket-extensions").length > 0) {
83
+ return "Server chose an extension that was not offered";
84
+ }
85
+ const protocols = listHeaderTokens_(headers, "sec-websocket-protocol");
86
+ if (protocols.length > 1 ||
87
+ (protocols.length === 1 && !offered.includes(protocols[0]))) {
88
+ return "Server chose a subprotocol that was not offered";
89
+ }
90
+ return null;
91
+ }
92
+ //# sourceMappingURL=connect-websocket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect-websocket.js","sourceRoot":"","sources":["../../src/handshake/connect-websocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAOlD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,iBAAiB,GACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AA+B/D,yEAAyE;AACzE,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAIvC,MAAM;IAHhB,2EAA2E;IAC3E,YACC,OAAe,EACN,MAAc;QAEvB,KAAK,CAAC,OAAO,CAAC,CAAC;sBAFN,MAAM;QAGf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACvC,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,SAAwB,EACxB,GAAQ,EACR,OAAgC;IAEhC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,IAAI,MAAM,CAAC,QAAQ,KAAK,KAAK,IAAI,MAAM,CAA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AAO,EAAE,0BAA0B,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvE,OAAO,gDAAgD,CAAC;IACzD,CAAC;IACD,MAAM,SAAS,GAAG,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,CAAC,CAAC;IACvE,IACC,SAAS,CAAC,MAAM,GAAG,CAAC;QACpB,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAE,CAAC,CAAC,EAC3D,CAAC;QACF,OAAO,iDAAiD,CAAC;IAC1D,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The `Sec-WebSocket-Accept` value proving a server read the client's
3
+ * `Sec-WebSocket-Key` (RFC 6455 §4.2.2): the base64 SHA-1 of the key followed
4
+ * by the protocol's GUID.
5
+ *
6
+ * Not a security measure — SHA-1 is used here only because the protocol fixes
7
+ * it — but a handshake whose value does not match must be refused.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * await computeWebSocketAccept("dGhlIHNhbXBsZSBub25jZQ==");
12
+ * // "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="
13
+ * ```;
14
+ */
15
+ export declare function computeWebSocketAccept(key: string): Promise<string>;
16
+ //# sourceMappingURL=websocket-accept.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-accept.d.ts","sourceRoot":"","sources":["../../src/handshake/websocket-accept.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;GAaG;AACH,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAGzE"}
@@ -0,0 +1,23 @@
1
+ import { encodeTextLatin1 } from "@ac-kit/core";
2
+ import { sha1 } from "@ac-kit/crypto-hash";
3
+ // RFC 6455 §1.3: the GUID every server appends to the client's key.
4
+ const WEBSOCKET_GUID_ = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
5
+ /**
6
+ * The `Sec-WebSocket-Accept` value proving a server read the client's
7
+ * `Sec-WebSocket-Key` (RFC 6455 §4.2.2): the base64 SHA-1 of the key followed
8
+ * by the protocol's GUID.
9
+ *
10
+ * Not a security measure — SHA-1 is used here only because the protocol fixes
11
+ * it — but a handshake whose value does not match must be refused.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * await computeWebSocketAccept("dGhlIHNhbXBsZSBub25jZQ==");
16
+ * // "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="
17
+ * ```;
18
+ */
19
+ export async function computeWebSocketAccept(key) {
20
+ const digest = await sha1(encodeTextLatin1(`${key}${WEBSOCKET_GUID_}`));
21
+ return digest.toBase64();
22
+ }
23
+ //# sourceMappingURL=websocket-accept.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-accept.js","sourceRoot":"","sources":["../../src/handshake/websocket-accept.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,oEAAoE;AACpE,MAAM,eAAe,GAAG,sCAAsC,CAAC;AAE/D;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,GAAW;IACvD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,GAAG,GAAG,GAAG,eAAe,EAAE,CAAC,CAAC,CAAC;IACxE,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "./handshake/accept-websocket.js";
2
+ export * from "./handshake/connect-websocket.js";
3
+ export * from "./handshake/websocket-accept.js";
4
+ export * from "./peer/websocket-peer.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./handshake/accept-websocket.js";
2
+ export * from "./handshake/connect-websocket.js";
3
+ export * from "./handshake/websocket-accept.js";
4
+ export * from "./peer/websocket-peer.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,131 @@
1
+ import { EventDispatcherMapBase } from "@ac-kit/async";
2
+ import { type WebSocketRole } from "@ac-kit/format-websocket";
3
+ import { type Transport } from "@ac-kit/net-core";
4
+ /** Construction options for {@link WebSocketPeer}. */
5
+ export type WebSocketPeerOptions = {
6
+ /** The connection after the opening handshake, or an HTTP tunnel. */
7
+ readonly transport: Transport;
8
+ readonly role: WebSocketRole;
9
+ /**
10
+ * Largest message accepted, in bytes, all its fragments together; a larger
11
+ * one fails the connection with `1009`. Required: messages are buffered whole
12
+ * before `message` fires.
13
+ */
14
+ readonly maxMessageSize: number;
15
+ /**
16
+ * How long, in milliseconds, to wait for the peer's side of the closing
17
+ * handshake before dropping the connection. Required.
18
+ */
19
+ readonly closeTimeoutMs: number;
20
+ /** The subprotocol the handshake settled on, or `null`. */
21
+ readonly protocol?: string | null;
22
+ };
23
+ /** Events emitted by a {@link WebSocketPeer}. */
24
+ export type WebSocketPeerEvents = {
25
+ /** A complete message: text as a string, binary as bytes. */
26
+ message: [data: string | Uint8Array];
27
+ /** A ping arrived; the pong is already on its way. */
28
+ ping: [payload: Uint8Array];
29
+ pong: [payload: Uint8Array];
30
+ /**
31
+ * The peer broke the protocol (a `WebSocketFrameError`) or the transport
32
+ * failed. The connection is being failed; `close` follows.
33
+ */
34
+ error: [error: unknown];
35
+ /**
36
+ * The connection is closed, exactly once.
37
+ *
38
+ * @param code What the peer sent, `1005` when it sent no code, or `1006` when
39
+ * the connection dropped without a closing handshake.
40
+ * @param wasClean Whether both close frames were exchanged.
41
+ */
42
+ close: [code: number, reason: string, wasClean: boolean];
43
+ };
44
+ /** The state of a {@link WebSocketPeer} (RFC 6455 §4 and §7). */
45
+ export type WebSocketState = "open" | "closing" | "closed";
46
+ /** The peer is closing or closed and cannot send. */
47
+ export declare class WebSocketClosedError extends Error {
48
+ constructor();
49
+ }
50
+ /**
51
+ * One end of a WebSocket connection, over any {@link Transport}: after an
52
+ * HTTP/1.1 `Upgrade`, or — the same way — over an HTTP/2 or HTTP/3 stream.
53
+ *
54
+ * Messages are sent as single frames and received whole: fragments are
55
+ * reassembled, up to `maxMessageSize`, and text is checked to be UTF-8. Pings
56
+ * are answered automatically. Every protocol violation fails the connection
57
+ * with the close code RFC 6455 assigns to it.
58
+ *
59
+ * Closing follows §7: {@link close} sends a close frame and waits for the
60
+ * peer's, a close frame received is echoed, and the server end closes the
61
+ * transport first. Either way `close` is emitted once.
62
+ *
63
+ * @see `acceptWebSocket` and `connectWebSocket` for the opening handshake.
64
+ */
65
+ export declare class WebSocketPeer extends EventDispatcherMapBase<WebSocketPeerEvents> {
66
+ private readonly options;
67
+ /** The subprotocol the handshake settled on, or `null`. */
68
+ readonly protocol: string | null;
69
+ private readonly link;
70
+ private readonly inbound;
71
+ private readonly closeTimer;
72
+ private state_;
73
+ private processing;
74
+ private fragments;
75
+ private fragmentsSize;
76
+ private fragmentOpcode;
77
+ private closeSent;
78
+ private received;
79
+ private readonly closed;
80
+ constructor(options: WebSocketPeerOptions);
81
+ get state(): WebSocketState;
82
+ /**
83
+ * Send one message, as a single frame: a string as text, bytes as binary.
84
+ *
85
+ * @param signal Cancels the wait for transport capacity.
86
+ * @throws {WebSocketClosedError} When the peer is closing or closed.
87
+ */
88
+ send(data: string | Uint8Array, signal?: AbortSignal): Promise<void>;
89
+ /**
90
+ * Send a ping. The peer answers with a pong carrying the same payload.
91
+ *
92
+ * @param payload At most 125 bytes.
93
+ * @throws {WebSocketClosedError} When the peer is closing or closed.
94
+ * @throws {RangeError} When `payload` exceeds 125 bytes.
95
+ */
96
+ ping(payload?: Uint8Array, signal?: AbortSignal): Promise<void>;
97
+ /**
98
+ * Start the closing handshake and wait for it to complete, or for
99
+ * `closeTimeoutMs` to pass, whichever comes first.
100
+ *
101
+ * @param code A sendable close code; defaults to `1000`.
102
+ * @param reason At most 123 UTF-8 bytes.
103
+ * @throws {RangeError} When `code` may not be sent or `reason` is too long.
104
+ */
105
+ close(code?: number, reason?: string): Promise<void>;
106
+ /** Drop the connection without a closing handshake. */
107
+ destroy(error?: unknown): void;
108
+ /** Closes the peer, so it can be used with `await using`. */
109
+ [Symbol.asyncDispose](): Promise<void>;
110
+ private enqueue;
111
+ /**
112
+ * Frames are handled one at a time, in order: a data frame's body is read
113
+ * asynchronously, and the frames after it must wait for it.
114
+ */
115
+ private process;
116
+ private handleFrame;
117
+ private handleData;
118
+ private handleClose;
119
+ /** Both close frames are exchanged: the server closes the transport. */
120
+ private completeClose;
121
+ private sendPong;
122
+ private sendClose;
123
+ private endTransport;
124
+ /** RFC 6455 §7.1.7: send a close frame with the error's code, then close. */
125
+ private fail;
126
+ private failWith;
127
+ private handlePeerEnd;
128
+ private terminate;
129
+ private finish;
130
+ }
131
+ //# sourceMappingURL=websocket-peer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-peer.d.ts","sourceRoot":"","sources":["../../src/peer/websocket-peer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EASN,KAAK,aAAa,EAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7D,sDAAsD;AACtD,MAAM,MAAM,oBAAo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";
2
+ import { concatBytes, decodeText, encodeTextUtf8, Timer } from "@ac-kit/core";
3
+ import { createWebSocketMaskStream, decodeWebSocketClosePayload, encodeWebSocketClosePayload, isWebSocketCloseCodeSendable, WebSocketFrameCodec, WebSocketFrameError, } from "@ac-kit/format-websocket";
4
+ import { FrameLink } from "@ac-kit/net-core";
5
+ /** The peer is closing or closed and cannot send. */
6
+ export class WebSocketClosedError extends Error {
7
+ constructor() {
8
+ super("WebSocket is closing or closed");
9
+ this.name = "WebSocketClosedError";
10
+ }
11
+ }
12
+ const NO_STATUS_ = 1005;
13
+ const ABNORMAL_ = 1006;
14
+ /**
15
+ * One end of a WebSocket connection, over any {@link Transport}: after an
16
+ * HTTP/1.1 `Upgrade`, or — the same way — over an HTTP/2 or HTTP/3 stream.
17
+ *
18
+ * Messages are sent as single frames and received whole: fragments are
19
+ * reassembled, up to `maxMessageSize`, and text is checked to be UTF-8. Pings
20
+ * are answered automatically. Every protocol violation fails the connection
21
+ * with the close code RFC 6455 assigns to it.
22
+ *
23
+ * Closing follows §7: {@link close} sends a close frame and waits for the
24
+ * peer's, a close frame received is echoed, and the server end closes the
25
+ * transport first. Either way `close` is emitted once.
26
+ *
27
+ * @see `acceptWebSocket` and `connectWebSocket` for the opening handshake.
28
+ */
29
+ export class WebSocketPeer extends EventDispatcherMapBase {
30
+ options;
31
+ /** The subprotocol the handshake settled on, or `null`. */
32
+ protocol;
33
+ link;
34
+ inbound = [];
35
+ closeTimer;
36
+ state_ = "open";
37
+ processing = false;
38
+ fragments = [];
39
+ fragmentsSize = 0;
40
+ fragmentOpcode = null;
41
+ closeSent = false;
42
+ received = null;
43
+ closed = Promise.withResolvers();
44
+ constructor(options) {
45
+ super();
46
+ this.options = options;
47
+ this.protocol = options.protocol ?? null;
48
+ this.closeTimer = new Timer(() => this.terminate(), options.closeTimeoutMs);
49
+ this.link = new FrameLink({
50
+ transport: options.transport,
51
+ codec: new WebSocketFrameCodec({
52
+ role: options.role,
53
+ maxPayloadLength: options.maxMessageSize,
54
+ }),
55
+ // A header is at most 14 bytes; control payloads at most 125.
56
+ maxBufferSize: 256,
57
+ sink: (frame, body) => this.enqueue({ frame, body }),
58
+ });
59
+ this.link.subscribe("protocolError", (error) => this.fail(error));
60
+ this.link.subscribe("error", (error) => this.dispatch("error", [error]));
61
+ this.link.subscribe("end", () => this.handlePeerEnd());
62
+ this.link.subscribe("close", () => this.finish());
63
+ }
64
+ get state() {
65
+ return this.state_;
66
+ }
67
+ /**
68
+ * Send one message, as a single frame: a string as text, bytes as binary.
69
+ *
70
+ * @param signal Cancels the wait for transport capacity.
71
+ * @throws {WebSocketClosedError} When the peer is closing or closed.
72
+ */
73
+ send(data, signal) {
74
+ if (this.state_ !== "open") {
75
+ return Promise.reject(new WebSocketClosedError());
76
+ }
77
+ return typeof data === "string"
78
+ ? this.link.send({ opcode: "text", payload: encodeTextUtf8(data) }, signal)
79
+ : this.link.send({ opcode: "binary", payload: data }, signal);
80
+ }
81
+ /**
82
+ * Send a ping. The peer answers with a pong carrying the same payload.
83
+ *
84
+ * @param payload At most 125 bytes.
85
+ * @throws {WebSocketClosedError} When the peer is closing or closed.
86
+ * @throws {RangeError} When `payload` exceeds 125 bytes.
87
+ */
88
+ ping(payload = new Uint8Array(0), signal) {
89
+ if (this.state_ !== "open") {
90
+ return Promise.reject(new WebSocketClosedError());
91
+ }
92
+ return this.link.send({ opcode: "ping", payload }, signal);
93
+ }
94
+ /**
95
+ * Start the closing handshake and wait for it to complete, or for
96
+ * `closeTimeoutMs` to pass, whichever comes first.
97
+ *
98
+ * @param code A sendable close code; defaults to `1000`.
99
+ * @param reason At most 123 UTF-8 bytes.
100
+ * @throws {RangeError} When `code` may not be sent or `reason` is too long.
101
+ */
102
+ async close(code = 1000, reason = "") {
103
+ if (!isWebSocketCloseCodeSendable(code)) {
104
+ throw new RangeError(`Close code ${code} may not be sent`);
105
+ }
106
+ const payload = encodeWebSocketClosePayload({ code, reason });
107
+ if (this.state_ === "open") {
108
+ this.state_ = "closing";
109
+ await this.sendClose(payload);
110
+ this.closeTimer.start();
111
+ }
112
+ await this.closed.promise;
113
+ }
114
+ /** Drop the connection without a closing handshake. */
115
+ destroy(error) {
116
+ this.link.destroy(error);
117
+ this.finish();
118
+ }
119
+ /** Closes the peer, so it can be used with `await using`. */
120
+ [Symbol.asyncDispose]() {
121
+ return this.close(1001);
122
+ }
123
+ enqueue(inbound) {
124
+ this.inbound.push(inbound);
125
+ void this.process();
126
+ }
127
+ /**
128
+ * Frames are handled one at a time, in order: a data frame's body is read
129
+ * asynchronously, and the frames after it must wait for it.
130
+ */
131
+ async process() {
132
+ if (this.processing) {
133
+ return;
134
+ }
135
+ this.processing = true;
136
+ try {
137
+ for (let next = this.inbound.shift(); next; next = this.inbound.shift()) {
138
+ if (this.state_ === "closed") {
139
+ return;
140
+ }
141
+ const failure = await this.handleFrame(next.frame, next.body);
142
+ if (failure) {
143
+ this.fail(failure);
144
+ return;
145
+ }
146
+ }
147
+ }
148
+ catch (error) {
149
+ // A body cut short by the transport: its failure closes the link too.
150
+ this.fail(error);
151
+ }
152
+ finally {
153
+ this.processing = false;
154
+ }
155
+ }
156
+ async handleFrame(frame, body) {
157
+ switch (frame.opcode) {
158
+ case "ping":
159
+ if (this.state_ === "open") {
160
+ void this.sendPong(frame.payload);
161
+ }
162
+ this.dispatch("ping", [frame.payload]);
163
+ return null;
164
+ case "pong":
165
+ this.dispatch("pong", [frame.payload]);
166
+ return null;
167
+ case "close":
168
+ return this.handleClose(frame.payload);
169
+ default:
170
+ return this.handleData(frame, body);
171
+ }
172
+ }
173
+ async handleData(frame, body) {
174
+ const starts = frame.opcode !== "continuation";
175
+ if (starts === (this.fragmentOpcode !== null)) {
176
+ return new WebSocketFrameError(starts
177
+ ? "New message inside a fragmented one"
178
+ : "Continuation without a message", 1002);
179
+ }
180
+ if (this.fragmentsSize + frame.payloadLength >
181
+ this.options.maxMessageSize) {
182
+ return new WebSocketFrameError("Message too large", 1009);
183
+ }
184
+ if (starts) {
185
+ this.fragmentOpcode = frame.opcode === "text" ? "text" : "binary";
186
+ }
187
+ if (body) {
188
+ const stream = frame.maskKey
189
+ ? body.pipeThrough(createWebSocketMaskStream(frame.maskKey))
190
+ : body;
191
+ for await (const chunk of stream) {
192
+ this.fragments.push(chunk);
193
+ this.fragmentsSize += chunk.length;
194
+ }
195
+ }
196
+ if (!frame.fin) {
197
+ return null;
198
+ }
199
+ const bytes = this.fragments.length === 1
200
+ ? this.fragments[0]
201
+ : concatBytes(this.fragments);
202
+ const opcode = this.fragmentOpcode;
203
+ this.fragments = [];
204
+ this.fragmentsSize = 0;
205
+ this.fragmentOpcode = null;
206
+ if (this.state_ !== "open") {
207
+ return null;
208
+ }
209
+ if (opcode === "binary") {
210
+ this.dispatch("message", [bytes]);
211
+ return null;
212
+ }
213
+ let text;
214
+ try {
215
+ text = decodeText(bytes, "utf-8", { fatal: true });
216
+ }
217
+ catch {
218
+ return new WebSocketFrameError("Text message is not UTF-8", 1007);
219
+ }
220
+ this.dispatch("message", [text]);
221
+ return null;
222
+ }
223
+ async handleClose(payload) {
224
+ const close = decodeWebSocketClosePayload(payload);
225
+ if (close instanceof WebSocketFrameError) {
226
+ return close;
227
+ }
228
+ this.received = { code: close.code ?? NO_STATUS_, reason: close.reason };
229
+ if (this.state_ === "open") {
230
+ this.state_ = "closing";
231
+ // Echo the code, as §5.5.1 asks; an empty close is echoed empty.
232
+ await this.sendClose(encodeWebSocketClosePayload({ code: close.code, reason: "" }));
233
+ }
234
+ this.completeClose();
235
+ return null;
236
+ }
237
+ /** Both close frames are exchanged: the server closes the transport. */
238
+ completeClose() {
239
+ if (!this.closeSent) {
240
+ return;
241
+ }
242
+ if (this.options.role === "server") {
243
+ void this.endTransport();
244
+ }
245
+ else {
246
+ this.closeTimer.restart();
247
+ }
248
+ }
249
+ async sendPong(payload) {
250
+ try {
251
+ await this.link.send({ opcode: "pong", payload });
252
+ }
253
+ catch {
254
+ // A failed write surfaces as the transport's own error.
255
+ }
256
+ }
257
+ async sendClose(payload) {
258
+ if (this.closeSent) {
259
+ return;
260
+ }
261
+ this.closeSent = true;
262
+ try {
263
+ await this.link.send({ opcode: "close", payload });
264
+ }
265
+ catch {
266
+ this.terminate();
267
+ }
268
+ }
269
+ async endTransport() {
270
+ this.closeTimer.restart();
271
+ try {
272
+ await this.link.end();
273
+ }
274
+ catch {
275
+ this.terminate();
276
+ }
277
+ }
278
+ /** RFC 6455 §7.1.7: send a close frame with the error's code, then close. */
279
+ fail(error) {
280
+ if (this.state_ === "closed") {
281
+ return;
282
+ }
283
+ this.dispatch("error", [error]);
284
+ this.state_ = "closing";
285
+ void this.failWith(error instanceof WebSocketFrameError ? error.closeCode : 1011);
286
+ }
287
+ async failWith(code) {
288
+ await this.sendClose(encodeWebSocketClosePayload({ code, reason: "" }));
289
+ await this.endTransport();
290
+ }
291
+ handlePeerEnd() {
292
+ if (this.received && this.closeSent) {
293
+ this.terminate();
294
+ return;
295
+ }
296
+ // The peer stopped sending without a closing handshake.
297
+ void this.endTransport();
298
+ }
299
+ terminate() {
300
+ this.link.destroy();
301
+ this.finish();
302
+ }
303
+ finish() {
304
+ if (this.state_ === "closed") {
305
+ return;
306
+ }
307
+ this.state_ = "closed";
308
+ this.closeTimer.cancel();
309
+ const clean = this.closeSent && this.received !== null;
310
+ const { code, reason } = this.received ?? { code: ABNORMAL_, reason: "" };
311
+ this.dispatch("close", [code, reason, clean]);
312
+ this.closed.resolve();
313
+ }
314
+ }
315
+ //# sourceMappingURL=websocket-peer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-peer.js","sourceRoot":"","sources":["../../src/peer/websocket-peer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EACN,yBAAyB,EACzB,2BAA2B,EAC3B,2BAA2B,EAC3B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,CAAC;YACjB,OAAO;QACR,CAAC;QACD,wDAAwD;QACxD,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC;IAC1B,CAAC;IAEO,SAAS;QAChB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACpB,IAAI,CAAC,MAAM,EAAE,CAAC;IACf,CAAC;IAEO,MAAM;QACb,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO;QACR,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;QACvB,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC;QACvD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;QAC1E,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC;CACD"}
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "@ac-kit/net-websocket",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "WebSocket endpoints (RFC 6455) over any @ac-kit/net-core Transport: a message-level peer and the opening handshake for both sides.",
5
+ "keywords": [
6
+ "rfc6455",
7
+ "websocket",
8
+ "websocket-client",
9
+ "websocket-server"
10
+ ],
11
+ "homepage": "https://anthochamp.pages.grenadine.io/node-essentials/api/net-websocket/",
12
+ "bugs": {
13
+ "url": "https://git.grenadine.io/anthochamp/node-essentials/issues"
14
+ },
15
+ "license": "BSD-3-Clause",
16
+ "author": "Anthony Champagne <dev@anthonychampagne.fr>",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://git.grenadine.io/anthochamp/node-essentials.git",
20
+ "directory": "packages/net-websocket"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "type": "module",
26
+ "sideEffects": false,
27
+ "main": "./dist/index.js",
28
+ "exports": {
29
+ ".": "./dist/index.js"
30
+ },
31
+ "publishConfig": {
32
+ "main": "./dist/index.js",
33
+ "exports": {
34
+ ".": "./dist/index.js"
35
+ },
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "compile": "tsc -p ./tsconfig.build.json -outDir dist",
40
+ "compile:check": "tsc -noEmit -p ./tsconfig.json",
41
+ "clean": "rimraf dist",
42
+ "build": "yarn clean && yarn compile",
43
+ "test": "yarn run -T vitest run",
44
+ "prepack": "yarn build"
45
+ },
46
+ "dependencies": {
47
+ "@ac-kit/async": "^0.2.0",
48
+ "@ac-kit/core": "^0.5.0",
49
+ "@ac-kit/crypto-hash": "^0.1.4",
50
+ "@ac-kit/format-http": "^0.3.0",
51
+ "@ac-kit/format-websocket": "^0.1.0",
52
+ "@ac-kit/net-core": "^0.3.0",
53
+ "@ac-kit/net-http": "^0.3.0",
54
+ "@types/web": "^0.0.361"
55
+ },
56
+ "devDependencies": {
57
+ "@ac-kit/integration-test-util": "0.4.0",
58
+ "@ac-kit/net-quic": "0.1.0",
59
+ "@ac-kit/net-transport-node": "0.2.1",
60
+ "@ac-kit/tsconfig": "0.1.0",
61
+ "@ac-kit/typedoc-config": "0.1.0",
62
+ "@ac-kit/vitest-config": "0.1.1",
63
+ "@types/node": "^26.5.1",
64
+ "@typescript/native": "typescript@7.0.2",
65
+ "rimraf": "6.1.4",
66
+ "typedoc": "0.28.20",
67
+ "typescript": "@typescript/typescript6@6.0.2"
68
+ },
69
+ "engines": {
70
+ "node": ">=24"
71
+ }
6
72
  }