@orkestrel/websocket 0.0.10 → 0.0.12

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 CHANGED
@@ -1,9 +1,14 @@
1
1
  # @orkestrel/websocket
2
2
 
3
- A dependency-light RFC 6455 WebSocket for Node native handshake and framing
4
- over duplex streams, with a typed emitter surface. Part of the `@orkestrel`
5
- line. Its sole runtime dependency is `@orkestrel/emitter`, used for the typed
6
- `emitter` every connection exposes.
3
+ > The server-native bidirectional transport: a lean, typed wrapper over a raw upgraded
4
+ > `node:stream` Duplex socket that speaks only the RFC 6455 wire protocol, owning the
5
+ > handshake, the masked and unmasked frame codec, ping and pong, and the close handshake,
6
+ > and surfacing every message on an owned `emitter`.
7
+
8
+ Take the socket a `node:http` upgrade handler gives you, pass it to the
9
+ `createNodeWebSocket` function, and read every message off the returned handle's
10
+ `emitter`. Its sole runtime dependency is `@orkestrel/emitter`, which supplies that
11
+ typed emitter. Part of the `@orkestrel` line.
7
12
 
8
13
  ## Install
9
14
 
@@ -13,7 +18,7 @@ npm install @orkestrel/websocket
13
18
 
14
19
  ## Requirements
15
20
 
16
- - Node.js >= 24
21
+ - Node.js >= 22.12.0
17
22
  - Ships dual ESM + CommonJS builds (see `exports` in `package.json`)
18
23
  - Server-only — a single Node-native surface
19
24
 
@@ -24,12 +29,17 @@ import { createServer } from 'node:http'
24
29
  import { createNodeWebSocket } from '@orkestrel/websocket'
25
30
 
26
31
  // A node:http server hands every upgrade request a raw socket; this wrapper takes it
27
- // from there. Passing the client's `sec-websocket-key` selects SERVER mode — the
32
+ // from there. Passing the client's `sec-websocket-key` selects server mode — the
28
33
  // wrapper writes the 101 handshake, marks the connection open, and decodes frames.
29
34
  createServer().on('upgrade', (request, socket, head) => {
35
+ const key = request.headers['sec-websocket-key']
36
+ if (typeof key !== 'string') {
37
+ socket.destroy()
38
+ return
39
+ }
30
40
  const ws = createNodeWebSocket({
31
41
  socket,
32
- key: request.headers['sec-websocket-key'], // present => server mode + 101 handshake
42
+ key, // present => server mode + 101 handshake
33
43
  head, // any bytes that arrived bundled with the upgrade request
34
44
  on: { message: (text) => ws.send(`echo: ${text}`) }, // wire listeners at construction
35
45
  })
@@ -42,7 +52,7 @@ createServer().on('upgrade', (request, socket, head) => {
42
52
 
43
53
  The full API — factories, the `NodeWebSocket` class, the pure codec helpers,
44
54
  constants, and types — is documented in
45
- [`guides/src/websocket.md`](https://github.com/orkestrel/websocket/blob/main/guides/src/websocket.md).
55
+ [`guides/websocket.md`](https://github.com/orkestrel/websocket/blob/main/guides/websocket.md).
46
56
 
47
57
  ## Package
48
58